Functions | |
def | atoi |
def | count |
def | find |
Variables | |
string | digits = "0123456789" |
string | hexdigits = "0123456789abcdefABCDEF" |
string | letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
def string::atoi | ( | a, | ||
b | ||||
) |
__NATIVE__ pPmObj_t pa; pPmObj_t pb; char const *pc; char *pend; long i; int8_t base; pPmObj_t pi; PmReturn_t retval = PM_RET_OK; /* Raise TypeError if it's not a string or wrong number of args, */ pa = NATIVE_GET_LOCAL(0); if ((OBJ_GET_TYPE(pa) != OBJ_TYPE_STR) || (NATIVE_GET_NUM_ARGS() < 1) || (NATIVE_GET_NUM_ARGS() > 2)) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } /* Get the base, if it exists; otherwise assume 10 */ base = 10; if (NATIVE_GET_NUM_ARGS() == 2) { pb = NATIVE_GET_LOCAL(1); /* Raise a TypeError if 2nd arg is not an int */ if (OBJ_GET_TYPE(pb) != OBJ_TYPE_INT) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } base = ((pPmInt_t)pb)->val; /* Raise ValueError if base is out of range */ if ((base < 0) || (base == 1) || (base > 36)) { PM_RAISE(retval, PM_RET_EX_VAL); return retval; } } /* Perform conversion */ pend = C_NULL; pc = (char const *)&(((pPmString_t)pa)->val); i = strtol(pc, &pend, base); /* Raise ValueError if there was a conversion error */ if (*pend != C_NULL) { PM_RAISE(retval, PM_RET_EX_VAL); return retval; } /* Create an int object to hold the result of the conversion */ retval = int_new(i, &pi); NATIVE_SET_TOS(pi); return retval;
def string::count | ( | s1, | ||
s2 | ||||
) |
__NATIVE__ pPmObj_t ps1; pPmObj_t ps2; uint8_t *pc1; uint8_t *pc2; uint8_t *pscan; uint16_t pc1len; uint16_t pc2len; uint16_t n; pPmObj_t pn; PmReturn_t retval = PM_RET_OK; /* Raise TypeError if it's not a string or wrong number of args, */ ps1 = NATIVE_GET_LOCAL(0); ps2 = NATIVE_GET_LOCAL(1); if ((OBJ_GET_TYPE(ps1) != OBJ_TYPE_STR) || (NATIVE_GET_NUM_ARGS() != 2) || (OBJ_GET_TYPE(ps2) != OBJ_TYPE_STR)) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } pc1 = ((pPmString_t)ps1)->val; pc2 = ((pPmString_t)ps2)->val; pc1len = ((pPmString_t)ps1)->length; pc2len = ((pPmString_t)ps2)->length; n = 0; if (*pc2 != C_NULL) { pscan = (uint8_t *)strstr((const char *)pc1, (const char *)pc2); while (pscan != C_NULL) { n++; pscan += pc2len; if (pscan > pc1 + pc1len) break; pscan = (uint8_t *)strstr((const char *)pscan, (const char *)pc2); } } retval = int_new(n, &pn); NATIVE_SET_TOS(pn); return retval;
def string::find | ( | s1, | ||
s2 | ||||
) |
__NATIVE__ pPmObj_t ps1; pPmObj_t ps2; uint8_t *pc1; uint8_t *pc2; uint8_t *pscan; int32_t n; pPmObj_t pn; PmReturn_t retval = PM_RET_OK; /* Raise TypeError if it's not a string or wrong number of args, */ ps1 = NATIVE_GET_LOCAL(0); ps2 = NATIVE_GET_LOCAL(1); if ((OBJ_GET_TYPE(ps1) != OBJ_TYPE_STR) || (NATIVE_GET_NUM_ARGS() != 2) || (OBJ_GET_TYPE(ps2) != OBJ_TYPE_STR)) { PM_RAISE(retval, PM_RET_EX_TYPE); return retval; } pc1 = ((pPmString_t)ps1)->val; pc2 = ((pPmString_t)ps2)->val; n = -1; /* If the strings are non-null, try to find the index of the substring */ if ((*pc1 != C_NULL) && (*pc2 != C_NULL)) { pscan = (uint8_t *)strstr((const char *)pc1, (const char *)pc2); if (pscan != C_NULL) { n = pscan - pc1; } } retval = int_new(n, &pn); NATIVE_SET_TOS(pn); return retval;