** Convert string 's' to a Lua number (put in 'result'). Return NULL ** on fail or the address of the ending '\0' on success. ** 'pmode' points to (and 'mode' contains) special things in the string: ** - 'x'/'X' means a hexadecimal numeral ** - 'n'/'N' means 'inf' or 'nan' (which should be rejected) ** - '.' just optimizes the search for the common case (nothing special) ** This function accepts b
| 244 | ** current locale radix mark, and tries to convert again. |
| 245 | */ |
| 246 | static const char *l_str2d (const char *s, lua_Number *result) { |
| 247 | const char *endptr; |
| 248 | const char *pmode = strpbrk(s, ".xXnN"); |
| 249 | int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; |
| 250 | if (mode == 'n') /* reject 'inf' and 'nan' */ |
| 251 | return NULL; |
| 252 | endptr = l_str2dloc(s, result, mode); /* try to convert */ |
| 253 | if (endptr == NULL) { /* failed? may be a different locale */ |
| 254 | char buff[L_MAXLENNUM + 1]; |
| 255 | const char *pdot = strchr(s, '.'); |
| 256 | if (strlen(s) > L_MAXLENNUM || pdot == NULL) |
| 257 | return NULL; /* string too long or no dot; fail */ |
| 258 | strcpy(buff, s); /* copy string to buffer */ |
| 259 | buff[pdot - s] = lua_getlocaledecpoint(); /* correct decimal point */ |
| 260 | endptr = l_str2dloc(buff, result, mode); /* try again */ |
| 261 | if (endptr != NULL) |
| 262 | endptr = s + (endptr - buff); /* make relative to 's' */ |
| 263 | } |
| 264 | return endptr; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | #define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10) |
no test coverage detected