diff options
author | Abseil Team <absl-team@google.com> | 2023-06-01 13:51:36 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-01 13:52:23 -0700 |
commit | e9bb35cea3d3b18bdaaa273f6e1746d9334aa324 (patch) | |
tree | 3f0a8a484b1edf6cc1520906bcb98a23fc8b8609 /absl/flags/marshalling.cc | |
parent | 01e628d2c82758d65b8bb1757ea9d696c65ae3d8 (diff) |
Adding support for int128 and uint128 flag types
PiperOrigin-RevId: 537120102
Change-Id: I7952e53aca10319eb433e4c4d60cf3d7fe74d19a
Diffstat (limited to 'absl/flags/marshalling.cc')
-rw-r--r-- | absl/flags/marshalling.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/absl/flags/marshalling.cc b/absl/flags/marshalling.cc index 81f9cebd..cf6312b1 100644 --- a/absl/flags/marshalling.cc +++ b/absl/flags/marshalling.cc @@ -26,6 +26,7 @@ #include "absl/base/config.h" #include "absl/base/log_severity.h" #include "absl/base/macros.h" +#include "absl/numeric/int128.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" @@ -125,6 +126,32 @@ bool AbslParseFlag(absl::string_view text, unsigned long long* dst, return ParseFlagImpl(text, *dst); } +bool AbslParseFlag(absl::string_view text, absl::int128* dst, std::string*) { + text = absl::StripAsciiWhitespace(text); + + // check hex + int base = NumericBase(text); + if (!absl::numbers_internal::safe_strto128_base(text, dst, base)) { + return false; + } + + return base == 16 ? absl::SimpleHexAtoi(text, dst) + : absl::SimpleAtoi(text, dst); +} + +bool AbslParseFlag(absl::string_view text, absl::uint128* dst, std::string*) { + text = absl::StripAsciiWhitespace(text); + + // check hex + int base = NumericBase(text); + if (!absl::numbers_internal::safe_strtou128_base(text, dst, base)) { + return false; + } + + return base == 16 ? absl::SimpleHexAtoi(text, dst) + : absl::SimpleAtoi(text, dst); +} + // -------------------------------------------------------------------- // AbslParseFlag for floating point types. |