|
|
|
@ -57,6 +57,7 @@ |
|
|
|
|
#include <cstdint> |
|
|
|
|
#include <string> |
|
|
|
|
#include <type_traits> |
|
|
|
|
#include <utility> |
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
#include "absl/base/port.h" |
|
|
|
@ -76,6 +77,27 @@ struct AlphaNumBuffer { |
|
|
|
|
size_t size; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class StringifySink { |
|
|
|
|
public: |
|
|
|
|
void Append(size_t count, char ch); |
|
|
|
|
|
|
|
|
|
void Append(string_view v); |
|
|
|
|
|
|
|
|
|
bool PutPaddedString(string_view v, int width, int precision, bool left); |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
friend string_view ExtractStringification(StringifySink& sink, const T& v); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
std::string buffer_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
string_view ExtractStringification(StringifySink& sink, const T& v) { |
|
|
|
|
AbslStringify(sink, v); |
|
|
|
|
return sink.buffer_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace strings_internal
|
|
|
|
|
|
|
|
|
|
// Enum that specifies the number of significant digits to return in a `Hex` or
|
|
|
|
@ -208,6 +230,15 @@ struct Dec { |
|
|
|
|
// `StrAppend()`, providing efficient conversion of numeric, boolean, and
|
|
|
|
|
// hexadecimal values (through the `Hex` type) into strings.
|
|
|
|
|
|
|
|
|
|
template <typename T, typename = void> |
|
|
|
|
struct HasAbslStringify : std::false_type {}; |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
struct HasAbslStringify<T, std::enable_if_t<std::is_void<decltype(AbslStringify( |
|
|
|
|
std::declval<strings_internal::StringifySink&>(), |
|
|
|
|
std::declval<const T&>()))>::value>> |
|
|
|
|
: std::true_type {}; |
|
|
|
|
|
|
|
|
|
class AlphaNum { |
|
|
|
|
public: |
|
|
|
|
// No bool ctor -- bools convert to an integral type.
|
|
|
|
@ -255,6 +286,13 @@ class AlphaNum { |
|
|
|
|
: piece_(NullSafeStringView(c_str)) {} // NOLINT(runtime/explicit)
|
|
|
|
|
AlphaNum(absl::string_view pc) : piece_(pc) {} // NOLINT(runtime/explicit)
|
|
|
|
|
|
|
|
|
|
template <typename T, typename = typename std::enable_if< |
|
|
|
|
HasAbslStringify<T>::value>::type> |
|
|
|
|
AlphaNum( // NOLINT(runtime/explicit)
|
|
|
|
|
const T& v, // NOLINT(runtime/explicit)
|
|
|
|
|
strings_internal::StringifySink&& sink = {}) // NOLINT(runtime/explicit)
|
|
|
|
|
: piece_(strings_internal::ExtractStringification(sink, v)) {} |
|
|
|
|
|
|
|
|
|
template <typename Allocator> |
|
|
|
|
AlphaNum( // NOLINT(runtime/explicit)
|
|
|
|
|
const std::basic_string<char, std::char_traits<char>, Allocator>& str) |
|
|
|
|