MCPcopy Create free account
hub / github.com/Tracktion/choc / parseNumber

Method parseNumber

choc/text/choc_JSON.h:411–455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409 }
410
411 value::Value parseNumber (bool negate)
412 {
413 auto startPos = current;
414 bool hadDot = false, hadExponent = false;
415
416 for (;;)
417 {
418 auto lastPos = current;
419 auto c = pop();
420
421 if (c >= '0' && c <= '9') continue;
422 if (c == '.' && ! hadDot) { hadDot = true; continue; }
423
424 if (! hadExponent && (c == 'e' || c == 'E'))
425 {
426 hadDot = true;
427 hadExponent = true;
428 popIf ('-');
429 continue;
430 }
431
432 if (isWhitespace (c) || c == ',' || c == '}' || c == ']' || c == 0)
433 {
434 current = lastPos;
435 char* endOfParsedNumber = nullptr;
436
437 if (! (hadDot || hadExponent))
438 {
439 auto v = std::strtoll (startPos.data(), &endOfParsedNumber, 10);
440
441 if (endOfParsedNumber == lastPos.data()
442 && v != std::numeric_limits<long long>::max()
443 && v != std::numeric_limits<long long>::min())
444 return value::createInt64 (static_cast<int64_t> (negate ? -v : v));
445 }
446
447 auto v = std::strtod (startPos.data(), &endOfParsedNumber);
448
449 if (endOfParsedNumber == lastPos.data())
450 return value::createFloat64 (negate ? -v : v);
451 }
452
453 throwError ("Syntax error in number", lastPos);
454 }
455 }
456
457 std::string parseString()
458 {

Callers

nothing calls this directly

Calls 5

isWhitespaceFunction · 0.85
createInt64Function · 0.85
createFloat64Function · 0.85
throwErrorFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected