| 579 | |
| 580 | |
| 581 | bool |
| 582 | Reader::decodeNumber( Token &token ) |
| 583 | { |
| 584 | bool isDouble = false; |
| 585 | for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) |
| 586 | { |
| 587 | isDouble = isDouble |
| 588 | || in( *inspect, '.', 'e', 'E', '+' ) |
| 589 | || ( *inspect == '-' && inspect != token.start_ ); |
| 590 | } |
| 591 | if ( isDouble ) |
| 592 | return decodeDouble( token ); |
| 593 | Location current = token.start_; |
| 594 | bool isNegative = *current == '-'; |
| 595 | if ( isNegative ) |
| 596 | ++current; |
| 597 | Value::UInt threshold = (isNegative ? Value::UInt(-Value::minInt) |
| 598 | : Value::maxUInt) / 10; |
| 599 | Value::UInt value = 0; |
| 600 | while ( current < token.end_ ) |
| 601 | { |
| 602 | Char c = *current++; |
| 603 | if ( c < '0' || c > '9' ) |
| 604 | return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); |
| 605 | if ( value >= threshold ) |
| 606 | return decodeDouble( token ); |
| 607 | value = value * 10 + Value::UInt(c - '0'); |
| 608 | } |
| 609 | if ( isNegative ) |
| 610 | currentValue() = -Value::Int( value ); |
| 611 | else if ( value <= Value::UInt(Value::maxInt) ) |
| 612 | currentValue() = Value::Int( value ); |
| 613 | else |
| 614 | currentValue() = value; |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | |
| 619 | bool |