| 46 | #define SPACECHARS " \f\n\r\t\v" |
| 47 | |
| 48 | static const char *b_str2int (const char *s, int base, lua_Integer *pn) { |
| 49 | lua_Unsigned n = 0; |
| 50 | int neg = 0; |
| 51 | s += strspn(s, SPACECHARS); /* skip initial spaces */ |
| 52 | if (*s == '-') { s++; neg = 1; } /* handle signal */ |
| 53 | else if (*s == '+') s++; |
| 54 | if (!isalnum((unsigned char)*s)) /* no digit? */ |
| 55 | return NULL; |
| 56 | do { |
| 57 | int digit = (isdigit((unsigned char)*s)) ? *s - '0' |
| 58 | : (toupper((unsigned char)*s) - 'A') + 10; |
| 59 | if (digit >= base) return NULL; /* invalid numeral */ |
| 60 | n = n * base + digit; |
| 61 | s++; |
| 62 | } while (isalnum((unsigned char)*s)); |
| 63 | s += strspn(s, SPACECHARS); /* skip trailing spaces */ |
| 64 | *pn = (lua_Integer)((neg) ? (0u - n) : n); |
| 65 | return s; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | static int luaB_tonumber (lua_State *L) { |
no test coverage detected