Parses 'str' for a double. If successful, writes the result to *value and returns true; otherwise leaves *value unchanged and returns false.
| 66 | // Parses 'str' for a double. If successful, writes the result to *value and |
| 67 | // returns true; otherwise leaves *value unchanged and returns false. |
| 68 | bool ParseDouble(const std::string& src_text, const char* str, double* value) { |
| 69 | // Parses the environment variable as a decimal integer. |
| 70 | char* end = nullptr; |
| 71 | const double double_value = strtod(str, &end); // NOLINT |
| 72 | |
| 73 | // Has strtol() consumed all characters in the string? |
| 74 | if (*end != '\0') { |
| 75 | // No - an invalid character was encountered. |
| 76 | std::cerr << src_text << " is expected to be a double, " |
| 77 | << "but actually has value \"" << str << "\".\n"; |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | *value = double_value; |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | // Parses 'str' into KV pairs. If successful, writes the result to *value and |
| 86 | // returns true; otherwise leaves *value unchanged and returns false. |
no outgoing calls
no test coverage detected