Skip to content

Commit 50753bb

Browse files
author
datadiode
committed
Simplify Reader::decodeNumber()
1 parent 8f3aa22 commit 50753bb

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/lib_json/json_reader.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,20 +517,14 @@ bool Reader::decodeNumber(Token& token) {
517517
}
518518

519519
bool Reader::decodeNumber(Token& token, Value& decoded) {
520-
bool isDouble = false;
521-
for (Location inspect = token.start_; inspect != token.end_; ++inspect) {
522-
isDouble = isDouble || in(*inspect, '.', 'e', 'E', '+') ||
523-
(*inspect == '-' && inspect != token.start_);
524-
}
525-
if (isDouble)
526-
return decodeDouble(token, decoded);
527520
// Attempts to parse the number as an integer. If the number is
528521
// larger than the maximum supported value of an integer then
529522
// we decode the number as a double.
530523
Location current = token.start_;
531524
bool isNegative = *current == '-';
532525
if (isNegative)
533526
++current;
527+
// TODO: Help the compiler do the div and mod at compile time or get rid of them.
534528
Value::LargestUInt maxIntegerValue =
535529
isNegative ? Value::LargestUInt(-Value::minLargestInt)
536530
: Value::maxLargestUInt;
@@ -539,9 +533,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
539533
while (current < token.end_) {
540534
Char c = *current++;
541535
if (c < '0' || c > '9')
542-
return addError("'" + std::string(token.start_, token.end_) +
543-
"' is not a number.",
544-
token);
536+
return decodeDouble(token, decoded);
545537
Value::UInt digit(c - '0');
546538
if (value >= threshold) {
547539
// We've hit or exceeded the max value divided by 10 (rounded down). If

0 commit comments

Comments
 (0)