MCPcopy Index your code
hub / github.com/GJDuck/e9patch / stringToNumber

Function stringToNumber

src/e9patch/e9json.cpp:422–441  ·  view source on GitHub ↗

* Convert a string into a number. */

Source from the content-addressed store, hash-verified

420 * Convert a string into a number.
421 */
422static intptr_t stringToNumber(const Parser &parser)
423{
424 bool neg = false;
425 const char *s = parser.s;
426 if (s[0] == '-')
427 {
428 neg = true;
429 s++;
430 }
431 int base = 10;
432 if (s[0] == '0' && s[1] == 'x')
433 base = 16;
434 char *end = nullptr;
435 errno = 0;
436 intptr_t x = (intptr_t)strtoull(s, &end, base);
437 if (errno != 0 || (end != nullptr && *end != '\0'))
438 parse_error(parser, "failed to parse number from JSON string \"%s\"",
439 parser.s);
440 return (neg? -x: x);
441}
442
443/*
444 * Expect the specific string token.

Callers 2

makeDataEntryFunction · 0.85
parseParamsFunction · 0.85

Calls 1

strtoullFunction · 0.85

Tested by

no test coverage detected