diff options
author | Abseil Team <absl-team@google.com> | 2018-02-09 11:56:54 -0800 |
---|---|---|
committer | Daniel Katz <katzdm@google.com> | 2018-02-09 20:09:05 +0000 |
commit | 0dc82b9d55e1616c1745d05973d40c9901903cc9 (patch) | |
tree | 9eaf6866f9625dcaac4c07790fbc06ff3fc099cf /absl/strings/str_cat.h | |
parent | 4791df7d1ac966e6c7abdeffafa5030d718500df (diff) |
Changes imported from Abseil "staging" branch:
- a0405e7870a80a9dbc6784b06795e7df5a8c90f5 Internal change by Daniel Katz <katzdm@google.com>
- 2888fe17796d7afa45f4b6ca7eb8e88f52739c39 StrCat: Support zero-padding and space-padding for decima... by Jorg Brown <jorg@google.com>
- feebc521195241783730df9700394f6585550ff2 Merge GitHub PR #91. by Derek Mauro <dmauro@google.com>
- e8164335efefb7335f407c17a16fce2ba4f24e3e This changes the value base_internal::kOnceDone from 32-b... by Abseil Team <absl-team@google.com>
- 0f6085f3f0ee1d6baf9a558d07a25c2fcde93273 Remove `compliant` field from some type trait structs. by Matt Armstrong <marmstrong@google.com>
GitOrigin-RevId: a0405e7870a80a9dbc6784b06795e7df5a8c90f5
Change-Id: Ic2efd40f6ec35f79a8aa12d4475cbea3150756d7
Diffstat (limited to 'absl/strings/str_cat.h')
-rw-r--r-- | absl/strings/str_cat.h | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/absl/strings/str_cat.h b/absl/strings/str_cat.h index 1cf7b11f..0c33b6cc 100644 --- a/absl/strings/str_cat.h +++ b/absl/strings/str_cat.h @@ -76,10 +76,10 @@ struct AlphaNumBuffer { } // namespace strings_internal -// Enum that specifies the number of significant digits to return in a `Hex` -// conversion and fill character to use. A `kZeroPad2` value, for example, would -// produce hexadecimal strings such as "0A","0F" and 'kSpacePad5' value would -// produce hexadecimal strings such as " A"," F". +// Enum that specifies the number of significant digits to return in a `Hex` or +// `Dec` conversion and fill character to use. A `kZeroPad2` value, for example, +// would produce hexadecimal strings such as "0A","0F" and a 'kSpacePad5' value +// would produce hexadecimal strings such as " A"," F". enum PadSpec { kNoPad = 1, kZeroPad2, @@ -154,6 +154,32 @@ struct Hex { }; // ----------------------------------------------------------------------------- +// Dec +// ----------------------------------------------------------------------------- +// +// `Dec` stores a set of decimal std::string conversion parameters for use +// within `AlphaNum` std::string conversions. Dec is slower than the default +// integer conversion, so use it only if you need padding. +struct Dec { + uint64_t value; + uint8_t width; + char fill; + bool neg; + + template <typename Int> + explicit Dec(Int v, PadSpec spec = absl::kNoPad, + typename std::enable_if<(sizeof(Int) <= 8)>::type* = nullptr) + : value(v >= 0 ? static_cast<uint64_t>(v) + : uint64_t{0} - static_cast<uint64_t>(v)), + width(spec == absl::kNoPad + ? 1 + : spec >= absl::kSpacePad2 ? spec - absl::kSpacePad2 + 2 + : spec - absl::kZeroPad2 + 2), + fill(spec >= absl::kSpacePad2 ? ' ' : '0'), + neg(v < 0) {} +}; + +// ----------------------------------------------------------------------------- // AlphaNum // ----------------------------------------------------------------------------- // @@ -191,6 +217,7 @@ class AlphaNum { : piece_(digits_, numbers_internal::SixDigitsToBuffer(f, digits_)) {} AlphaNum(Hex hex); // NOLINT(runtime/explicit) + AlphaNum(Dec dec); // NOLINT(runtime/explicit) template <size_t size> AlphaNum( // NOLINT(runtime/explicit) |