| 1887 | |
| 1888 | template <unsigned Digits10, class ExponentType, class Allocator> |
| 1889 | bool cpp_dec_float<Digits10, ExponentType, Allocator>::rd_string(const char* const s) |
| 1890 | { |
| 1891 | try{ |
| 1892 | |
| 1893 | std::string str(s); |
| 1894 | |
| 1895 | // TBD: Using several regular expressions may significantly reduce |
| 1896 | // the code complexity (and perhaps the run-time) of rd_string(). |
| 1897 | |
| 1898 | // Get a possible exponent and remove it. |
| 1899 | exp = static_cast<ExponentType>(0); |
| 1900 | |
| 1901 | std::size_t pos; |
| 1902 | |
| 1903 | if( ((pos = str.find('e')) != std::string::npos) |
| 1904 | || ((pos = str.find('E')) != std::string::npos) |
| 1905 | ) |
| 1906 | { |
| 1907 | // Remove the exponent part from the string. |
| 1908 | exp = boost::lexical_cast<ExponentType>(static_cast<const char*>(str.c_str() + (pos + 1u))); |
| 1909 | str = str.substr(static_cast<std::size_t>(0u), pos); |
| 1910 | } |
| 1911 | |
| 1912 | // Get a possible +/- sign and remove it. |
| 1913 | neg = false; |
| 1914 | |
| 1915 | if(str.size()) |
| 1916 | { |
| 1917 | if(str[0] == '-') |
| 1918 | { |
| 1919 | neg = true; |
| 1920 | str.erase(0, 1); |
| 1921 | } |
| 1922 | else if(str[0] == '+') |
| 1923 | { |
| 1924 | str.erase(0, 1); |
| 1925 | } |
| 1926 | } |
| 1927 | // |
| 1928 | // Special cases for infinities and NaN's: |
| 1929 | // |
| 1930 | if((str == "inf") || (str == "INF") || (str == "infinity") || (str == "INFINITY")) |
| 1931 | { |
| 1932 | if(neg) |
| 1933 | { |
| 1934 | *this = this->inf(); |
| 1935 | this->negate(); |
| 1936 | } |
| 1937 | else |
| 1938 | *this = this->inf(); |
| 1939 | return true; |
| 1940 | } |
| 1941 | if((str.size() >= 3) && ((str.substr(0, 3) == "nan") || (str.substr(0, 3) == "NAN") || (str.substr(0, 3) == "NaN"))) |
| 1942 | { |
| 1943 | *this = this->nan(); |
| 1944 | return true; |
| 1945 | } |
| 1946 |
nothing calls this directly
no test coverage detected