** 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 an 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
| 272 | ** current locale radix mark, and tries to convert again. |
| 273 | */ |
| 274 | static const char *l_str2d (const char *s, lua_Number *result) { |
| 275 | const char *endptr; |
| 276 | const char *pmode = strpbrk(s, ".xXnN"); |
| 277 | int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; |
| 278 | if (mode == 'n') /* reject 'inf' and 'nan' */ |
| 279 | return NULL; |
| 280 | endptr = l_str2dloc(s, result, mode); /* try to convert */ |
| 281 | if (endptr == NULL) { /* failed? may be a different locale */ |
| 282 | char buff[L_MAXLENNUM + 1]; |
| 283 | const char *pdot = strchr(s, '.'); |
| 284 | if (strlen(s) > L_MAXLENNUM || pdot == NULL) |
| 285 | return NULL; /* string too long or no dot; fail */ |
| 286 | strcpy(buff, s); /* copy string to buffer */ |
| 287 | buff[pdot - s] = lua_getlocaledecpoint(); /* correct decimal point */ |
| 288 | endptr = l_str2dloc(buff, result, mode); /* try again */ |
| 289 | if (endptr != NULL) |
| 290 | endptr = s + (endptr - buff); /* make relative to 's' */ |
| 291 | } |
| 292 | return endptr; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | #define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10) |
no test coverage detected