specialized for reading an integer value. not using the standard strtol() for speed reason.
| 2699 | // specialized for reading an integer value. |
| 2700 | // not using the standard strtol() for speed reason. |
| 2701 | vtkTypeInt64 vtkFoamFile::ReadIntegerValue() |
| 2702 | { |
| 2703 | // skip prepending invalid chars |
| 2704 | // expanded the outermost loop in nextTokenHead() for performance |
| 2705 | int c; |
| 2706 | while (std::isspace(c = this->Getc())) // isspace() accepts -1 as EOF |
| 2707 | { |
| 2708 | if (c == '\n') |
| 2709 | { |
| 2710 | ++this->Superclass::LineNumber; |
| 2711 | #if VTK_FOAMFILE_RECOGNIZE_LINEHEAD |
| 2712 | this->Superclass::WasNewline = true; |
| 2713 | #endif |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | // If a '/' is encountered, handle it as a comment/alternative token start. |
| 2718 | if (c == '/') |
| 2719 | { |
| 2720 | this->PutBack(c); |
| 2721 | c = this->NextTokenHead(); |
| 2722 | } |
| 2723 | |
| 2724 | // leading sign? |
| 2725 | const bool negNum = (c == '-'); |
| 2726 | if (negNum || c == '+') |
| 2727 | { |
| 2728 | c = this->Getc(); |
| 2729 | if (c == '\n') |
| 2730 | { |
| 2731 | ++this->Superclass::LineNumber; |
| 2732 | #if VTK_FOAMFILE_RECOGNIZE_LINEHEAD |
| 2733 | this->Superclass::WasNewline = true; |
| 2734 | #endif |
| 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | if (!std::isdigit(c)) // isdigit() accepts -1 as EOF |
| 2739 | { |
| 2740 | if (c == EOF) |
| 2741 | { |
| 2742 | this->ThrowUnexpectedEOFException(); |
| 2743 | } |
| 2744 | else |
| 2745 | { |
| 2746 | this->ThrowUnexpectedNondigitException(c); |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | // Add the first digit. |
| 2751 | vtkTypeInt64 num = c - '0'; |
| 2752 | // Continue collecting all the following digits. |
| 2753 | while (std::isdigit(c = this->Getc())) |
| 2754 | { |
| 2755 | num = 10 * num + c - '0'; |
| 2756 | } |
| 2757 | |
| 2758 | if (c == EOF) |
no test coverage detected