| 2078 | |
| 2079 | template <unsigned Digits10, class ExponentType, class Allocator> |
| 2080 | bool cpp_dec_float<Digits10, ExponentType, Allocator>::rd_string(const char* const s) |
| 2081 | { |
| 2082 | #ifndef BOOST_NO_EXCEPTIONS |
| 2083 | try |
| 2084 | { |
| 2085 | #endif |
| 2086 | |
| 2087 | std::string str(s); |
| 2088 | static const std::string valid_characters{"0123456789"}; |
| 2089 | |
| 2090 | // TBD: Using several regular expressions may significantly reduce |
| 2091 | // the code complexity (and perhaps the run-time) of rd_string(). |
| 2092 | |
| 2093 | // Get a possible exponent and remove it. |
| 2094 | exp = static_cast<exponent_type>(0); |
| 2095 | |
| 2096 | std::size_t pos; |
| 2097 | |
| 2098 | if (((pos = str.find('e')) != std::string::npos) || ((pos = str.find('E')) != std::string::npos)) |
| 2099 | { |
| 2100 | // Remove the exponent part from the string. |
| 2101 | #ifndef BOOST_MP_STANDALONE |
| 2102 | exp = boost::lexical_cast<exponent_type>(static_cast<const char*>(str.c_str() + (pos + 1u))); |
| 2103 | #else |
| 2104 | if (str.find_first_not_of(valid_characters, ((str[pos + 1] == '+') || (str[pos + 1] == '-')) ? pos + 2 : pos + 1) != std::string::npos) |
| 2105 | BOOST_MP_THROW_EXCEPTION(std::runtime_error("Can not construct a floating point with non-numeric content")); |
| 2106 | exp = static_cast<exponent_type>(std::atoll(static_cast<const char*>(str.c_str() + (pos + 1u)))); |
| 2107 | #endif |
| 2108 | |
| 2109 | str = str.substr(static_cast<std::size_t>(0u), pos); |
| 2110 | } |
| 2111 | |
| 2112 | // Get a possible +/- sign and remove it. |
| 2113 | neg = false; |
| 2114 | |
| 2115 | if (str.size()) |
| 2116 | { |
| 2117 | if (str[0] == '-') |
| 2118 | { |
| 2119 | neg = true; |
| 2120 | str.erase(0, 1); |
| 2121 | } |
| 2122 | else if (str[0] == '+') |
| 2123 | { |
| 2124 | str.erase(0, 1); |
| 2125 | } |
| 2126 | } |
| 2127 | // |
| 2128 | // Special cases for infinities and NaN's: |
| 2129 | // |
| 2130 | if ((str == "inf") || (str == "INF") || (str == "infinity") || (str == "INFINITY")) |
| 2131 | { |
| 2132 | if (neg) |
| 2133 | { |
| 2134 | *this = this->inf(); |
| 2135 | this->negate(); |
| 2136 | } |
| 2137 | else |
nothing calls this directly
no test coverage detected