MCPcopy Create free account
hub / github.com/DFHack/dfhack / b_str2int

Function b_str2int

depends/lua/src/lbaselib.c:48–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46#define SPACECHARS " \f\n\r\t\v"
47
48static 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
69static int luaB_tonumber (lua_State *L) {

Callers 1

luaB_tonumberFunction · 0.85

Calls 1

toupperFunction · 0.85

Tested by

no test coverage detected