diff options
author | Abseil Team <absl-team@google.com> | 2021-03-01 06:24:39 -0800 |
---|---|---|
committer | vslashg <gfalcon@google.com> | 2021-03-01 11:09:42 -0500 |
commit | a76698790753d2ec71f655cdc84d61bcb27780d4 (patch) | |
tree | 86722313204661d2e0501b1fa6f9d8b439ae8757 /absl/strings/numbers.cc | |
parent | 998805a4c79d5d7a771f7e5a8ee3cbbbcba04f94 (diff) |
Export of internal Abseil changes
--
a9eb3c976c6d8ef4fca3d416847f8fca4bd90dd7 by Derek Mauro <dmauro@google.com>:
Remove the deprecated container library, which doesn't do anything.
This will help prevent user confusion, as seen in #183.
PiperOrigin-RevId: 360172262
--
4f872f651e25a528bdc59ee4e24543fbbd358f00 by Abseil Team <absl-team@google.com>:
Remove unused nspace alias.
PiperOrigin-RevId: 359487559
--
43e877e464886cf9226012f5bb47910b8995e70f by Abseil Team <absl-team@google.com>:
Create a StatusToStringMode to control how the ToString behaves.
PiperOrigin-RevId: 359339603
--
0da1291569e167341613359846948c72c8a838e1 by Greg Falcon <gfalcon@google.com>:
Fix a bug in SimpleAtoi/SimpleAtof, which accepted a prefix of "+-" (e.g., "+-5" was parsed as 5.0).
This regression was introduced when we migrated these functions to use absl::from_chars.
PiperOrigin-RevId: 359135105
GitOrigin-RevId: a9eb3c976c6d8ef4fca3d416847f8fca4bd90dd7
Change-Id: I0e2072cad80651e473ba1d34b1fb3a033dfaba80
Diffstat (limited to 'absl/strings/numbers.cc')
-rw-r--r-- | absl/strings/numbers.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/absl/strings/numbers.cc b/absl/strings/numbers.cc index e6bf44ce..966d94bd 100644 --- a/absl/strings/numbers.cc +++ b/absl/strings/numbers.cc @@ -46,8 +46,13 @@ ABSL_NAMESPACE_BEGIN bool SimpleAtof(absl::string_view str, float* out) { *out = 0.0; str = StripAsciiWhitespace(str); + // std::from_chars doesn't accept an initial +, but SimpleAtof does, so if one + // is present, skip it, while avoiding accepting "+-0" as valid. if (!str.empty() && str[0] == '+') { str.remove_prefix(1); + if (!str.empty() && str[0] == '-') { + return false; + } } auto result = absl::from_chars(str.data(), str.data() + str.size(), *out); if (result.ec == std::errc::invalid_argument) { @@ -72,8 +77,13 @@ bool SimpleAtof(absl::string_view str, float* out) { bool SimpleAtod(absl::string_view str, double* out) { *out = 0.0; str = StripAsciiWhitespace(str); + // std::from_chars doesn't accept an initial +, but SimpleAtod does, so if one + // is present, skip it, while avoiding accepting "+-0" as valid. if (!str.empty() && str[0] == '+') { str.remove_prefix(1); + if (!str.empty() && str[0] == '-') { + return false; + } } auto result = absl::from_chars(str.data(), str.data() + str.size(), *out); if (result.ec == std::errc::invalid_argument) { |