MCPcopy Create free account
hub / github.com/chen3feng/toft / ParseFloat

Function ParseFloat

base/string/format/scan_arg.cpp:231–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229
230template <typename Type>
231static 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
259int ScanValueParser<float>::Parse(const char* str,
260 const ScanSpecification& spec,

Callers 1

ParseMethod · 0.85

Calls 2

SkipLeadingSpacesFunction · 0.85
SpecifierMatchMethod · 0.80

Tested by

no test coverage detected