MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / b_str2int

Function b_str2int

3rd/lua-5.4.3/src/lbaselib.c:60–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58#define SPACECHARS " \f\n\r\t\v"
59
60static const char *b_str2int (const char *s, int base, lua_Integer *pn) {
61 lua_Unsigned n = 0;
62 int neg = 0;
63 s += strspn(s, SPACECHARS); /* skip initial spaces */
64 if (*s == '-') { s++; neg = 1; } /* handle sign */
65 else if (*s == '+') s++;
66 if (!isalnum((unsigned char)*s)) /* no digit? */
67 return NULL;
68 do {
69 int digit = (isdigit((unsigned char)*s)) ? *s - '0'
70 : (toupper((unsigned char)*s) - 'A') + 10;
71 if (digit >= base) return NULL; /* invalid numeral */
72 n = n * base + digit;
73 s++;
74 } while (isalnum((unsigned char)*s));
75 s += strspn(s, SPACECHARS); /* skip trailing spaces */
76 *pn = (lua_Integer)((neg) ? (0u - n) : n);
77 return s;
78}
79
80
81static int luaB_tonumber (lua_State *L) {

Callers 1

luaB_tonumberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected