| 37 | |
| 38 | template <typename T> |
| 39 | bool ToReal(char const * start, T & result) |
| 40 | { |
| 41 | // Try faster implementation first. |
| 42 | double d; |
| 43 | // TODO(AB): replace with more robust dependency that doesn't use std::is_finite in the implementation. |
| 44 | char const * endptr = fast_double_parser::parse_number(start, &d); |
| 45 | if (endptr == nullptr) |
| 46 | { |
| 47 | // Fallback to our implementation, it supports numbers like "1." |
| 48 | char * stop; |
| 49 | result = RealConverter<T>(start, &stop); |
| 50 | if (*stop == 0 && start != stop && math::is_finite(result)) |
| 51 | return true; |
| 52 | } |
| 53 | else if (*endptr == 0 && math::is_finite(d)) |
| 54 | { |
| 55 | result = static_cast<T>(d); |
| 56 | return true; |
| 57 | } |
| 58 | // Do not parse strings that contain additional non-number characters. |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | } // namespace |
| 63 | |