| 229 | |
| 230 | template <typename Type> |
| 231 | static int ParseFloat(const char* str, const ScanSpecification& spec, Type* value) |
| 232 | { |
| 233 | if (!spec.SpecifierMatch("aefgAEFG")) { |
| 234 | LOG(DFATAL) << "Invalid scan specifier '" << spec.specifier |
| 235 | << "' for float type"; |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | const char* s = str; |
| 240 | SkipLeadingSpaces(&s); |
| 241 | char* endptr; |
| 242 | Type v; |
| 243 | |
| 244 | if (sizeof(Type) == sizeof(float)) { // NOLINT(runtime/sizeof) |
| 245 | v = strtof(s, &endptr); |
| 246 | } else if (sizeof(Type) == sizeof(double)) { // NOLINT(runtime/sizeof) |
| 247 | v = strtod(s, &endptr); |
| 248 | } else if (sizeof(Type) == sizeof(long double)) { // NOLINT(runtime/sizeof) |
| 249 | v = strtold(s, &endptr); |
| 250 | } |
| 251 | |
| 252 | if (endptr == s) // Nothing parsed |
| 253 | return 0; |
| 254 | |
| 255 | *value = v; |
| 256 | return endptr - str; |
| 257 | } |
| 258 | |
| 259 | int ScanValueParser<float>::Parse(const char* str, |
| 260 | const ScanSpecification& spec, |
no test coverage detected