aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/third_party/abseil-cpp/absl/strings/str_cat.h
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/third_party/abseil-cpp/absl/strings/str_cat.h')
-rw-r--r--Firestore/third_party/abseil-cpp/absl/strings/str_cat.h62
1 files changed, 50 insertions, 12 deletions
diff --git a/Firestore/third_party/abseil-cpp/absl/strings/str_cat.h b/Firestore/third_party/abseil-cpp/absl/strings/str_cat.h
index 1cf7b11..e38369c 100644
--- a/Firestore/third_party/abseil-cpp/absl/strings/str_cat.h
+++ b/Firestore/third_party/abseil-cpp/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,
@@ -127,21 +127,32 @@ struct Hex {
char fill;
template <typename Int>
- explicit Hex(Int v, PadSpec spec = absl::kNoPad,
- typename std::enable_if<sizeof(Int) == 1>::type* = nullptr)
+ explicit Hex(
+ Int v, PadSpec spec = absl::kNoPad,
+ typename std::enable_if<sizeof(Int) == 1 &&
+ !std::is_pointer<Int>::value>::type* = nullptr)
: Hex(spec, static_cast<uint8_t>(v)) {}
template <typename Int>
- explicit Hex(Int v, PadSpec spec = absl::kNoPad,
- typename std::enable_if<sizeof(Int) == 2>::type* = nullptr)
+ explicit Hex(
+ Int v, PadSpec spec = absl::kNoPad,
+ typename std::enable_if<sizeof(Int) == 2 &&
+ !std::is_pointer<Int>::value>::type* = nullptr)
: Hex(spec, static_cast<uint16_t>(v)) {}
template <typename Int>
- explicit Hex(Int v, PadSpec spec = absl::kNoPad,
- typename std::enable_if<sizeof(Int) == 4>::type* = nullptr)
+ explicit Hex(
+ Int v, PadSpec spec = absl::kNoPad,
+ typename std::enable_if<sizeof(Int) == 4 &&
+ !std::is_pointer<Int>::value>::type* = nullptr)
: Hex(spec, static_cast<uint32_t>(v)) {}
template <typename Int>
- explicit Hex(Int v, PadSpec spec = absl::kNoPad,
- typename std::enable_if<sizeof(Int) == 8>::type* = nullptr)
+ explicit Hex(
+ Int v, PadSpec spec = absl::kNoPad,
+ typename std::enable_if<sizeof(Int) == 8 &&
+ !std::is_pointer<Int>::value>::type* = nullptr)
: Hex(spec, static_cast<uint64_t>(v)) {}
+ template <typename Pointee>
+ explicit Hex(Pointee* v, PadSpec spec = absl::kNoPad)
+ : Hex(spec, reinterpret_cast<uintptr_t>(v)) {}
private:
Hex(PadSpec spec, uint64_t v)
@@ -154,6 +165,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 +228,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)