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
This commit is contained in:
parent
4791df7d1a
commit
0dc82b9d55
6 changed files with 151 additions and 18 deletions
|
|
@ -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,
|
||||
|
|
@ -153,6 +153,32 @@ struct Hex {
|
|||
fill(spec >= absl::kSpacePad2 ? ' ' : '0') {}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue