Chromium Code Reviews| Index: src/scanner.cc |
| =================================================================== |
| --- src/scanner.cc (revision 6635) |
| +++ src/scanner.cc (working copy) |
| @@ -516,17 +516,27 @@ |
| Token::Value JsonScanner::ScanJsonNumber() { |
| LiteralScope literal(this); |
| - if (c0_ == '-') AddLiteralCharAdvance(); |
| + bool sign = (c0_ == '-'); |
|
Lasse Reichstein
2011/02/04 13:53:36
Call the variable "negative".
It's not obvious wh
sandholm
2011/02/04 14:26:37
Done.
|
| + |
| + if (sign) AddLiteralCharAdvance(); |
|
Lasse Reichstein
2011/02/04 13:53:36
I would prefer:
bool negative = false;
if (c0_ ==
sandholm
2011/02/04 14:26:37
Done.
|
| if (c0_ == '0') { |
| AddLiteralCharAdvance(); |
| // Prefix zero is only allowed if it's the only digit before |
| // a decimal point or exponent. |
| if ('0' <= c0_ && c0_ <= '9') return Token::ILLEGAL; |
| } else { |
| + int i = 0; |
| + int digits = 0; |
| if (c0_ < '1' || c0_ > '9') return Token::ILLEGAL; |
| do { |
| + i = i * 10 + c0_ - '0'; |
| + digits++; |
| AddLiteralCharAdvance(); |
| } while (c0_ >= '0' && c0_ <= '9'); |
| + if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) { |
| + number = (sign ? -i : i); |
| + return Token::NUMBER; |
| + } |
| } |
| if (c0_ == '.') { |
| AddLiteralCharAdvance(); |
| @@ -544,6 +554,10 @@ |
| } while (c0_ >= '0' && c0_ <= '9'); |
| } |
| literal.Complete(); |
| + ASSERT_NOT_NULL(next_.literal_chars); |
| + number = StringToDouble(next_.literal_chars->ascii_literal(), |
| + NO_FLAGS, // Hex, octal or trailing junk. |
| + OS::nan_value()); |
| return Token::NUMBER; |
| } |