Export of internal Abseil changes.
-- 7fa1107161a03dac53fb84c2b06d8092616c7b13 by Abseil Team <absl-team@google.com>: Harden the generic stacktrace implementation for use during early program execution PiperOrigin-RevId: 226375950 -- 079f9969329f5eb66f647dd3c44b17541b1bf217 by Matt Kulukundis <kfm@google.com>: Workaround platforms that have over-aggressive warnings on -Wexit-time-destructors PiperOrigin-RevId: 226362948 -- 1447943f509be681ca5495add0162c750ef237f1 by Matt Kulukundis <kfm@google.com>: Switch from 64 to size_t atomics so they work on embedded platforms that do not have 64 bit atomics. PiperOrigin-RevId: 226210704 -- d14d49837ae2bcde74051e0c79c18ee0f43866b9 by Tom Manshreck <shreck@google.com>: Develop initial documentation for API breaking changes process: PiperOrigin-RevId: 226210021 -- 7ea3d7fe0e86979dab83a5fc9cc3bf1d6cb3bd53 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 226195522 -- 7de873e880d7f016a4fa1e08d626f0535cc470af by Abseil Team <absl-team@google.com>: Make Abseil LICENSE files newline terminated, with a single trailing blank line. Also remove line-ending whitespace. PiperOrigin-RevId: 226182949 -- 7d00643fadfad7f0d992c68bd9d2ed2e5bc960b0 by Matt Kulukundis <kfm@google.com>: Internal cleanup PiperOrigin-RevId: 226045282 -- c4a0a11c0ce2875271191e477f3d36eaaeca4613 by Matt Kulukundis <kfm@google.com>: Internal cleanup PiperOrigin-RevId: 226038273 -- 8ee4ebbb1ae5cda119e436e5ff7e3aa966608c10 by Matt Kulukundis <kfm@google.com>: Adds a global sampler which tracks a fraction of live tables for collecting telemetry data. PiperOrigin-RevId: 226032080 -- d576446f050518cd1b0ae447d682d8552f0e7e30 by Mark Barolak <mbar@google.com>: Replace an internal CaseEqual function with calls to the identical absl::EqualsIgnoreCase. This closes out a rather old TODO. PiperOrigin-RevId: 226024779 -- 6b23f1ee028a5ffa608c920424f1220a117a8f3d by Abseil Team <absl-team@google.com>: Add December 2018 LTS branch to list of LTS branches. PiperOrigin-RevId: 226011333 -- bb0833a43bdaef4c8c059b17bcd27ba9a085a114 by Mark Barolak <mbar@google.com>: Explicitly state that when the SimpleAtoi family of functions encounter an error, the value of their output parameter is unspecified. Also standardize the name of the output parameter to be `out`. PiperOrigin-RevId: 225997035 -- 46c1876b1a248eabda7545daa61a74a4cdfe9077 by Abseil Team <absl-team@google.com>: Remove deprecated CMake function absl_test, absl_library and absl_header_library PiperOrigin-RevId: 225950041 GitOrigin-RevId: 7fa1107161a03dac53fb84c2b06d8092616c7b13 Change-Id: I2ca9d3aada9292614527d1339a7557494139b806
This commit is contained in:
parent
3e2e9b5557
commit
968a34ffda
16 changed files with 1313 additions and 348 deletions
|
|
@ -35,17 +35,18 @@
|
|||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/charconv.h"
|
||||
#include "absl/strings/internal/memutil.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
|
||||
namespace absl {
|
||||
|
||||
bool SimpleAtof(absl::string_view str, float* value) {
|
||||
*value = 0.0;
|
||||
bool SimpleAtof(absl::string_view str, float* out) {
|
||||
*out = 0.0;
|
||||
str = StripAsciiWhitespace(str);
|
||||
if (!str.empty() && str[0] == '+') {
|
||||
str.remove_prefix(1);
|
||||
}
|
||||
auto result = absl::from_chars(str.data(), str.data() + str.size(), *value);
|
||||
auto result = absl::from_chars(str.data(), str.data() + str.size(), *out);
|
||||
if (result.ec == std::errc::invalid_argument) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -56,22 +57,22 @@ bool SimpleAtof(absl::string_view str, float* value) {
|
|||
// from_chars() with DR 3801's current wording will return max() on
|
||||
// overflow. SimpleAtof returns infinity instead.
|
||||
if (result.ec == std::errc::result_out_of_range) {
|
||||
if (*value > 1.0) {
|
||||
*value = std::numeric_limits<float>::infinity();
|
||||
} else if (*value < -1.0) {
|
||||
*value = -std::numeric_limits<float>::infinity();
|
||||
if (*out > 1.0) {
|
||||
*out = std::numeric_limits<float>::infinity();
|
||||
} else if (*out < -1.0) {
|
||||
*out = -std::numeric_limits<float>::infinity();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimpleAtod(absl::string_view str, double* value) {
|
||||
*value = 0.0;
|
||||
bool SimpleAtod(absl::string_view str, double* out) {
|
||||
*out = 0.0;
|
||||
str = StripAsciiWhitespace(str);
|
||||
if (!str.empty() && str[0] == '+') {
|
||||
str.remove_prefix(1);
|
||||
}
|
||||
auto result = absl::from_chars(str.data(), str.data() + str.size(), *value);
|
||||
auto result = absl::from_chars(str.data(), str.data() + str.size(), *out);
|
||||
if (result.ec == std::errc::invalid_argument) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -82,10 +83,10 @@ bool SimpleAtod(absl::string_view str, double* value) {
|
|||
// from_chars() with DR 3801's current wording will return max() on
|
||||
// overflow. SimpleAtod returns infinity instead.
|
||||
if (result.ec == std::errc::result_out_of_range) {
|
||||
if (*value > 1.0) {
|
||||
*value = std::numeric_limits<double>::infinity();
|
||||
} else if (*value < -1.0) {
|
||||
*value = -std::numeric_limits<double>::infinity();
|
||||
if (*out > 1.0) {
|
||||
*out = std::numeric_limits<double>::infinity();
|
||||
} else if (*out < -1.0) {
|
||||
*out = -std::numeric_limits<double>::infinity();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -93,14 +94,6 @@ bool SimpleAtod(absl::string_view str, double* value) {
|
|||
|
||||
namespace {
|
||||
|
||||
// TODO(rogeeff): replace with the real released thing once we figure out what
|
||||
// it is.
|
||||
inline bool CaseEqual(absl::string_view piece1, absl::string_view piece2) {
|
||||
return (piece1.size() == piece2.size() &&
|
||||
0 == strings_internal::memcasecmp(piece1.data(), piece2.data(),
|
||||
piece1.size()));
|
||||
}
|
||||
|
||||
// Writes a two-character representation of 'i' to 'buf'. 'i' must be in the
|
||||
// range 0 <= i < 100, and buf must have space for two characters. Example:
|
||||
// char buf[2];
|
||||
|
|
@ -136,18 +129,18 @@ inline void PutTwoDigits(size_t i, char* buf) {
|
|||
|
||||
} // namespace
|
||||
|
||||
bool SimpleAtob(absl::string_view str, bool* value) {
|
||||
ABSL_RAW_CHECK(value != nullptr, "Output pointer must not be nullptr.");
|
||||
if (CaseEqual(str, "true") || CaseEqual(str, "t") ||
|
||||
CaseEqual(str, "yes") || CaseEqual(str, "y") ||
|
||||
CaseEqual(str, "1")) {
|
||||
*value = true;
|
||||
bool SimpleAtob(absl::string_view str, bool* out) {
|
||||
ABSL_RAW_CHECK(out != nullptr, "Output pointer must not be nullptr.");
|
||||
if (EqualsIgnoreCase(str, "true") || EqualsIgnoreCase(str, "t") ||
|
||||
EqualsIgnoreCase(str, "yes") || EqualsIgnoreCase(str, "y") ||
|
||||
EqualsIgnoreCase(str, "1")) {
|
||||
*out = true;
|
||||
return true;
|
||||
}
|
||||
if (CaseEqual(str, "false") || CaseEqual(str, "f") ||
|
||||
CaseEqual(str, "no") || CaseEqual(str, "n") ||
|
||||
CaseEqual(str, "0")) {
|
||||
*value = false;
|
||||
if (EqualsIgnoreCase(str, "false") || EqualsIgnoreCase(str, "f") ||
|
||||
EqualsIgnoreCase(str, "no") || EqualsIgnoreCase(str, "n") ||
|
||||
EqualsIgnoreCase(str, "0")) {
|
||||
*out = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ namespace absl {
|
|||
// Converts the given string into an integer value, returning `true` if
|
||||
// successful. The string must reflect a base-10 integer (optionally followed or
|
||||
// preceded by ASCII whitespace) whose value falls within the range of the
|
||||
// integer type.
|
||||
// integer type. If any errors are encountered, this function returns `false`,
|
||||
// leaving `out` in an unspecified state.
|
||||
template <typename int_type>
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out);
|
||||
|
||||
|
|
@ -53,24 +54,28 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out);
|
|||
// Converts the given string (optionally followed or preceded by ASCII
|
||||
// whitespace) into a float, which may be rounded on overflow or underflow.
|
||||
// See http://en.cppreference.com/w/c/string/byte/strtof for details about the
|
||||
// allowed formats for `str`.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str, float* value);
|
||||
// allowed formats for `str`. If any errors are encountered, this function
|
||||
// returns `false`, leaving `out` in an unspecified state.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str, float* out);
|
||||
|
||||
// SimpleAtod()
|
||||
//
|
||||
// Converts the given string (optionally followed or preceded by ASCII
|
||||
// whitespace) into a double, which may be rounded on overflow or underflow.
|
||||
// See http://en.cppreference.com/w/c/string/byte/strtof for details about the
|
||||
// allowed formats for `str`.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str, double* value);
|
||||
// allowed formats for `str`. If any errors are encountered, this function
|
||||
// returns `false`, leaving `out` in an unspecified state.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str, double* out);
|
||||
|
||||
// SimpleAtob()
|
||||
//
|
||||
// Converts the given string into a boolean, returning `true` if successful.
|
||||
// The following case-insensitive strings are interpreted as boolean `true`:
|
||||
// "true", "t", "yes", "y", "1". The following case-insensitive strings
|
||||
// are interpreted as boolean `false`: "false", "f", "no", "n", "0".
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtob(absl::string_view str, bool* value);
|
||||
// are interpreted as boolean `false`: "false", "f", "no", "n", "0". If any
|
||||
// errors are encountered, this function returns `false`, leaving `out` in an
|
||||
// unspecified state.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtob(absl::string_view str, bool* out);
|
||||
|
||||
} // namespace absl
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue