| 346 | } |
| 347 | |
| 348 | bool safe_strtod(StringPiece str, double* value) { |
| 349 | int processed_characters_count = -1; |
| 350 | auto len = str.size(); |
| 351 | |
| 352 | // If string length exceeds buffer size or int max, fail. |
| 353 | if (len >= kFastToBufferSize) return false; |
| 354 | if (len > std::numeric_limits<int>::max()) return false; |
| 355 | |
| 356 | *value = StringToFloatConverter().StringToDouble( |
| 357 | str.data(), static_cast<int>(len), &processed_characters_count); |
| 358 | return processed_characters_count > 0; |
| 359 | } |
| 360 | |
| 361 | size_t FloatToBuffer(float value, char* buffer) { |
| 362 | // FLT_DIG is 6 for IEEE-754 floats, which are used on almost all |