reading a double value from a string
| 2766 | |
| 2767 | // reading a double value from a string |
| 2768 | double vtkFoamFile::ReadDoubleValue() |
| 2769 | { |
| 2770 | int c; |
| 2771 | // Skip whitespace, update line numbers, and handle newlines. |
| 2772 | while (std::isspace(c = this->Getc())) |
| 2773 | { |
| 2774 | if (c == '\n') |
| 2775 | { |
| 2776 | ++this->Superclass::LineNumber; |
| 2777 | #if VTK_FOAMFILE_RECOGNIZE_LINEHEAD |
| 2778 | this->Superclass::WasNewline = true; |
| 2779 | #endif |
| 2780 | } |
| 2781 | } |
| 2782 | if (c == '/') |
| 2783 | { |
| 2784 | this->PutBack(c); |
| 2785 | c = this->NextTokenHead(); |
| 2786 | } |
| 2787 | |
| 2788 | // Prepare token accumulation. |
| 2789 | size_t size = 0; |
| 2790 | std::array<char, 1024> buffer; |
| 2791 | |
| 2792 | // Optional leading sign. |
| 2793 | if (c == '-' || c == '+') |
| 2794 | { |
| 2795 | buffer[size++] = static_cast<char>(c); |
| 2796 | c = this->Getc(); |
| 2797 | if (c == '\n') |
| 2798 | { |
| 2799 | ++this->Superclass::LineNumber; |
| 2800 | #if VTK_FOAMFILE_RECOGNIZE_LINEHEAD |
| 2801 | this->Superclass::WasNewline = true; |
| 2802 | #endif |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | // The first character must be a digit or a decimal point. |
| 2807 | if (!std::isdigit(c) && c != '.') // Attention: isdigit() accepts EOF |
| 2808 | { |
| 2809 | this->ThrowUnexpectedNondigitException(c); |
| 2810 | } |
| 2811 | |
| 2812 | // Read integer part (before '.'). |
| 2813 | if (c != '.') |
| 2814 | { |
| 2815 | // Accumulate the first digit. |
| 2816 | buffer[size++] = static_cast<char>(c); |
| 2817 | while (std::isdigit(c = this->Getc())) |
| 2818 | { |
| 2819 | buffer[size++] = static_cast<char>(c); |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | // Read decimal part (after '.'). |
| 2824 | if (c == '.') |
| 2825 | { |
no test coverage detected