Export of internal Abseil changes.
-- f4bb8afa9376b4120f56f3beff7b07260da4a5c2 by CJ Johnson <johnsoncj@google.com>: Add user to Github list PiperOrigin-RevId: 209630262 GitOrigin-RevId: f4bb8afa9376b4120f56f3beff7b07260da4a5c2 Change-Id: I3fedf35011d805ee4a20b92e073b43523b47d15b
This commit is contained in:
parent
fefc83638f
commit
bed5bd6e18
54 changed files with 302 additions and 302 deletions
|
@ -100,7 +100,7 @@
|
|||
// ABSL_PRINTF_ATTRIBUTE
|
||||
// ABSL_SCANF_ATTRIBUTE
|
||||
//
|
||||
// Tells the compiler to perform `printf` format std::string checking if the
|
||||
// Tells the compiler to perform `printf` format string checking if the
|
||||
// compiler supports it; see the 'format' attribute in
|
||||
// <http://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html>.
|
||||
//
|
||||
|
|
|
@ -199,7 +199,7 @@
|
|||
#define ABSL_HAVE_INTRINSIC_INT128 1
|
||||
#elif defined(__CUDACC__)
|
||||
// __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
|
||||
// std::string explaining that it has been removed starting with CUDA 9. We use
|
||||
// string explaining that it has been removed starting with CUDA 9. We use
|
||||
// nested #ifs because there is no short-circuiting in the preprocessor.
|
||||
// NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
|
||||
#if __CUDACC_VER__ >= 70000
|
||||
|
|
|
@ -179,7 +179,7 @@ TEST(ThrowingValueTest, ThrowingStreamOps) {
|
|||
}
|
||||
|
||||
// Tests the operator<< of ThrowingValue by forcing ConstructorTracker to emit
|
||||
// a nonfatal failure that contains the std::string representation of the Thrower
|
||||
// a nonfatal failure that contains the string representation of the Thrower
|
||||
TEST(ThrowingValueTest, StreamOpsOutput) {
|
||||
using ::testing::TypeSpec;
|
||||
exceptions_internal::ConstructorTracker ct(exceptions_internal::countdown);
|
||||
|
|
|
@ -114,7 +114,7 @@ void SafeWriteToStderr(const char *s, size_t len);
|
|||
|
||||
// compile-time function to get the "base" filename, that is, the part of
|
||||
// a filename after the last "/" or "\" path separator. The search starts at
|
||||
// the end of the std::string; the second parameter is the length of the std::string.
|
||||
// the end of the string; the second parameter is the length of the string.
|
||||
constexpr const char* Basename(const char* fname, int offset) {
|
||||
return offset == 0 || fname[offset - 1] == '/' || fname[offset - 1] == '\\'
|
||||
? fname + offset
|
||||
|
|
|
@ -39,7 +39,7 @@ constexpr std::array<absl::LogSeverity, 4> LogSeverities() {
|
|||
absl::LogSeverity::kError, absl::LogSeverity::kFatal}};
|
||||
}
|
||||
|
||||
// Returns the all-caps std::string representation (e.g. "INFO") of the specified
|
||||
// Returns the all-caps string representation (e.g. "INFO") of the specified
|
||||
// severity level if it is one of the normal levels and "UNKNOWN" otherwise.
|
||||
constexpr const char* LogSeverityName(absl::LogSeverity s) {
|
||||
return s == absl::LogSeverity::kInfo
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST(RawLoggingCompilationTest, PassingCheck) {
|
|||
}
|
||||
|
||||
// Not all platforms support output from raw log, so we don't verify any
|
||||
// particular output for RAW check failures (expecting the empty std::string
|
||||
// particular output for RAW check failures (expecting the empty string
|
||||
// accomplishes this). This test is primarily a compilation test, but we
|
||||
// are verifying process death when EXPECT_DEATH works for a platform.
|
||||
const char kExpectedDeathOutput[] = "";
|
||||
|
|
|
@ -66,7 +66,7 @@ BENCHMARK(BM_StdVectorFill)->Range(0, 1024);
|
|||
// The purpose of the next two benchmarks is to verify that
|
||||
// absl::InlinedVector is efficient when moving is more efficent than
|
||||
// copying. To do so, we use strings that are larger than the short
|
||||
// std::string optimization.
|
||||
// string optimization.
|
||||
bool StringRepresentedInline(std::string s) {
|
||||
const char* chars = s.data();
|
||||
std::string s1 = std::move(s);
|
||||
|
|
|
@ -340,7 +340,7 @@ static bool ZeroOrMore(ParseFunc parse_func, State *state) {
|
|||
}
|
||||
|
||||
// Append "str" at "out_cur_idx". If there is an overflow, out_cur_idx is
|
||||
// set to out_end_idx+1. The output std::string is ensured to
|
||||
// set to out_end_idx+1. The output string is ensured to
|
||||
// always terminate with '\0' as long as there is no overflow.
|
||||
static void Append(State *state, const char *const str, const int length) {
|
||||
for (int i = 0; i < length; ++i) {
|
||||
|
@ -840,7 +840,7 @@ static bool ParseNumber(State *state, int *number_out) {
|
|||
}
|
||||
|
||||
// Floating-point literals are encoded using a fixed-length lowercase
|
||||
// hexadecimal std::string.
|
||||
// hexadecimal string.
|
||||
static bool ParseFloatNumber(State *state) {
|
||||
ComplexityGuard guard(state);
|
||||
if (guard.IsTooComplex()) return false;
|
||||
|
|
|
@ -321,7 +321,7 @@ TEST(Symbolize, SymbolizeWithMultipleMaps) {
|
|||
}
|
||||
}
|
||||
|
||||
// Appends std::string(*args->arg) to args->symbol_buf.
|
||||
// Appends string(*args->arg) to args->symbol_buf.
|
||||
static void DummySymbolDecorator(
|
||||
const absl::debugging_internal::SymbolDecoratorArgs *args) {
|
||||
std::string *message = static_cast<std::string *>(args->arg);
|
||||
|
|
|
@ -165,7 +165,7 @@ inline char ascii_tolower(unsigned char c) {
|
|||
// Converts the characters in `s` to lowercase, changing the contents of `s`.
|
||||
void AsciiStrToLower(std::string* s);
|
||||
|
||||
// Creates a lowercase std::string from a given absl::string_view.
|
||||
// Creates a lowercase string from a given absl::string_view.
|
||||
ABSL_MUST_USE_RESULT inline std::string AsciiStrToLower(absl::string_view s) {
|
||||
std::string result(s);
|
||||
absl::AsciiStrToLower(&result);
|
||||
|
@ -183,7 +183,7 @@ inline char ascii_toupper(unsigned char c) {
|
|||
// Converts the characters in `s` to uppercase, changing the contents of `s`.
|
||||
void AsciiStrToUpper(std::string* s);
|
||||
|
||||
// Creates an uppercase std::string from a given absl::string_view.
|
||||
// Creates an uppercase string from a given absl::string_view.
|
||||
ABSL_MUST_USE_RESULT inline std::string AsciiStrToUpper(absl::string_view s) {
|
||||
std::string result(s);
|
||||
absl::AsciiStrToUpper(&result);
|
||||
|
@ -198,7 +198,7 @@ ABSL_MUST_USE_RESULT inline absl::string_view StripLeadingAsciiWhitespace(
|
|||
return absl::string_view(it, str.end() - it);
|
||||
}
|
||||
|
||||
// Strips in place whitespace from the beginning of the given std::string.
|
||||
// Strips in place whitespace from the beginning of the given string.
|
||||
inline void StripLeadingAsciiWhitespace(std::string* str) {
|
||||
auto it = std::find_if_not(str->begin(), str->end(), absl::ascii_isspace);
|
||||
str->erase(str->begin(), it);
|
||||
|
@ -212,7 +212,7 @@ ABSL_MUST_USE_RESULT inline absl::string_view StripTrailingAsciiWhitespace(
|
|||
return absl::string_view(str.begin(), str.rend() - it);
|
||||
}
|
||||
|
||||
// Strips in place whitespace from the end of the given std::string
|
||||
// Strips in place whitespace from the end of the given string
|
||||
inline void StripTrailingAsciiWhitespace(std::string* str) {
|
||||
auto it = std::find_if_not(str->rbegin(), str->rend(), absl::ascii_isspace);
|
||||
str->erase(str->rend() - it);
|
||||
|
@ -225,7 +225,7 @@ ABSL_MUST_USE_RESULT inline absl::string_view StripAsciiWhitespace(
|
|||
return StripTrailingAsciiWhitespace(StripLeadingAsciiWhitespace(str));
|
||||
}
|
||||
|
||||
// Strips in place whitespace from both ends of the given std::string
|
||||
// Strips in place whitespace from both ends of the given string
|
||||
inline void StripAsciiWhitespace(std::string* str) {
|
||||
StripTrailingAsciiWhitespace(str);
|
||||
StripLeadingAsciiWhitespace(str);
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace absl {
|
|||
// Workalike compatibilty version of std::chars_format from C++17.
|
||||
//
|
||||
// This is an bitfield enumerator which can be passed to absl::from_chars to
|
||||
// configure the std::string-to-float conversion.
|
||||
// configure the string-to-float conversion.
|
||||
enum class chars_format {
|
||||
scientific = 1,
|
||||
fixed = 2,
|
||||
|
@ -30,7 +30,7 @@ enum class chars_format {
|
|||
general = fixed | scientific,
|
||||
};
|
||||
|
||||
// The return result of a std::string-to-number conversion.
|
||||
// The return result of a string-to-number conversion.
|
||||
//
|
||||
// `ec` will be set to `invalid_argument` if a well-formed number was not found
|
||||
// at the start of the input range, `result_out_of_range` if a well-formed
|
||||
|
@ -67,7 +67,7 @@ struct from_chars_result {
|
|||
// If `fmt` is set, it must be one of the enumerator values of the chars_format.
|
||||
// (This is despite the fact that chars_format is a bitmask type.) If set to
|
||||
// `scientific`, a matching number must contain an exponent. If set to `fixed`,
|
||||
// then an exponent will never match. (For example, the std::string "1e5" will be
|
||||
// then an exponent will never match. (For example, the string "1e5" will be
|
||||
// parsed as "1".) If set to `hex`, then a hexadecimal float is parsed in the
|
||||
// format that strtod() accepts, except that a "0x" prefix is NOT matched.
|
||||
// (In particular, in `hex` mode, the input "0xff" results in the largest
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace {
|
|||
|
||||
#if ABSL_COMPILER_DOES_EXACT_ROUNDING
|
||||
|
||||
// Tests that the given std::string is accepted by absl::from_chars, and that it
|
||||
// Tests that the given string is accepted by absl::from_chars, and that it
|
||||
// converts exactly equal to the given number.
|
||||
void TestDoubleParse(absl::string_view str, double expected_number) {
|
||||
SCOPED_TRACE(str);
|
||||
|
@ -250,7 +250,7 @@ TEST(FromChars, NearRoundingCasesExplicit) {
|
|||
EXPECT_EQ(ToFloat("459926601011.e15"), ldexpf(12466336, 65));
|
||||
}
|
||||
|
||||
// Common test logic for converting a std::string which lies exactly halfway between
|
||||
// Common test logic for converting a string which lies exactly halfway between
|
||||
// two target floats.
|
||||
//
|
||||
// mantissa and exponent represent the precise value between two floating point
|
||||
|
@ -655,7 +655,7 @@ int NextStep(int step) {
|
|||
// is correct for in-bounds values, and that overflow and underflow are done
|
||||
// correctly for out-of-bounds values.
|
||||
//
|
||||
// input_generator maps from an integer index to a std::string to test.
|
||||
// input_generator maps from an integer index to a string to test.
|
||||
// expected_generator maps from an integer index to an expected Float value.
|
||||
// from_chars conversion of input_generator(i) should result in
|
||||
// expected_generator(i).
|
||||
|
|
|
@ -89,7 +89,7 @@ inline bool IsSurrogate(char32_t c, absl::string_view src, std::string* error) {
|
|||
//
|
||||
// Unescapes C escape sequences and is the reverse of CEscape().
|
||||
//
|
||||
// If 'source' is valid, stores the unescaped std::string and its size in
|
||||
// If 'source' is valid, stores the unescaped string and its size in
|
||||
// 'dest' and 'dest_len' respectively, and returns true. Otherwise
|
||||
// returns false and optionally stores the error description in
|
||||
// 'error'. Set 'error' to nullptr to disable error reporting.
|
||||
|
@ -294,7 +294,7 @@ bool CUnescapeInternal(absl::string_view source, bool leave_nulls_escaped,
|
|||
// ----------------------------------------------------------------------
|
||||
// CUnescapeInternal()
|
||||
//
|
||||
// Same as above but uses a C++ std::string for output. 'source' and 'dest'
|
||||
// Same as above but uses a C++ string for output. 'source' and 'dest'
|
||||
// may be the same.
|
||||
// ----------------------------------------------------------------------
|
||||
bool CUnescapeInternal(absl::string_view source, bool leave_nulls_escaped,
|
||||
|
@ -684,7 +684,7 @@ bool Base64UnescapeInternal(const char* src_param, size_t szsrc, char* dest,
|
|||
// The arrays below were generated by the following code
|
||||
// #include <sys/time.h>
|
||||
// #include <stdlib.h>
|
||||
// #include <std::string.h>
|
||||
// #include <string.h>
|
||||
// main()
|
||||
// {
|
||||
// static const char Base64[] =
|
||||
|
@ -999,7 +999,7 @@ constexpr char kHexValue[256] = {
|
|||
/* clang-format on */
|
||||
|
||||
// This is a templated function so that T can be either a char*
|
||||
// or a std::string. This works because we use the [] operator to access
|
||||
// or a string. This works because we use the [] operator to access
|
||||
// individual characters at a time.
|
||||
template <typename T>
|
||||
void HexStringToBytesInternal(const char* from, T to, ptrdiff_t num) {
|
||||
|
@ -1009,7 +1009,7 @@ void HexStringToBytesInternal(const char* from, T to, ptrdiff_t num) {
|
|||
}
|
||||
}
|
||||
|
||||
// This is a templated function so that T can be either a char* or a std::string.
|
||||
// This is a templated function so that T can be either a char* or a string.
|
||||
template <typename T>
|
||||
void BytesToHexStringInternal(const unsigned char* src, T dest, ptrdiff_t num) {
|
||||
auto dest_ptr = &dest[0];
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// File: escaping.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header file contains std::string utilities involved in escaping and
|
||||
// This header file contains string utilities involved in escaping and
|
||||
// unescaping strings in various ways.
|
||||
//
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace absl {
|
|||
|
||||
// CUnescape()
|
||||
//
|
||||
// Unescapes a `source` std::string and copies it into `dest`, rewriting C-style
|
||||
// Unescapes a `source` string and copies it into `dest`, rewriting C-style
|
||||
// escape sequences (http://en.cppreference.com/w/cpp/language/escape) into
|
||||
// their proper code point equivalents, returning `true` if successful.
|
||||
//
|
||||
|
@ -78,7 +78,7 @@ inline bool CUnescape(absl::string_view source, std::string* dest) {
|
|||
|
||||
// CEscape()
|
||||
//
|
||||
// Escapes a 'src' std::string using C-style escapes sequences
|
||||
// Escapes a 'src' string using C-style escapes sequences
|
||||
// (http://en.cppreference.com/w/cpp/language/escape), escaping other
|
||||
// non-printable/non-whitespace bytes as octal sequences (e.g. "\377").
|
||||
//
|
||||
|
@ -91,7 +91,7 @@ std::string CEscape(absl::string_view src);
|
|||
|
||||
// CHexEscape()
|
||||
//
|
||||
// Escapes a 'src' std::string using C-style escape sequences, escaping
|
||||
// Escapes a 'src' string using C-style escape sequences, escaping
|
||||
// other non-printable/non-whitespace bytes as hexadecimal sequences (e.g.
|
||||
// "\xFF").
|
||||
//
|
||||
|
@ -104,7 +104,7 @@ std::string CHexEscape(absl::string_view src);
|
|||
|
||||
// Utf8SafeCEscape()
|
||||
//
|
||||
// Escapes a 'src' std::string using C-style escape sequences, escaping bytes as
|
||||
// Escapes a 'src' string using C-style escape sequences, escaping bytes as
|
||||
// octal sequences, and passing through UTF-8 characters without conversion.
|
||||
// I.e., when encountering any bytes with their high bit set, this function
|
||||
// will not escape those values, whether or not they are valid UTF-8.
|
||||
|
@ -112,47 +112,47 @@ std::string Utf8SafeCEscape(absl::string_view src);
|
|||
|
||||
// Utf8SafeCHexEscape()
|
||||
//
|
||||
// Escapes a 'src' std::string using C-style escape sequences, escaping bytes as
|
||||
// Escapes a 'src' string using C-style escape sequences, escaping bytes as
|
||||
// hexadecimal sequences, and passing through UTF-8 characters without
|
||||
// conversion.
|
||||
std::string Utf8SafeCHexEscape(absl::string_view src);
|
||||
|
||||
// Base64Unescape()
|
||||
//
|
||||
// Converts a `src` std::string encoded in Base64 to its binary equivalent, writing
|
||||
// Converts a `src` string encoded in Base64 to its binary equivalent, writing
|
||||
// it to a `dest` buffer, returning `true` on success. If `src` contains invalid
|
||||
// characters, `dest` is cleared and returns `false`.
|
||||
bool Base64Unescape(absl::string_view src, std::string* dest);
|
||||
|
||||
// WebSafeBase64Unescape()
|
||||
//
|
||||
// Converts a `src` std::string encoded in Base64 to its binary equivalent, writing
|
||||
// Converts a `src` string encoded in Base64 to its binary equivalent, writing
|
||||
// it to a `dest` buffer, but using '-' instead of '+', and '_' instead of '/'.
|
||||
// If `src` contains invalid characters, `dest` is cleared and returns `false`.
|
||||
bool WebSafeBase64Unescape(absl::string_view src, std::string* dest);
|
||||
|
||||
// Base64Escape()
|
||||
//
|
||||
// Encodes a `src` std::string into a `dest` buffer using base64 encoding, with
|
||||
// Encodes a `src` string into a `dest` buffer using base64 encoding, with
|
||||
// padding characters. This function conforms with RFC 4648 section 4 (base64).
|
||||
void Base64Escape(absl::string_view src, std::string* dest);
|
||||
|
||||
// WebSafeBase64Escape()
|
||||
//
|
||||
// Encodes a `src` std::string into a `dest` buffer using '-' instead of '+' and
|
||||
// Encodes a `src` string into a `dest` buffer using '-' instead of '+' and
|
||||
// '_' instead of '/', and without padding. This function conforms with RFC 4648
|
||||
// section 5 (base64url).
|
||||
void WebSafeBase64Escape(absl::string_view src, std::string* dest);
|
||||
|
||||
// HexStringToBytes()
|
||||
//
|
||||
// Converts an ASCII hex std::string into bytes, returning binary data of length
|
||||
// Converts an ASCII hex string into bytes, returning binary data of length
|
||||
// `from.size()/2`.
|
||||
std::string HexStringToBytes(absl::string_view from);
|
||||
|
||||
// BytesToHexString()
|
||||
//
|
||||
// Converts binary data into an ASCII text std::string, returning a std::string of size
|
||||
// Converts binary data into an ASCII text string, returning a string of size
|
||||
// `2*from.size()`.
|
||||
std::string BytesToHexString(absl::string_view from);
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ static_assert(std::numeric_limits<int>::digits10 >= kDecimalExponentDigitsMax,
|
|||
|
||||
// To avoid incredibly large inputs causing integer overflow for our exponent,
|
||||
// we impose an arbitrary but very large limit on the number of significant
|
||||
// digits we will accept. The implementation refuses to match a std::string with
|
||||
// digits we will accept. The implementation refuses to match a string with
|
||||
// more consecutive significant mantissa digits than this.
|
||||
constexpr int kDecimalDigitLimit = 50000000;
|
||||
|
||||
|
|
|
@ -29,16 +29,16 @@ using absl::strings_internal::ParseFloat;
|
|||
|
||||
namespace {
|
||||
|
||||
// Check that a given std::string input is parsed to the expected mantissa and
|
||||
// Check that a given string input is parsed to the expected mantissa and
|
||||
// exponent.
|
||||
//
|
||||
// Input std::string `s` must contain a '$' character. It marks the end of the
|
||||
// Input string `s` must contain a '$' character. It marks the end of the
|
||||
// characters that should be consumed by the match. It is stripped from the
|
||||
// input to ParseFloat.
|
||||
//
|
||||
// If input std::string `s` contains '[' and ']' characters, these mark the region
|
||||
// If input string `s` contains '[' and ']' characters, these mark the region
|
||||
// of characters that should be marked as the "subrange". For NaNs, this is
|
||||
// the location of the extended NaN std::string. For numbers, this is the location
|
||||
// the location of the extended NaN string. For numbers, this is the location
|
||||
// of the full, over-large mantissa.
|
||||
template <int base>
|
||||
void ExpectParsedFloat(std::string s, absl::chars_format format_flags,
|
||||
|
@ -92,10 +92,10 @@ void ExpectParsedFloat(std::string s, absl::chars_format format_flags,
|
|||
EXPECT_EQ(characters_matched, expected_characters_matched);
|
||||
}
|
||||
|
||||
// Check that a given std::string input is parsed to the expected mantissa and
|
||||
// Check that a given string input is parsed to the expected mantissa and
|
||||
// exponent.
|
||||
//
|
||||
// Input std::string `s` must contain a '$' character. It marks the end of the
|
||||
// Input string `s` must contain a '$' character. It marks the end of the
|
||||
// characters that were consumed by the match.
|
||||
template <int base>
|
||||
void ExpectNumber(std::string s, absl::chars_format format_flags,
|
||||
|
@ -106,7 +106,7 @@ void ExpectNumber(std::string s, absl::chars_format format_flags,
|
|||
expected_literal_exponent);
|
||||
}
|
||||
|
||||
// Check that a given std::string input is parsed to the given special value.
|
||||
// Check that a given string input is parsed to the given special value.
|
||||
//
|
||||
// This tests against both number bases, since infinities and NaNs have
|
||||
// identical representations in both modes.
|
||||
|
@ -116,7 +116,7 @@ void ExpectSpecial(const std::string& s, absl::chars_format format_flags,
|
|||
ExpectParsedFloat<16>(s, format_flags, type, 0, 0);
|
||||
}
|
||||
|
||||
// Check that a given input std::string is not matched by Float.
|
||||
// Check that a given input string is not matched by Float.
|
||||
template <int base>
|
||||
void ExpectFailedParse(absl::string_view s, absl::chars_format format_flags) {
|
||||
ParsedFloat parsed =
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
|
||||
// These routines provide mem versions of standard C std::string routines,
|
||||
// These routines provide mem versions of standard C string routines,
|
||||
// such as strpbrk. They function exactly the same as the str versions,
|
||||
// so if you wonder what they are, replace the word "mem" by
|
||||
// "str" and check out the man page. I could return void*, as the
|
||||
|
@ -22,14 +22,14 @@
|
|||
// since this is by far the most common way these functions are called.
|
||||
//
|
||||
// The difference between the mem and str versions is the mem version
|
||||
// takes a pointer and a length, rather than a '\0'-terminated std::string.
|
||||
// takes a pointer and a length, rather than a '\0'-terminated string.
|
||||
// The memcase* routines defined here assume the locale is "C"
|
||||
// (they use absl::ascii_tolower instead of tolower).
|
||||
//
|
||||
// These routines are based on the BSD library.
|
||||
//
|
||||
// Here's a list of routines from std::string.h, and their mem analogues.
|
||||
// Functions in lowercase are defined in std::string.h; those in UPPERCASE
|
||||
// Here's a list of routines from string.h, and their mem analogues.
|
||||
// Functions in lowercase are defined in string.h; those in UPPERCASE
|
||||
// are defined here:
|
||||
//
|
||||
// strlen --
|
||||
|
|
|
@ -25,18 +25,18 @@
|
|||
namespace absl {
|
||||
namespace strings_internal {
|
||||
|
||||
// The same as std::ostringstream but appends to a user-specified std::string,
|
||||
// The same as std::ostringstream but appends to a user-specified string,
|
||||
// and is faster. It is ~70% faster to create, ~50% faster to write to, and
|
||||
// completely free to extract the result std::string.
|
||||
// completely free to extract the result string.
|
||||
//
|
||||
// std::string s;
|
||||
// string s;
|
||||
// OStringStream strm(&s);
|
||||
// strm << 42 << ' ' << 3.14; // appends to `s`
|
||||
//
|
||||
// The stream object doesn't have to be named. Starting from C++11 operator<<
|
||||
// works with rvalues of std::ostream.
|
||||
//
|
||||
// std::string s;
|
||||
// string s;
|
||||
// OStringStream(&s) << 42 << ' ' << 3.14; // appends to `s`
|
||||
//
|
||||
// OStringStream is faster to create than std::ostringstream but it's still
|
||||
|
@ -45,14 +45,14 @@ namespace strings_internal {
|
|||
//
|
||||
// Creates unnecessary instances of OStringStream: slow.
|
||||
//
|
||||
// std::string s;
|
||||
// string s;
|
||||
// OStringStream(&s) << 42;
|
||||
// OStringStream(&s) << ' ';
|
||||
// OStringStream(&s) << 3.14;
|
||||
//
|
||||
// Creates a single instance of OStringStream and reuses it: fast.
|
||||
//
|
||||
// std::string s;
|
||||
// string s;
|
||||
// OStringStream strm(&s);
|
||||
// strm << 42;
|
||||
// strm << ' ';
|
||||
|
|
|
@ -44,8 +44,8 @@ void ResizeUninit(string_type* s, size_t new_size, std::false_type) {
|
|||
s->resize(new_size);
|
||||
}
|
||||
|
||||
// Returns true if the std::string implementation supports a resize where
|
||||
// the new characters added to the std::string are left untouched.
|
||||
// Returns true if the string implementation supports a resize where
|
||||
// the new characters added to the string are left untouched.
|
||||
//
|
||||
// (A better name might be "STLStringSupportsUninitializedResize", alluding to
|
||||
// the previous function.)
|
||||
|
@ -57,7 +57,7 @@ inline constexpr bool STLStringSupportsNontrashingResize(string_type*) {
|
|||
// Like str->resize(new_size), except any new characters added to "*str" as a
|
||||
// result of resizing may be left uninitialized, rather than being filled with
|
||||
// '0' bytes. Typically used when code is then going to overwrite the backing
|
||||
// store of the std::string with known data. Uses a Google extension to std::string.
|
||||
// store of the string with known data. Uses a Google extension to ::string.
|
||||
template <typename string_type, typename = void>
|
||||
inline void STLStringResizeUninitialized(string_type* s, size_t new_size) {
|
||||
ResizeUninit(s, new_size, HasResizeUninitialized<string_type>());
|
||||
|
|
|
@ -168,7 +168,7 @@ int FprintF(std::FILE* output, const UntypedFormatSpecImpl& format,
|
|||
int SnprintF(char* output, size_t size, const UntypedFormatSpecImpl& format,
|
||||
absl::Span<const FormatArgImpl> args);
|
||||
|
||||
// Returned by Streamed(v). Converts via '%s' to the std::string created
|
||||
// Returned by Streamed(v). Converts via '%s' to the string created
|
||||
// by std::ostream << v.
|
||||
template <typename T>
|
||||
class StreamedWrapper {
|
||||
|
|
|
@ -57,7 +57,7 @@ class FormatRawSinkImpl {
|
|||
void (*write_)(void*, string_view);
|
||||
};
|
||||
|
||||
// An abstraction to which conversions write their std::string data.
|
||||
// An abstraction to which conversions write their string data.
|
||||
class FormatSinkImpl {
|
||||
public:
|
||||
explicit FormatSinkImpl(FormatRawSinkImpl raw) : raw_(raw) {}
|
||||
|
|
|
@ -75,14 +75,14 @@ struct UnboundConversion {
|
|||
bool ConsumeUnboundConversion(string_view* src, UnboundConversion* conv,
|
||||
int* next_arg);
|
||||
|
||||
// Parse the format std::string provided in 'src' and pass the identified items into
|
||||
// Parse the format string provided in 'src' and pass the identified items into
|
||||
// 'consumer'.
|
||||
// Text runs will be passed by calling
|
||||
// Consumer::Append(string_view);
|
||||
// ConversionItems will be passed by calling
|
||||
// Consumer::ConvertOne(UnboundConversion, string_view);
|
||||
// In the case of ConvertOne, the string_view that is passed is the
|
||||
// portion of the format std::string corresponding to the conversion, not including
|
||||
// portion of the format string corresponding to the conversion, not including
|
||||
// the leading %. On success, it returns true. On failure, it stops and returns
|
||||
// false.
|
||||
template <typename Consumer>
|
||||
|
@ -237,7 +237,7 @@ class ParsedFormatBase {
|
|||
// This class also supports runtime format checking with the ::New() and
|
||||
// ::NewAllowIgnored() factory functions.
|
||||
// This is the only API that allows the user to pass a runtime specified format
|
||||
// std::string. These factory functions will return NULL if the format does not match
|
||||
// string. These factory functions will return NULL if the format does not match
|
||||
// the conversions requested by the user.
|
||||
template <str_format_internal::Conv... C>
|
||||
class ExtendedParsedFormat : public str_format_internal::ParsedFormatBase {
|
||||
|
|
|
@ -189,7 +189,7 @@ struct DefaultFormatter<std::unique_ptr<ValueType>>
|
|||
//
|
||||
|
||||
// The main joining algorithm. This simply joins the elements in the given
|
||||
// iterator range, each separated by the given separator, into an output std::string,
|
||||
// iterator range, each separated by the given separator, into an output string,
|
||||
// and formats each element using the provided Formatter object.
|
||||
template <typename Iterator, typename Formatter>
|
||||
std::string JoinAlgorithm(Iterator start, Iterator end, absl::string_view s,
|
||||
|
@ -205,20 +205,20 @@ std::string JoinAlgorithm(Iterator start, Iterator end, absl::string_view s,
|
|||
}
|
||||
|
||||
// A joining algorithm that's optimized for a forward iterator range of
|
||||
// std::string-like objects that do not need any additional formatting. This is to
|
||||
// optimize the common case of joining, say, a std::vector<std::string> or a
|
||||
// string-like objects that do not need any additional formatting. This is to
|
||||
// optimize the common case of joining, say, a std::vector<string> or a
|
||||
// std::vector<absl::string_view>.
|
||||
//
|
||||
// This is an overload of the previous JoinAlgorithm() function. Here the
|
||||
// Formatter argument is of type NoFormatter. Since NoFormatter is an internal
|
||||
// type, this overload is only invoked when strings::Join() is called with a
|
||||
// range of std::string-like objects (e.g., std::string, absl::string_view), and an
|
||||
// range of string-like objects (e.g., string, absl::string_view), and an
|
||||
// explicit Formatter argument was NOT specified.
|
||||
//
|
||||
// The optimization is that the needed space will be reserved in the output
|
||||
// std::string to avoid the need to resize while appending. To do this, the iterator
|
||||
// string to avoid the need to resize while appending. To do this, the iterator
|
||||
// range will be traversed twice: once to calculate the total needed size, and
|
||||
// then again to copy the elements and delimiters to the output std::string.
|
||||
// then again to copy the elements and delimiters to the output string.
|
||||
template <typename Iterator,
|
||||
typename = typename std::enable_if<std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace strings_internal {
|
|||
|
||||
// This class is implicitly constructible from everything that absl::string_view
|
||||
// is implicitly constructible from. If it's constructed from a temporary
|
||||
// std::string, the data is moved into a data member so its lifetime matches that of
|
||||
// string, the data is moved into a data member so its lifetime matches that of
|
||||
// the ConvertibleToStringView instance.
|
||||
class ConvertibleToStringView {
|
||||
public:
|
||||
|
@ -102,7 +102,7 @@ ConvertibleToStringView(std::string&& s) // NOLINT(runtime/explicit)
|
|||
absl::string_view value_;
|
||||
};
|
||||
|
||||
// An iterator that enumerates the parts of a std::string from a Splitter. The text
|
||||
// An iterator that enumerates the parts of a string from a Splitter. The text
|
||||
// to be split, the Delimiter, and the Predicate are all taken from the given
|
||||
// Splitter object. Iterators may only be compared if they refer to the same
|
||||
// Splitter instance.
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// File: match.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This file contains simple utilities for performing std::string matching checks.
|
||||
// This file contains simple utilities for performing string matching checks.
|
||||
// All of these function parameters are specified as `absl::string_view`,
|
||||
// meaning that these functions can accept `std::string`, `absl::string_view` or
|
||||
// nul-terminated C-style strings.
|
||||
|
@ -41,14 +41,14 @@ namespace absl {
|
|||
|
||||
// StrContains()
|
||||
//
|
||||
// Returns whether a given std::string `haystack` contains the substring `needle`.
|
||||
// Returns whether a given string `haystack` contains the substring `needle`.
|
||||
inline bool StrContains(absl::string_view haystack, absl::string_view needle) {
|
||||
return haystack.find(needle, 0) != haystack.npos;
|
||||
}
|
||||
|
||||
// StartsWith()
|
||||
//
|
||||
// Returns whether a given std::string `text` begins with `prefix`.
|
||||
// Returns whether a given string `text` begins with `prefix`.
|
||||
inline bool StartsWith(absl::string_view text, absl::string_view prefix) {
|
||||
return prefix.empty() ||
|
||||
(text.size() >= prefix.size() &&
|
||||
|
@ -57,7 +57,7 @@ inline bool StartsWith(absl::string_view text, absl::string_view prefix) {
|
|||
|
||||
// EndsWith()
|
||||
//
|
||||
// Returns whether a given std::string `text` ends with `suffix`.
|
||||
// Returns whether a given string `text` ends with `suffix`.
|
||||
inline bool EndsWith(absl::string_view text, absl::string_view suffix) {
|
||||
return suffix.empty() ||
|
||||
(text.size() >= suffix.size() &&
|
||||
|
@ -68,13 +68,13 @@ inline bool EndsWith(absl::string_view text, absl::string_view suffix) {
|
|||
|
||||
// StartsWithIgnoreCase()
|
||||
//
|
||||
// Returns whether a given std::string `text` starts with `starts_with`, ignoring
|
||||
// Returns whether a given string `text` starts with `starts_with`, ignoring
|
||||
// case in the comparison.
|
||||
bool StartsWithIgnoreCase(absl::string_view text, absl::string_view prefix);
|
||||
|
||||
// EndsWithIgnoreCase()
|
||||
//
|
||||
// Returns whether a given std::string `text` ends with `ends_with`, ignoring case
|
||||
// Returns whether a given string `text` ends with `ends_with`, ignoring case
|
||||
// in the comparison.
|
||||
bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file contains std::string processing functions related to
|
||||
// This file contains string processing functions related to
|
||||
// numeric values.
|
||||
|
||||
#include "absl/strings/numbers.h"
|
||||
|
@ -161,8 +161,8 @@ bool SimpleAtob(absl::string_view str, bool* value) {
|
|||
// their output to the beginning of the buffer. The caller is responsible
|
||||
// for ensuring that the buffer has enough space to hold the output.
|
||||
//
|
||||
// Returns a pointer to the end of the std::string (i.e. the null character
|
||||
// terminating the std::string).
|
||||
// Returns a pointer to the end of the string (i.e. the null character
|
||||
// terminating the string).
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -41,8 +41,8 @@ namespace absl {
|
|||
|
||||
// SimpleAtoi()
|
||||
//
|
||||
// Converts the given std::string into an integer value, returning `true` if
|
||||
// successful. The std::string must reflect a base-10 integer (optionally followed or
|
||||
// Converts the given string into an integer value, returning `true` if
|
||||
// successful. The string must reflect a base-10 integer (optionally followed or
|
||||
// preceded by ASCII whitespace) whose value falls within the range of the
|
||||
// integer type.
|
||||
template <typename int_type>
|
||||
|
@ -50,23 +50,23 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out);
|
|||
|
||||
// SimpleAtof()
|
||||
//
|
||||
// Converts the given std::string (optionally followed or preceded by ASCII
|
||||
// Converts the given string (optionally followed or preceded by ASCII
|
||||
// whitespace) into a float, which may be rounded on overflow or underflow.
|
||||
// See http://en.cppreference.com/w/c/std::string/byte/strtof for details about the
|
||||
// See http://en.cppreference.com/w/c/string/byte/strtof for details about the
|
||||
// allowed formats for `str`.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str, float* value);
|
||||
|
||||
// SimpleAtod()
|
||||
//
|
||||
// Converts the given std::string (optionally followed or preceded by ASCII
|
||||
// Converts the given string (optionally followed or preceded by ASCII
|
||||
// whitespace) into a double, which may be rounded on overflow or underflow.
|
||||
// See http://en.cppreference.com/w/c/std::string/byte/strtof for details about the
|
||||
// See http://en.cppreference.com/w/c/string/byte/strtof for details about the
|
||||
// allowed formats for `str`.
|
||||
ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str, double* value);
|
||||
|
||||
// SimpleAtob()
|
||||
//
|
||||
// Converts the given std::string into a boolean, returning `true` if successful.
|
||||
// Converts the given string into a boolean, returning `true` if successful.
|
||||
// The following case-insensitive strings are interpreted as boolean `true`:
|
||||
// "true", "t", "yes", "y", "1". The following case-insensitive strings
|
||||
// are interpreted as boolean `false`: "false", "f", "no", "n", "0".
|
||||
|
@ -169,9 +169,9 @@ ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s, int_type* out,
|
|||
|
||||
// SimpleAtoi()
|
||||
//
|
||||
// Converts a std::string to an integer, using `safe_strto?()` functions for actual
|
||||
// Converts a string to an integer, using `safe_strto?()` functions for actual
|
||||
// parsing, returning `true` if successful. The `safe_strto?()` functions apply
|
||||
// strict checking; the std::string must be a base-10 integer, optionally followed or
|
||||
// strict checking; the string must be a base-10 integer, optionally followed or
|
||||
// preceded by ASCII whitespace, with a value in the range of the corresponding
|
||||
// integer type.
|
||||
template <typename int_type>
|
||||
|
|
|
@ -158,7 +158,7 @@ BENCHMARK(BM_safe_strtou64_string)
|
|||
->ArgPair(16, 10)
|
||||
->ArgPair(16, 16);
|
||||
|
||||
// Returns a vector of `num_strings` strings. Each std::string represents a
|
||||
// Returns a vector of `num_strings` strings. Each string represents a
|
||||
// floating point number with `num_digits` digits before the decimal point and
|
||||
// another `num_digits` digits after.
|
||||
std::vector<std::string> MakeFloatStrings(int num_strings, int num_digits) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file tests std::string processing functions related to numeric values.
|
||||
// This file tests string processing functions related to numeric values.
|
||||
|
||||
#include "absl/strings/numbers.h"
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ AlphaNum::AlphaNum(Dec dec) {
|
|||
// ----------------------------------------------------------------------
|
||||
// StrCat()
|
||||
// This merges the given strings or integers, with no delimiter. This
|
||||
// is designed to be the fastest possible way to construct a std::string out
|
||||
// is designed to be the fastest possible way to construct a string out
|
||||
// of a mix of raw C strings, StringPieces, strings, and integer values.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
|
@ -154,10 +154,10 @@ std::string CatPieces(std::initializer_list<absl::string_view> pieces) {
|
|||
}
|
||||
|
||||
// It's possible to call StrAppend with an absl::string_view that is itself a
|
||||
// fragment of the std::string we're appending to. However the results of this are
|
||||
// fragment of the string we're appending to. However the results of this are
|
||||
// random. Therefore, check for this in debug mode. Use unsigned math so we
|
||||
// only have to do one comparison. Note, there's an exception case: appending an
|
||||
// empty std::string is always allowed.
|
||||
// empty string is always allowed.
|
||||
#define ASSERT_NO_OVERLAP(dest, src) \
|
||||
assert(((src).size() == 0) || \
|
||||
(uintptr_t((src).data() - (dest).data()) > uintptr_t((dest).size())))
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// designed to be used as a parameter type that efficiently manages conversion
|
||||
// to strings and avoids copies in the above operations.
|
||||
//
|
||||
// Any routine accepting either a std::string or a number may accept `AlphaNum`.
|
||||
// Any routine accepting either a string or a number may accept `AlphaNum`.
|
||||
// The basic idea is that by accepting a `const AlphaNum &` as an argument
|
||||
// to your function, your callers will automagically convert bools, integers,
|
||||
// and floating point values to strings for you.
|
||||
|
@ -65,7 +65,7 @@
|
|||
namespace absl {
|
||||
|
||||
namespace strings_internal {
|
||||
// AlphaNumBuffer allows a way to pass a std::string to StrCat without having to do
|
||||
// AlphaNumBuffer allows a way to pass a string to StrCat without having to do
|
||||
// memory allocation. It is simply a pair of a fixed-size character array, and
|
||||
// a size. Please don't use outside of absl, yet.
|
||||
template <size_t max_size>
|
||||
|
@ -119,8 +119,8 @@ enum PadSpec : uint8_t {
|
|||
// Hex
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// `Hex` stores a set of hexadecimal std::string conversion parameters for use
|
||||
// within `AlphaNum` std::string conversions.
|
||||
// `Hex` stores a set of hexadecimal string conversion parameters for use
|
||||
// within `AlphaNum` string conversions.
|
||||
struct Hex {
|
||||
uint64_t value;
|
||||
uint8_t width;
|
||||
|
@ -168,8 +168,8 @@ 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
|
||||
// `Dec` stores a set of decimal string conversion parameters for use
|
||||
// within `AlphaNum` string conversions. Dec is slower than the default
|
||||
// integer conversion, so use it only if you need padding.
|
||||
struct Dec {
|
||||
uint64_t value;
|
||||
|
@ -271,7 +271,7 @@ class AlphaNum {
|
|||
//
|
||||
// Merges given strings or numbers, using no delimiter(s).
|
||||
//
|
||||
// `StrCat()` is designed to be the fastest possible way to construct a std::string
|
||||
// `StrCat()` is designed to be the fastest possible way to construct a string
|
||||
// out of a mix of raw C strings, string_views, strings, bool values,
|
||||
// and numeric values.
|
||||
//
|
||||
|
@ -279,7 +279,7 @@ class AlphaNum {
|
|||
// works poorly on strings built up out of fragments.
|
||||
//
|
||||
// For clarity and performance, don't use `StrCat()` when appending to a
|
||||
// std::string. Use `StrAppend()` instead. In particular, avoid using any of these
|
||||
// string. Use `StrAppend()` instead. In particular, avoid using any of these
|
||||
// (anti-)patterns:
|
||||
//
|
||||
// str.append(StrCat(...))
|
||||
|
@ -328,26 +328,26 @@ ABSL_MUST_USE_RESULT inline std::string StrCat(const AlphaNum& a, const AlphaNum
|
|||
// StrAppend()
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Appends a std::string or set of strings to an existing std::string, in a similar
|
||||
// Appends a string or set of strings to an existing string, in a similar
|
||||
// fashion to `StrCat()`.
|
||||
//
|
||||
// WARNING: `StrAppend(&str, a, b, c, ...)` requires that none of the
|
||||
// a, b, c, parameters be a reference into str. For speed, `StrAppend()` does
|
||||
// not try to check each of its input arguments to be sure that they are not
|
||||
// a subset of the std::string being appended to. That is, while this will work:
|
||||
// a subset of the string being appended to. That is, while this will work:
|
||||
//
|
||||
// std::string s = "foo";
|
||||
// string s = "foo";
|
||||
// s += s;
|
||||
//
|
||||
// This output is undefined:
|
||||
//
|
||||
// std::string s = "foo";
|
||||
// string s = "foo";
|
||||
// StrAppend(&s, s);
|
||||
//
|
||||
// This output is undefined as well, since `absl::string_view` does not own its
|
||||
// data:
|
||||
//
|
||||
// std::string s = "foobar";
|
||||
// string s = "foobar";
|
||||
// absl::string_view p = s;
|
||||
// StrAppend(&s, p);
|
||||
|
||||
|
|
|
@ -18,20 +18,20 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// The `str_format` library is a typesafe replacement for the family of
|
||||
// `printf()` std::string formatting routines within the `<cstdio>` standard library
|
||||
// `printf()` string formatting routines within the `<cstdio>` standard library
|
||||
// header. Like the `printf` family, the `str_format` uses a "format string" to
|
||||
// perform argument substitutions based on types.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string s = absl::StrFormat("%s %s You have $%d!", "Hello", name, dollars);
|
||||
// string s = absl::StrFormat("%s %s You have $%d!", "Hello", name, dollars);
|
||||
//
|
||||
// The library consists of the following basic utilities:
|
||||
//
|
||||
// * `absl::StrFormat()`, a type-safe replacement for `std::sprintf()`, to
|
||||
// write a format std::string to a `string` value.
|
||||
// * `absl::StrAppendFormat()` to append a format std::string to a `string`
|
||||
// * `absl::StreamFormat()` to more efficiently write a format std::string to a
|
||||
// write a format string to a `string` value.
|
||||
// * `absl::StrAppendFormat()` to append a format string to a `string`
|
||||
// * `absl::StreamFormat()` to more efficiently write a format string to a
|
||||
// stream, such as`std::cout`.
|
||||
// * `absl::PrintF()`, `absl::FPrintF()` and `absl::SNPrintF()` as
|
||||
// replacements for `std::printf()`, `std::fprintf()` and `std::snprintf()`.
|
||||
|
@ -39,15 +39,15 @@
|
|||
// Note: a version of `std::sprintf()` is not supported as it is
|
||||
// generally unsafe due to buffer overflows.
|
||||
//
|
||||
// Additionally, you can provide a format std::string (and its associated arguments)
|
||||
// Additionally, you can provide a format string (and its associated arguments)
|
||||
// using one of the following abstractions:
|
||||
//
|
||||
// * A `FormatSpec` class template fully encapsulates a format std::string and its
|
||||
// * A `FormatSpec` class template fully encapsulates a format string and its
|
||||
// type arguments and is usually provided to `str_format` functions as a
|
||||
// variadic argument of type `FormatSpec<Arg...>`. The `FormatSpec<Args...>`
|
||||
// template is evaluated at compile-time, providing type safety.
|
||||
// * A `ParsedFormat` instance, which encapsulates a specific, pre-compiled
|
||||
// format std::string for a specific set of type(s), and which can be passed
|
||||
// format string for a specific set of type(s), and which can be passed
|
||||
// between API boundaries. (The `FormatSpec` type should not be used
|
||||
// directly.)
|
||||
//
|
||||
|
@ -60,7 +60,7 @@
|
|||
//
|
||||
// * A `FormatUntyped()` function that is similar to `Format()` except it is
|
||||
// loosely typed. `FormatUntyped()` is not a template and does not perform
|
||||
// any compile-time checking of the format std::string; instead, it returns a
|
||||
// any compile-time checking of the format string; instead, it returns a
|
||||
// boolean from a runtime check.
|
||||
//
|
||||
// In addition, the `str_format` library provides extension points for
|
||||
|
@ -89,7 +89,7 @@ namespace absl {
|
|||
// Example:
|
||||
//
|
||||
// absl::UntypedFormatSpec format("%d");
|
||||
// std::string out;
|
||||
// string out;
|
||||
// CHECK(absl::FormatUntyped(&out, format, {absl::FormatArg(1)}));
|
||||
class UntypedFormatSpec {
|
||||
public:
|
||||
|
@ -135,7 +135,7 @@ str_format_internal::StreamedWrapper<T> FormatStreamed(const T& v) {
|
|||
// Example:
|
||||
//
|
||||
// int n = 0;
|
||||
// std::string s = absl::StrFormat("%s%d%n", "hello", 123,
|
||||
// string s = absl::StrFormat("%s%d%n", "hello", 123,
|
||||
// absl::FormatCountCapture(&n));
|
||||
// EXPECT_EQ(8, n);
|
||||
class FormatCountCapture {
|
||||
|
@ -155,10 +155,10 @@ class FormatCountCapture {
|
|||
|
||||
// FormatSpec
|
||||
//
|
||||
// The `FormatSpec` type defines the makeup of a format std::string within the
|
||||
// The `FormatSpec` type defines the makeup of a format string within the
|
||||
// `str_format` library. You should not need to use or manipulate this type
|
||||
// directly. A `FormatSpec` is a variadic class template that is evaluated at
|
||||
// compile-time, according to the format std::string and arguments that are passed
|
||||
// compile-time, according to the format string and arguments that are passed
|
||||
// to it.
|
||||
//
|
||||
// For a `FormatSpec` to be valid at compile-time, it must be provided as
|
||||
|
@ -166,12 +166,12 @@ class FormatCountCapture {
|
|||
//
|
||||
// * A `constexpr` literal or `absl::string_view`, which is how it most often
|
||||
// used.
|
||||
// * A `ParsedFormat` instantiation, which ensures the format std::string is
|
||||
// * A `ParsedFormat` instantiation, which ensures the format string is
|
||||
// valid before use. (See below.)
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // Provided as a std::string literal.
|
||||
// // Provided as a string literal.
|
||||
// absl::StrFormat("Welcome to %s, Number %d!", "The Village", 6);
|
||||
//
|
||||
// // Provided as a constexpr absl::string_view.
|
||||
|
@ -183,7 +183,7 @@ class FormatCountCapture {
|
|||
// absl::ParsedFormat<'s', 'd'> formatString("Welcome to %s, Number %d!");
|
||||
// absl::StrFormat(formatString, "TheVillage", 6);
|
||||
//
|
||||
// A format std::string generally follows the POSIX syntax as used within the POSIX
|
||||
// A format string generally follows the POSIX syntax as used within the POSIX
|
||||
// `printf` specification.
|
||||
//
|
||||
// (See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html.)
|
||||
|
@ -223,7 +223,7 @@ class FormatCountCapture {
|
|||
// "%p", *int -> "0x7ffdeb6ad2a4"
|
||||
//
|
||||
// int n = 0;
|
||||
// std::string s = absl::StrFormat(
|
||||
// string s = absl::StrFormat(
|
||||
// "%s%d%n", "hello", 123, absl::FormatCountCapture(&n));
|
||||
// EXPECT_EQ(8, n);
|
||||
//
|
||||
|
@ -236,7 +236,7 @@ class FormatCountCapture {
|
|||
//
|
||||
// However, in the `str_format` library, a format conversion specifies a broader
|
||||
// C++ conceptual category instead of an exact type. For example, `%s` binds to
|
||||
// any std::string-like argument, so `std::string`, `absl::string_view`, and
|
||||
// any string-like argument, so `std::string`, `absl::string_view`, and
|
||||
// `const char*` are all accepted. Likewise, `%d` accepts any integer-like
|
||||
// argument, etc.
|
||||
|
||||
|
@ -248,7 +248,7 @@ using FormatSpec =
|
|||
//
|
||||
// A `ParsedFormat` is a class template representing a preparsed `FormatSpec`,
|
||||
// with template arguments specifying the conversion characters used within the
|
||||
// format std::string. Such characters must be valid format type specifiers, and
|
||||
// format string. Such characters must be valid format type specifiers, and
|
||||
// these type specifiers are checked at compile-time.
|
||||
//
|
||||
// Instances of `ParsedFormat` can be created, copied, and reused to speed up
|
||||
|
@ -275,26 +275,26 @@ using ParsedFormat = str_format_internal::ExtendedParsedFormat<
|
|||
|
||||
// StrFormat()
|
||||
//
|
||||
// Returns a `string` given a `printf()`-style format std::string and zero or more
|
||||
// Returns a `string` given a `printf()`-style format string and zero or more
|
||||
// additional arguments. Use it as you would `sprintf()`. `StrFormat()` is the
|
||||
// primary formatting function within the `str_format` library, and should be
|
||||
// used in most cases where you need type-safe conversion of types into
|
||||
// formatted strings.
|
||||
//
|
||||
// The format std::string generally consists of ordinary character data along with
|
||||
// The format string generally consists of ordinary character data along with
|
||||
// one or more format conversion specifiers (denoted by the `%` character).
|
||||
// Ordinary character data is returned unchanged into the result std::string, while
|
||||
// Ordinary character data is returned unchanged into the result string, while
|
||||
// each conversion specification performs a type substitution from
|
||||
// `StrFormat()`'s other arguments. See the comments for `FormatSpec` for full
|
||||
// information on the makeup of this format std::string.
|
||||
// information on the makeup of this format string.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string s = absl::StrFormat(
|
||||
// string s = absl::StrFormat(
|
||||
// "Welcome to %s, Number %d!", "The Village", 6);
|
||||
// EXPECT_EQ("Welcome to The Village, Number 6!", s);
|
||||
//
|
||||
// Returns an empty std::string in case of error.
|
||||
// Returns an empty string in case of error.
|
||||
template <typename... Args>
|
||||
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec<Args...>& format,
|
||||
const Args&... args) {
|
||||
|
@ -305,13 +305,13 @@ ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec<Args...>& format,
|
|||
|
||||
// StrAppendFormat()
|
||||
//
|
||||
// Appends to a `dst` std::string given a format std::string, and zero or more additional
|
||||
// Appends to a `dst` string given a format string, and zero or more additional
|
||||
// arguments, returning `*dst` as a convenience for chaining purposes. Appends
|
||||
// nothing in case of error (but possibly alters its capacity).
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string orig("For example PI is approximately ");
|
||||
// string orig("For example PI is approximately ");
|
||||
// std::cout << StrAppendFormat(&orig, "%12.6f", 3.14);
|
||||
template <typename... Args>
|
||||
std::string& StrAppendFormat(std::string* dst, const FormatSpec<Args...>& format,
|
||||
|
@ -323,7 +323,7 @@ std::string& StrAppendFormat(std::string* dst, const FormatSpec<Args...>& format
|
|||
|
||||
// StreamFormat()
|
||||
//
|
||||
// Writes to an output stream given a format std::string and zero or more arguments,
|
||||
// Writes to an output stream given a format string and zero or more arguments,
|
||||
// generally in a manner that is more efficient than streaming the result of
|
||||
// `absl:: StrFormat()`. The returned object must be streamed before the full
|
||||
// expression ends.
|
||||
|
@ -341,7 +341,7 @@ ABSL_MUST_USE_RESULT str_format_internal::Streamable StreamFormat(
|
|||
|
||||
// PrintF()
|
||||
//
|
||||
// Writes to stdout given a format std::string and zero or more arguments. This
|
||||
// Writes to stdout given a format string and zero or more arguments. This
|
||||
// function is functionally equivalent to `std::printf()` (and type-safe);
|
||||
// prefer `absl::PrintF()` over `std::printf()`.
|
||||
//
|
||||
|
@ -361,7 +361,7 @@ int PrintF(const FormatSpec<Args...>& format, const Args&... args) {
|
|||
|
||||
// FPrintF()
|
||||
//
|
||||
// Writes to a file given a format std::string and zero or more arguments. This
|
||||
// Writes to a file given a format string and zero or more arguments. This
|
||||
// function is functionally equivalent to `std::fprintf()` (and type-safe);
|
||||
// prefer `absl::FPrintF()` over `std::fprintf()`.
|
||||
//
|
||||
|
@ -382,7 +382,7 @@ int FPrintF(std::FILE* output, const FormatSpec<Args...>& format,
|
|||
|
||||
// SNPrintF()
|
||||
//
|
||||
// Writes to a sized buffer given a format std::string and zero or more arguments.
|
||||
// Writes to a sized buffer given a format string and zero or more arguments.
|
||||
// This function is functionally equivalent to `std::snprintf()` (and
|
||||
// type-safe); prefer `absl::SNPrintF()` over `std::snprintf()`.
|
||||
//
|
||||
|
@ -430,14 +430,14 @@ class FormatRawSink {
|
|||
|
||||
// Format()
|
||||
//
|
||||
// Writes a formatted std::string to an arbitrary sink object (implementing the
|
||||
// `absl::FormatRawSink` interface), using a format std::string and zero or more
|
||||
// Writes a formatted string to an arbitrary sink object (implementing the
|
||||
// `absl::FormatRawSink` interface), using a format string and zero or more
|
||||
// additional arguments.
|
||||
//
|
||||
// By default, `string` and `std::ostream` are supported as destination objects.
|
||||
//
|
||||
// `absl::Format()` is a generic version of `absl::StrFormat(), for custom
|
||||
// sinks. The format std::string, like format strings for `StrFormat()`, is checked
|
||||
// sinks. The format string, like format strings for `StrFormat()`, is checked
|
||||
// at compile-time.
|
||||
//
|
||||
// On failure, this function returns `false` and the state of the sink is
|
||||
|
@ -463,13 +463,13 @@ using FormatArg = str_format_internal::FormatArgImpl;
|
|||
|
||||
// FormatUntyped()
|
||||
//
|
||||
// Writes a formatted std::string to an arbitrary sink object (implementing the
|
||||
// Writes a formatted string to an arbitrary sink object (implementing the
|
||||
// `absl::FormatRawSink` interface), using an `UntypedFormatSpec` and zero or
|
||||
// more additional arguments.
|
||||
//
|
||||
// This function acts as the most generic formatting function in the
|
||||
// `str_format` library. The caller provides a raw sink, an unchecked format
|
||||
// std::string, and (usually) a runtime specified list of arguments; no compile-time
|
||||
// string, and (usually) a runtime specified list of arguments; no compile-time
|
||||
// checking of formatting is performed within this function. As a result, a
|
||||
// caller should check the return value to verify that no error occurred.
|
||||
// On failure, this function returns `false` and the state of the sink is
|
||||
|
@ -483,9 +483,9 @@ using FormatArg = str_format_internal::FormatArgImpl;
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// std::optional<std::string> FormatDynamic(const std::string& in_format,
|
||||
// const vector<std::string>& in_args) {
|
||||
// std::string out;
|
||||
// std::optional<string> FormatDynamic(const string& in_format,
|
||||
// const vector<string>& in_args) {
|
||||
// string out;
|
||||
// std::vector<absl::FormatArg> args;
|
||||
// for (const auto& v : in_args) {
|
||||
// // It is important that 'v' is a reference to the objects in in_args.
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header file contains functions for joining a range of elements and
|
||||
// returning the result as a std::string. StrJoin operations are specified by passing
|
||||
// a range, a separator std::string to use between the elements joined, and an
|
||||
// returning the result as a string. StrJoin operations are specified by passing
|
||||
// a range, a separator string to use between the elements joined, and an
|
||||
// optional Formatter responsible for converting each argument in the range to a
|
||||
// std::string. If omitted, a default `AlphaNumFormatter()` is called on the elements
|
||||
// string. If omitted, a default `AlphaNumFormatter()` is called on the elements
|
||||
// to be joined, using the same formatting that `absl::StrCat()` uses. This
|
||||
// package defines a number of default formatters, and you can define your own
|
||||
// implementations.
|
||||
|
@ -29,7 +29,7 @@
|
|||
// Ranges are specified by passing a container with `std::begin()` and
|
||||
// `std::end()` iterators, container-specific `begin()` and `end()` iterators, a
|
||||
// brace-initialized `std::initializer_list`, or a `std::tuple` of heterogeneous
|
||||
// objects. The separator std::string is specified as an `absl::string_view`.
|
||||
// objects. The separator string is specified as an `absl::string_view`.
|
||||
//
|
||||
// Because the default formatter uses the `absl::AlphaNum` class,
|
||||
// `absl::StrJoin()`, like `absl::StrCat()`, will work out-of-the-box on
|
||||
|
@ -37,8 +37,8 @@
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// std::vector<std::string> v = {"foo", "bar", "baz"};
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// std::vector<string> v = {"foo", "bar", "baz"};
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("foo-bar-baz", s);
|
||||
//
|
||||
// See comments on the `absl::StrJoin()` function for more examples.
|
||||
|
@ -66,16 +66,16 @@ namespace absl {
|
|||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// A Formatter is a function object that is responsible for formatting its
|
||||
// argument as a std::string and appending it to a given output std::string. Formatters
|
||||
// argument as a string and appending it to a given output string. Formatters
|
||||
// may be implemented as function objects, lambdas, or normal functions. You may
|
||||
// provide your own Formatter to enable `absl::StrJoin()` to work with arbitrary
|
||||
// types.
|
||||
//
|
||||
// The following is an example of a custom Formatter that simply uses
|
||||
// `std::to_string()` to format an integer as a std::string.
|
||||
// `std::to_string()` to format an integer as a string.
|
||||
//
|
||||
// struct MyFormatter {
|
||||
// void operator()(std::string* out, int i) const {
|
||||
// void operator()(string* out, int i) const {
|
||||
// out->append(std::to_string(i));
|
||||
// }
|
||||
// };
|
||||
|
@ -84,7 +84,7 @@ namespace absl {
|
|||
// argument to `absl::StrJoin()`:
|
||||
//
|
||||
// std::vector<int> v = {1, 2, 3, 4};
|
||||
// std::string s = absl::StrJoin(v, "-", MyFormatter());
|
||||
// string s = absl::StrJoin(v, "-", MyFormatter());
|
||||
// EXPECT_EQ("1-2-3-4", s);
|
||||
//
|
||||
// The following standard formatters are provided within this file:
|
||||
|
@ -156,10 +156,10 @@ DereferenceFormatter() {
|
|||
// StrJoin()
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Joins a range of elements and returns the result as a std::string.
|
||||
// `absl::StrJoin()` takes a range, a separator std::string to use between the
|
||||
// Joins a range of elements and returns the result as a string.
|
||||
// `absl::StrJoin()` takes a range, a separator string to use between the
|
||||
// elements joined, and an optional Formatter responsible for converting each
|
||||
// argument in the range to a std::string.
|
||||
// argument in the range to a string.
|
||||
//
|
||||
// If omitted, the default `AlphaNumFormatter()` is called on the elements to be
|
||||
// joined.
|
||||
|
@ -167,22 +167,22 @@ DereferenceFormatter() {
|
|||
// Example 1:
|
||||
// // Joins a collection of strings. This pattern also works with a collection
|
||||
// // of `absl::string_view` or even `const char*`.
|
||||
// std::vector<std::string> v = {"foo", "bar", "baz"};
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// std::vector<string> v = {"foo", "bar", "baz"};
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("foo-bar-baz", s);
|
||||
//
|
||||
// Example 2:
|
||||
// // Joins the values in the given `std::initializer_list<>` specified using
|
||||
// // brace initialization. This pattern also works with an initializer_list
|
||||
// // of ints or `absl::string_view` -- any `AlphaNum`-compatible type.
|
||||
// std::string s = absl::StrJoin({"foo", "bar", "baz"}, "-");
|
||||
// string s = absl::StrJoin({"foo", "bar", "baz"}, "-");
|
||||
// EXPECT_EQ("foo-bar-baz", s);
|
||||
//
|
||||
// Example 3:
|
||||
// // Joins a collection of ints. This pattern also works with floats,
|
||||
// // doubles, int64s -- any `StrCat()`-compatible type.
|
||||
// std::vector<int> v = {1, 2, 3, -4};
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("1-2-3--4", s);
|
||||
//
|
||||
// Example 4:
|
||||
|
@ -193,7 +193,7 @@ DereferenceFormatter() {
|
|||
// // `std::vector<int*>`.
|
||||
// int x = 1, y = 2, z = 3;
|
||||
// std::vector<int*> v = {&x, &y, &z};
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("1-2-3", s);
|
||||
//
|
||||
// Example 5:
|
||||
|
@ -202,42 +202,42 @@ DereferenceFormatter() {
|
|||
// v.emplace_back(new int(1));
|
||||
// v.emplace_back(new int(2));
|
||||
// v.emplace_back(new int(3));
|
||||
// std::string s = absl::StrJoin(v, "-");
|
||||
// string s = absl::StrJoin(v, "-");
|
||||
// EXPECT_EQ("1-2-3", s);
|
||||
//
|
||||
// Example 6:
|
||||
// // Joins a `std::map`, with each key-value pair separated by an equals
|
||||
// // sign. This pattern would also work with, say, a
|
||||
// // `std::vector<std::pair<>>`.
|
||||
// std::map<std::string, int> m = {
|
||||
// std::map<string, int> m = {
|
||||
// std::make_pair("a", 1),
|
||||
// std::make_pair("b", 2),
|
||||
// std::make_pair("c", 3)};
|
||||
// std::string s = absl::StrJoin(m, ",", absl::PairFormatter("="));
|
||||
// string s = absl::StrJoin(m, ",", absl::PairFormatter("="));
|
||||
// EXPECT_EQ("a=1,b=2,c=3", s);
|
||||
//
|
||||
// Example 7:
|
||||
// // These examples show how `absl::StrJoin()` handles a few common edge
|
||||
// // cases:
|
||||
// std::vector<std::string> v_empty;
|
||||
// std::vector<string> v_empty;
|
||||
// EXPECT_EQ("", absl::StrJoin(v_empty, "-"));
|
||||
//
|
||||
// std::vector<std::string> v_one_item = {"foo"};
|
||||
// std::vector<string> v_one_item = {"foo"};
|
||||
// EXPECT_EQ("foo", absl::StrJoin(v_one_item, "-"));
|
||||
//
|
||||
// std::vector<std::string> v_empty_string = {""};
|
||||
// std::vector<string> v_empty_string = {""};
|
||||
// EXPECT_EQ("", absl::StrJoin(v_empty_string, "-"));
|
||||
//
|
||||
// std::vector<std::string> v_one_item_empty_string = {"a", ""};
|
||||
// std::vector<string> v_one_item_empty_string = {"a", ""};
|
||||
// EXPECT_EQ("a-", absl::StrJoin(v_one_item_empty_string, "-"));
|
||||
//
|
||||
// std::vector<std::string> v_two_empty_string = {"", ""};
|
||||
// std::vector<string> v_two_empty_string = {"", ""};
|
||||
// EXPECT_EQ("-", absl::StrJoin(v_two_empty_string, "-"));
|
||||
//
|
||||
// Example 8:
|
||||
// // Joins a `std::tuple<T...>` of heterogeneous types, converting each to
|
||||
// // a std::string using the `absl::AlphaNum` class.
|
||||
// std::string s = absl::StrJoin(std::make_tuple(123, "abc", 0.456), "-");
|
||||
// // a string using the `absl::AlphaNum` class.
|
||||
// string s = absl::StrJoin(std::make_tuple(123, "abc", 0.456), "-");
|
||||
// EXPECT_EQ("123-abc-0.456", s);
|
||||
|
||||
template <typename Iterator, typename Formatter>
|
||||
|
|
|
@ -17,19 +17,19 @@
|
|||
// File: str_replace.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This file defines `absl::StrReplaceAll()`, a general-purpose std::string
|
||||
// This file defines `absl::StrReplaceAll()`, a general-purpose string
|
||||
// replacement function designed for large, arbitrary text substitutions,
|
||||
// especially on strings which you are receiving from some other system for
|
||||
// further processing (e.g. processing regular expressions, escaping HTML
|
||||
// entities, etc. `StrReplaceAll` is designed to be efficient even when only
|
||||
// one substitution is being performed, or when substitution is rare.
|
||||
//
|
||||
// If the std::string being modified is known at compile-time, and the substitutions
|
||||
// If the string being modified is known at compile-time, and the substitutions
|
||||
// vary, `absl::Substitute()` may be a better choice.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string html_escaped = absl::StrReplaceAll(user_input, {
|
||||
// string html_escaped = absl::StrReplaceAll(user_input, {
|
||||
// {"&", "&"},
|
||||
// {"<", "<"},
|
||||
// {">", ">"},
|
||||
|
@ -49,16 +49,16 @@ namespace absl {
|
|||
|
||||
// StrReplaceAll()
|
||||
//
|
||||
// Replaces character sequences within a given std::string with replacements provided
|
||||
// Replaces character sequences within a given string with replacements provided
|
||||
// within an initializer list of key/value pairs. Candidate replacements are
|
||||
// considered in order as they occur within the std::string, with earlier matches
|
||||
// considered in order as they occur within the string, with earlier matches
|
||||
// taking precedence, and longer matches taking precedence for candidates
|
||||
// starting at the same position in the std::string. Once a substitution is made, the
|
||||
// starting at the same position in the string. Once a substitution is made, the
|
||||
// replaced text is not considered for any further substitutions.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string s = absl::StrReplaceAll("$who bought $count #Noun. Thanks $who!",
|
||||
// string s = absl::StrReplaceAll("$who bought $count #Noun. Thanks $who!",
|
||||
// {{"$count", absl::StrCat(5)},
|
||||
// {"$who", "Bob"},
|
||||
// {"#Noun", "Apples"}});
|
||||
|
@ -78,28 +78,28 @@ ABSL_MUST_USE_RESULT std::string StrReplaceAll(
|
|||
// replacements["$who"] = "Bob";
|
||||
// replacements["$count"] = "5";
|
||||
// replacements["#Noun"] = "Apples";
|
||||
// std::string s = absl::StrReplaceAll("$who bought $count #Noun. Thanks $who!",
|
||||
// string s = absl::StrReplaceAll("$who bought $count #Noun. Thanks $who!",
|
||||
// replacements);
|
||||
// EXPECT_EQ("Bob bought 5 Apples. Thanks Bob!", s);
|
||||
//
|
||||
// // A std::vector of std::pair elements can be more efficient.
|
||||
// std::vector<std::pair<const absl::string_view, std::string>> replacements;
|
||||
// std::vector<std::pair<const absl::string_view, string>> replacements;
|
||||
// replacements.push_back({"&", "&"});
|
||||
// replacements.push_back({"<", "<"});
|
||||
// replacements.push_back({">", ">"});
|
||||
// std::string s = absl::StrReplaceAll("if (ptr < &foo)",
|
||||
// string s = absl::StrReplaceAll("if (ptr < &foo)",
|
||||
// replacements);
|
||||
// EXPECT_EQ("if (ptr < &foo)", s);
|
||||
template <typename StrToStrMapping>
|
||||
std::string StrReplaceAll(absl::string_view s, const StrToStrMapping& replacements);
|
||||
|
||||
// Overload of `StrReplaceAll()` to replace character sequences within a given
|
||||
// output std::string *in place* with replacements provided within an initializer
|
||||
// output string *in place* with replacements provided within an initializer
|
||||
// list of key/value pairs, returning the number of substitutions that occurred.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string s = std::string("$who bought $count #Noun. Thanks $who!");
|
||||
// string s = std::string("$who bought $count #Noun. Thanks $who!");
|
||||
// int count;
|
||||
// count = absl::StrReplaceAll({{"$count", absl::StrCat(5)},
|
||||
// {"$who", "Bob"},
|
||||
|
@ -112,12 +112,12 @@ int StrReplaceAll(
|
|||
std::string* target);
|
||||
|
||||
// Overload of `StrReplaceAll()` to replace patterns within a given output
|
||||
// std::string *in place* with replacements provided within a container of key/value
|
||||
// string *in place* with replacements provided within a container of key/value
|
||||
// pairs.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// std::string s = std::string("if (ptr < &foo)");
|
||||
// string s = std::string("if (ptr < &foo)");
|
||||
// int count = absl::StrReplaceAll({{"&", "&"},
|
||||
// {"<", "<"},
|
||||
// {">", ">"}}, &s);
|
||||
|
|
|
@ -38,16 +38,16 @@ struct Replacement {
|
|||
{"liquor", "shakes"}, //
|
||||
};
|
||||
|
||||
// Here, we set up a std::string for use in global-replace benchmarks.
|
||||
// Here, we set up a string for use in global-replace benchmarks.
|
||||
// We started with a million blanks, and then deterministically insert
|
||||
// 10,000 copies each of two pangrams. The result is a std::string that is
|
||||
// 10,000 copies each of two pangrams. The result is a string that is
|
||||
// 40% blank space and 60% these words. 'the' occurs 18,247 times and
|
||||
// all the substitutions together occur 49,004 times.
|
||||
//
|
||||
// We then create "after_replacing_the" to be a std::string that is a result of
|
||||
// We then create "after_replacing_the" to be a string that is a result of
|
||||
// replacing "the" with "box" in big_string.
|
||||
//
|
||||
// And then we create "after_replacing_many" to be a std::string that is result
|
||||
// And then we create "after_replacing_many" to be a string that is result
|
||||
// of preferring several substitutions.
|
||||
void SetUpStrings() {
|
||||
if (big_string == nullptr) {
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
//
|
||||
// This file contains functions for splitting strings. It defines the main
|
||||
// `StrSplit()` function, several delimiters for determining the boundaries on
|
||||
// which to split the std::string, and predicates for filtering delimited results.
|
||||
// which to split the string, and predicates for filtering delimited results.
|
||||
// `StrSplit()` adapts the returned collection to the type specified by the
|
||||
// caller.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // Splits the given std::string on commas. Returns the results in a
|
||||
// // Splits the given string on commas. Returns the results in a
|
||||
// // vector of strings.
|
||||
// std::vector<std::string> v = absl::StrSplit("a,b,c", ',');
|
||||
// // Can also use ","
|
||||
|
@ -55,7 +55,7 @@ namespace absl {
|
|||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// `StrSplit()` uses delimiters to define the boundaries between elements in the
|
||||
// provided input. Several `Delimiter` types are defined below. If a std::string
|
||||
// provided input. Several `Delimiter` types are defined below. If a string
|
||||
// (`const char*`, `std::string`, or `absl::string_view`) is passed in place of
|
||||
// an explicit `Delimiter` object, `StrSplit()` treats it the same way as if it
|
||||
// were passed a `ByString` delimiter.
|
||||
|
@ -65,7 +65,7 @@ namespace absl {
|
|||
//
|
||||
// The following `Delimiter` types are available for use within `StrSplit()`:
|
||||
//
|
||||
// - `ByString` (default for std::string arguments)
|
||||
// - `ByString` (default for string arguments)
|
||||
// - `ByChar` (default for a char argument)
|
||||
// - `ByAnyChar`
|
||||
// - `ByLength`
|
||||
|
@ -76,15 +76,15 @@ namespace absl {
|
|||
// be split and the position to begin searching for the next delimiter in the
|
||||
// input text. The returned absl::string_view should refer to the next
|
||||
// occurrence (after pos) of the represented delimiter; this returned
|
||||
// absl::string_view represents the next location where the input std::string should
|
||||
// absl::string_view represents the next location where the input string should
|
||||
// be broken. The returned absl::string_view may be zero-length if the Delimiter
|
||||
// does not represent a part of the std::string (e.g., a fixed-length delimiter). If
|
||||
// does not represent a part of the string (e.g., a fixed-length delimiter). If
|
||||
// no delimiter is found in the given text, a zero-length absl::string_view
|
||||
// referring to text.end() should be returned (e.g.,
|
||||
// absl::string_view(text.end(), 0)). It is important that the returned
|
||||
// absl::string_view always be within the bounds of input text given as an
|
||||
// argument--it must not refer to a std::string that is physically located outside of
|
||||
// the given std::string.
|
||||
// argument--it must not refer to a string that is physically located outside of
|
||||
// the given string.
|
||||
//
|
||||
// The following example is a simple Delimiter object that is created with a
|
||||
// single char and will look for that char in the text passed to the Find()
|
||||
|
@ -104,13 +104,13 @@ namespace absl {
|
|||
|
||||
// ByString
|
||||
//
|
||||
// A sub-std::string delimiter. If `StrSplit()` is passed a std::string in place of a
|
||||
// `Delimiter` object, the std::string will be implicitly converted into a
|
||||
// A sub-string delimiter. If `StrSplit()` is passed a string in place of a
|
||||
// `Delimiter` object, the string will be implicitly converted into a
|
||||
// `ByString` delimiter.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // Because a std::string literal is converted to an `absl::ByString`,
|
||||
// // Because a string literal is converted to an `absl::ByString`,
|
||||
// // the following two splits are equivalent.
|
||||
//
|
||||
// std::vector<std::string> v1 = absl::StrSplit("a, b, c", ", ");
|
||||
|
@ -131,7 +131,7 @@ class ByString {
|
|||
// ByChar
|
||||
//
|
||||
// A single character delimiter. `ByChar` is functionally equivalent to a
|
||||
// 1-char std::string within a `ByString` delimiter, but slightly more
|
||||
// 1-char string within a `ByString` delimiter, but slightly more
|
||||
// efficient.
|
||||
//
|
||||
// Example:
|
||||
|
@ -164,9 +164,9 @@ class ByChar {
|
|||
// ByAnyChar
|
||||
//
|
||||
// A delimiter that will match any of the given byte-sized characters within
|
||||
// its provided std::string.
|
||||
// its provided string.
|
||||
//
|
||||
// Note: this delimiter works with single-byte std::string data, but does not work
|
||||
// Note: this delimiter works with single-byte string data, but does not work
|
||||
// with variable-width encodings, such as UTF-8.
|
||||
//
|
||||
// Example:
|
||||
|
@ -175,8 +175,8 @@ class ByChar {
|
|||
// std::vector<std::string> v = absl::StrSplit("a,b=c", ByAnyChar(",="));
|
||||
// // v[0] == "a", v[1] == "b", v[2] == "c"
|
||||
//
|
||||
// If `ByAnyChar` is given the empty std::string, it behaves exactly like
|
||||
// `ByString` and matches each individual character in the input std::string.
|
||||
// If `ByAnyChar` is given the empty string, it behaves exactly like
|
||||
// `ByString` and matches each individual character in the input string.
|
||||
//
|
||||
class ByAnyChar {
|
||||
public:
|
||||
|
@ -192,7 +192,7 @@ class ByAnyChar {
|
|||
// A delimiter for splitting into equal-length strings. The length argument to
|
||||
// the constructor must be greater than 0.
|
||||
//
|
||||
// Note: this delimiter works with single-byte std::string data, but does not work
|
||||
// Note: this delimiter works with single-byte string data, but does not work
|
||||
// with variable-width encodings, such as UTF-8.
|
||||
//
|
||||
// Example:
|
||||
|
@ -202,7 +202,7 @@ class ByAnyChar {
|
|||
|
||||
// // v[0] == "123", v[1] == "456", v[2] == "789"
|
||||
//
|
||||
// Note that the std::string does not have to be a multiple of the fixed split
|
||||
// Note that the string does not have to be a multiple of the fixed split
|
||||
// length. In such a case, the last substring will be shorter.
|
||||
//
|
||||
// using absl::ByLength;
|
||||
|
@ -223,9 +223,9 @@ namespace strings_internal {
|
|||
// A traits-like metafunction for selecting the default Delimiter object type
|
||||
// for a particular Delimiter type. The base case simply exposes type Delimiter
|
||||
// itself as the delimiter's Type. However, there are specializations for
|
||||
// std::string-like objects that map them to the ByString delimiter object.
|
||||
// string-like objects that map them to the ByString delimiter object.
|
||||
// This allows functions like absl::StrSplit() and absl::MaxSplits() to accept
|
||||
// std::string-like objects (e.g., ',') as delimiter arguments but they will be
|
||||
// string-like objects (e.g., ',') as delimiter arguments but they will be
|
||||
// treated as if a ByString delimiter was given.
|
||||
template <typename Delimiter>
|
||||
struct SelectDelimiter {
|
||||
|
@ -331,7 +331,7 @@ struct AllowEmpty {
|
|||
// SkipEmpty()
|
||||
//
|
||||
// Returns `false` if the given `absl::string_view` is empty, indicating that
|
||||
// `StrSplit()` should omit the empty std::string.
|
||||
// `StrSplit()` should omit the empty string.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
|
@ -339,7 +339,7 @@ struct AllowEmpty {
|
|||
//
|
||||
// // v[0] == "a", v[1] == "b"
|
||||
//
|
||||
// Note: `SkipEmpty()` does not consider a std::string containing only whitespace
|
||||
// Note: `SkipEmpty()` does not consider a string containing only whitespace
|
||||
// to be empty. To skip such whitespace as well, use the `SkipWhitespace()`
|
||||
// predicate.
|
||||
struct SkipEmpty {
|
||||
|
@ -349,7 +349,7 @@ struct SkipEmpty {
|
|||
// SkipWhitespace()
|
||||
//
|
||||
// Returns `false` if the given `absl::string_view` is empty *or* contains only
|
||||
// whitespace, indicating that `StrSplit()` should omit the std::string.
|
||||
// whitespace, indicating that `StrSplit()` should omit the string.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
|
@ -373,7 +373,7 @@ struct SkipWhitespace {
|
|||
|
||||
// StrSplit()
|
||||
//
|
||||
// Splits a given std::string based on the provided `Delimiter` object, returning the
|
||||
// Splits a given string based on the provided `Delimiter` object, returning the
|
||||
// elements within the type specified by the caller. Optionally, you may pass a
|
||||
// `Predicate` to `StrSplit()` indicating whether to include or exclude the
|
||||
// resulting element within the final result set. (See the overviews for
|
||||
|
@ -412,7 +412,7 @@ struct SkipWhitespace {
|
|||
//
|
||||
// The `StrSplit()` function adapts the returned collection to the collection
|
||||
// specified by the caller (e.g. `std::vector` above). The returned collections
|
||||
// may contain `string`, `absl::string_view` (in which case the original std::string
|
||||
// may contain `string`, `absl::string_view` (in which case the original string
|
||||
// being split must ensure that it outlives the collection), or any object that
|
||||
// can be explicitly created from an `absl::string_view`. This behavior works
|
||||
// for:
|
||||
|
@ -424,7 +424,7 @@ struct SkipWhitespace {
|
|||
// Example:
|
||||
//
|
||||
// // The results are returned as `absl::string_view` objects. Note that we
|
||||
// // have to ensure that the input std::string outlives any results.
|
||||
// // have to ensure that the input string outlives any results.
|
||||
// std::vector<absl::string_view> v = absl::StrSplit("a,b,c", ',');
|
||||
//
|
||||
// // Stores results in a std::set<std::string>, which also performs
|
||||
|
@ -444,7 +444,7 @@ struct SkipWhitespace {
|
|||
// // is provided as a series of key/value pairs. For example, the 0th element
|
||||
// // resulting from the split will be stored as a key to the 1st element. If
|
||||
// // an odd number of elements are resolved, the last element is paired with
|
||||
// // a default-constructed value (e.g., empty std::string).
|
||||
// // a default-constructed value (e.g., empty string).
|
||||
// std::map<std::string, std::string> m = absl::StrSplit("a,b,c", ',');
|
||||
// // m["a"] == "b", m["c"] == "" // last component value equals ""
|
||||
//
|
||||
|
@ -452,14 +452,14 @@ struct SkipWhitespace {
|
|||
// elements and is not a collection type. When splitting to a `std::pair` the
|
||||
// first two split strings become the `std::pair` `.first` and `.second`
|
||||
// members, respectively. The remaining split substrings are discarded. If there
|
||||
// are less than two split substrings, the empty std::string is used for the
|
||||
// are less than two split substrings, the empty string is used for the
|
||||
// corresponding
|
||||
// `std::pair` member.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // Stores first two split strings as the members in a std::pair.
|
||||
// std::pair<std::string, std::string> p = absl::StrSplit("a,b,c", ',');
|
||||
// std::pair<string, string> p = absl::StrSplit("a,b,c", ',');
|
||||
// // p.first == "a", p.second == "b" // "c" is omitted.
|
||||
//
|
||||
// The `StrSplit()` function can be used multiple times to perform more
|
||||
|
@ -467,9 +467,9 @@ struct SkipWhitespace {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// // The input std::string "a=b=c,d=e,f=,g" becomes
|
||||
// // The input string "a=b=c,d=e,f=,g" becomes
|
||||
// // { "a" => "b=c", "d" => "e", "f" => "", "g" => "" }
|
||||
// std::map<std::string, std::string> m;
|
||||
// std::map<string, string> m;
|
||||
// for (absl::string_view sp : absl::StrSplit("a=b=c,d=e,f=,g", ',')) {
|
||||
// m.insert(absl::StrSplit(sp, absl::MaxSplits('=', 1)));
|
||||
// }
|
||||
|
|
|
@ -276,7 +276,7 @@ TEST(SplitIterator, Basics) {
|
|||
EXPECT_EQ(it, end);
|
||||
}
|
||||
|
||||
// Simple Predicate to skip a particular std::string.
|
||||
// Simple Predicate to skip a particular string.
|
||||
class Skip {
|
||||
public:
|
||||
explicit Skip(const std::string& s) : s_(s) {}
|
||||
|
@ -768,7 +768,7 @@ static bool IsFoundAtStartingPos(absl::string_view text, Delimiter d,
|
|||
}
|
||||
|
||||
// Helper function for testing Delimiter objects. Returns true if the given
|
||||
// Delimiter is found in the given std::string at the given position. This function
|
||||
// Delimiter is found in the given string at the given position. This function
|
||||
// tests two cases:
|
||||
// 1. The actual text given, staring at position 0
|
||||
// 2. The text given with leading padding that should be ignored
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
//
|
||||
// This file contains the definition of the `absl::string_view` class. A
|
||||
// `string_view` points to a contiguous span of characters, often part or all of
|
||||
// another `std::string`, double-quoted std::string literal, character array, or even
|
||||
// another `std::string`, double-quoted string literal, character array, or even
|
||||
// another `string_view`.
|
||||
//
|
||||
// This `absl::string_view` abstraction is designed to be a drop-in
|
||||
|
@ -56,15 +56,15 @@ namespace absl {
|
|||
|
||||
// absl::string_view
|
||||
//
|
||||
// A `string_view` provides a lightweight view into the std::string data provided by
|
||||
// a `std::string`, double-quoted std::string literal, character array, or even
|
||||
// another `string_view`. A `string_view` does *not* own the std::string to which it
|
||||
// A `string_view` provides a lightweight view into the string data provided by
|
||||
// a `std::string`, double-quoted string literal, character array, or even
|
||||
// another `string_view`. A `string_view` does *not* own the string to which it
|
||||
// points, and that data cannot be modified through the view.
|
||||
//
|
||||
// You can use `string_view` as a function or method parameter anywhere a
|
||||
// parameter can receive a double-quoted std::string literal, `const char*`,
|
||||
// parameter can receive a double-quoted string literal, `const char*`,
|
||||
// `std::string`, or another `absl::string_view` argument with no need to copy
|
||||
// the std::string data. Systematic use of `string_view` within function arguments
|
||||
// the string data. Systematic use of `string_view` within function arguments
|
||||
// reduces data copies and `strlen()` calls.
|
||||
//
|
||||
// Because of its small size, prefer passing `string_view` by value:
|
||||
|
@ -97,8 +97,8 @@ namespace absl {
|
|||
// `string_view` this way, it is your responsibility to ensure that the object
|
||||
// pointed to by the `string_view` outlives the `string_view`.
|
||||
//
|
||||
// A `string_view` may represent a whole std::string or just part of a std::string. For
|
||||
// example, when splitting a std::string, `std::vector<absl::string_view>` is a
|
||||
// A `string_view` may represent a whole string or just part of a string. For
|
||||
// example, when splitting a string, `std::vector<absl::string_view>` is a
|
||||
// natural data type for the output.
|
||||
//
|
||||
//
|
||||
|
|
|
@ -284,7 +284,7 @@ TEST(StringViewTest, ComparisonOperatorsByCharacterPosition) {
|
|||
}
|
||||
#undef COMPARE
|
||||
|
||||
// Sadly, our users often confuse std::string::npos with absl::string_view::npos;
|
||||
// Sadly, our users often confuse string::npos with absl::string_view::npos;
|
||||
// So much so that we test here that they are the same. They need to
|
||||
// both be unsigned, and both be the maximum-valued integer of their type.
|
||||
|
||||
|
@ -812,7 +812,7 @@ TEST(StringViewTest, FrontBackSingleChar) {
|
|||
}
|
||||
|
||||
// `std::string_view::string_view(const char*)` calls
|
||||
// `std::char_traits<char>::length(const char*)` to get the std::string length. In
|
||||
// `std::char_traits<char>::length(const char*)` to get the string length. In
|
||||
// libc++, it doesn't allow `nullptr` in the constexpr context, with the error
|
||||
// "read of dereferenced null pointer is not allowed in a constant expression".
|
||||
// At run time, the behavior of `std::char_traits::length()` on `nullptr` is
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// File: strip.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This file contains various functions for stripping substrings from a std::string.
|
||||
// This file contains various functions for stripping substrings from a string.
|
||||
#ifndef ABSL_STRINGS_STRIP_H_
|
||||
#define ABSL_STRINGS_STRIP_H_
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace absl {
|
|||
|
||||
// ConsumePrefix()
|
||||
//
|
||||
// Strips the `expected` prefix from the start of the given std::string, returning
|
||||
// Strips the `expected` prefix from the start of the given string, returning
|
||||
// `true` if the strip operation succeeded or false otherwise.
|
||||
//
|
||||
// Example:
|
||||
|
@ -48,7 +48,7 @@ inline bool ConsumePrefix(absl::string_view* str, absl::string_view expected) {
|
|||
}
|
||||
// ConsumeSuffix()
|
||||
//
|
||||
// Strips the `expected` suffix from the end of the given std::string, returning
|
||||
// Strips the `expected` suffix from the end of the given string, returning
|
||||
// `true` if the strip operation succeeded or false otherwise.
|
||||
//
|
||||
// Example:
|
||||
|
@ -64,9 +64,9 @@ inline bool ConsumeSuffix(absl::string_view* str, absl::string_view expected) {
|
|||
|
||||
// StripPrefix()
|
||||
//
|
||||
// Returns a view into the input std::string 'str' with the given 'prefix' removed,
|
||||
// but leaving the original std::string intact. If the prefix does not match at the
|
||||
// start of the std::string, returns the original std::string instead.
|
||||
// Returns a view into the input string 'str' with the given 'prefix' removed,
|
||||
// but leaving the original string intact. If the prefix does not match at the
|
||||
// start of the string, returns the original string instead.
|
||||
ABSL_MUST_USE_RESULT inline absl::string_view StripPrefix(
|
||||
absl::string_view str, absl::string_view prefix) {
|
||||
if (absl::StartsWith(str, prefix)) str.remove_prefix(prefix.size());
|
||||
|
@ -75,9 +75,9 @@ ABSL_MUST_USE_RESULT inline absl::string_view StripPrefix(
|
|||
|
||||
// StripSuffix()
|
||||
//
|
||||
// Returns a view into the input std::string 'str' with the given 'suffix' removed,
|
||||
// but leaving the original std::string intact. If the suffix does not match at the
|
||||
// end of the std::string, returns the original std::string instead.
|
||||
// Returns a view into the input string 'str' with the given 'suffix' removed,
|
||||
// but leaving the original string intact. If the suffix does not match at the
|
||||
// end of the string, returns the original string instead.
|
||||
ABSL_MUST_USE_RESULT inline absl::string_view StripSuffix(
|
||||
absl::string_view str, absl::string_view suffix) {
|
||||
if (absl::EndsWith(str, suffix)) str.remove_suffix(suffix.size());
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file contains functions that remove a defined part from the std::string,
|
||||
// i.e., strip the std::string.
|
||||
// This file contains functions that remove a defined part from the string,
|
||||
// i.e., strip the string.
|
||||
|
||||
#include "absl/strings/strip.h"
|
||||
|
||||
|
|
|
@ -17,46 +17,46 @@
|
|||
// File: substitute.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This package contains functions for efficiently performing std::string
|
||||
// substitutions using a format std::string with positional notation:
|
||||
// This package contains functions for efficiently performing string
|
||||
// substitutions using a format string with positional notation:
|
||||
// `Substitute()` and `SubstituteAndAppend()`.
|
||||
//
|
||||
// Unlike printf-style format specifiers, `Substitute()` functions do not need
|
||||
// to specify the type of the substitution arguments. Supported arguments
|
||||
// following the format std::string, such as strings, string_views, ints,
|
||||
// following the format string, such as strings, string_views, ints,
|
||||
// floats, and bools, are automatically converted to strings during the
|
||||
// substitution process. (See below for a full list of supported types.)
|
||||
//
|
||||
// `Substitute()` does not allow you to specify *how* to format a value, beyond
|
||||
// the default conversion to std::string. For example, you cannot format an integer
|
||||
// the default conversion to string. For example, you cannot format an integer
|
||||
// in hex.
|
||||
//
|
||||
// The format std::string uses positional identifiers indicated by a dollar sign ($)
|
||||
// The format string uses positional identifiers indicated by a dollar sign ($)
|
||||
// and single digit positional ids to indicate which substitution arguments to
|
||||
// use at that location within the format std::string.
|
||||
// use at that location within the format string.
|
||||
//
|
||||
// Example 1:
|
||||
// std::string s = Substitute("$1 purchased $0 $2. Thanks $1!",
|
||||
// string s = Substitute("$1 purchased $0 $2. Thanks $1!",
|
||||
// 5, "Bob", "Apples");
|
||||
// EXPECT_EQ("Bob purchased 5 Apples. Thanks Bob!", s);
|
||||
//
|
||||
// Example 2:
|
||||
// std::string s = "Hi. ";
|
||||
// string s = "Hi. ";
|
||||
// SubstituteAndAppend(&s, "My name is $0 and I am $1 years old.", "Bob", 5);
|
||||
// EXPECT_EQ("Hi. My name is Bob and I am 5 years old.", s);
|
||||
//
|
||||
//
|
||||
// Supported types:
|
||||
// * absl::string_view, std::string, const char* (null is equivalent to "")
|
||||
// * absl::string_view, string, const char* (null is equivalent to "")
|
||||
// * int32_t, int64_t, uint32_t, uint64
|
||||
// * float, double
|
||||
// * bool (Printed as "true" or "false")
|
||||
// * pointer types other than char* (Printed as "0x<lower case hex std::string>",
|
||||
// * pointer types other than char* (Printed as "0x<lower case hex string>",
|
||||
// except that null is printed as "NULL")
|
||||
//
|
||||
// If an invalid format std::string is provided, Substitute returns an empty std::string
|
||||
// and SubstituteAndAppend does not change the provided output std::string.
|
||||
// A format std::string is invalid if it:
|
||||
// If an invalid format string is provided, Substitute returns an empty string
|
||||
// and SubstituteAndAppend does not change the provided output string.
|
||||
// A format string is invalid if it:
|
||||
// * ends in an unescaped $ character,
|
||||
// e.g. "Hello $", or
|
||||
// * calls for a position argument which is not provided,
|
||||
|
@ -88,7 +88,7 @@ namespace substitute_internal {
|
|||
//
|
||||
// This class provides an argument type for `absl::Substitute()` and
|
||||
// `absl::SubstituteAndAppend()`. `Arg` handles implicit conversion of various
|
||||
// types to a std::string. (`Arg` is very similar to the `AlphaNum` class in
|
||||
// types to a string. (`Arg` is very similar to the `AlphaNum` class in
|
||||
// `StrCat()`.)
|
||||
//
|
||||
// This class has implicit constructors.
|
||||
|
@ -197,8 +197,8 @@ constexpr int PlaceholderBitmask(const char* format) {
|
|||
|
||||
// SubstituteAndAppend()
|
||||
//
|
||||
// Substitutes variables into a given format std::string and appends to a given
|
||||
// output std::string. See file comments above for usage.
|
||||
// Substitutes variables into a given format string and appends to a given
|
||||
// output string. See file comments above for usage.
|
||||
//
|
||||
// The declarations of `SubstituteAndAppend()` below consist of overloads
|
||||
// for passing 0 to 10 arguments, respectively.
|
||||
|
@ -444,7 +444,7 @@ void SubstituteAndAppend(
|
|||
|
||||
// Substitute()
|
||||
//
|
||||
// Substitutes variables into a given format std::string. See file comments above
|
||||
// Substitutes variables into a given format string. See file comments above
|
||||
// for usage.
|
||||
//
|
||||
// The declarations of `Substitute()` below consist of overloads for passing 0
|
||||
|
@ -456,7 +456,7 @@ void SubstituteAndAppend(
|
|||
// Example:
|
||||
// template <typename... Args>
|
||||
// void VarMsg(absl::string_view format, const Args&... args) {
|
||||
// std::string s = absl::Substitute(format, args...);
|
||||
// string s = absl::Substitute(format, args...);
|
||||
|
||||
ABSL_MUST_USE_RESULT inline std::string Substitute(absl::string_view format) {
|
||||
std::string result;
|
||||
|
|
|
@ -298,7 +298,7 @@ static struct SynchEvent { // this is a trivial hash table for the events
|
|||
// set "bits" in the word there (waiting until lockbit is clear before doing
|
||||
// so), and return a refcounted reference that will remain valid until
|
||||
// UnrefSynchEvent() is called. If a new SynchEvent is allocated,
|
||||
// the std::string name is copied into it.
|
||||
// the string name is copied into it.
|
||||
// When used with a mutex, the caller should also ensure that kMuEvent
|
||||
// is set in the mutex word, and similarly for condition variables and kCVEvent.
|
||||
static SynchEvent *EnsureSynchEvent(std::atomic<intptr_t> *addr,
|
||||
|
@ -1827,8 +1827,8 @@ bool Mutex::LockSlowWithDeadline(MuHow how, const Condition *cond,
|
|||
cond == nullptr || EvalConditionAnnotated(cond, this, true, how);
|
||||
}
|
||||
|
||||
// RAW_CHECK_FMT() takes a condition, a printf-style format std::string, and
|
||||
// the printf-style argument list. The format std::string must be a literal.
|
||||
// RAW_CHECK_FMT() takes a condition, a printf-style format string, and
|
||||
// the printf-style argument list. The format string must be a literal.
|
||||
// Arguments after the first are not evaluated unless the condition is true.
|
||||
#define RAW_CHECK_FMT(cond, ...) \
|
||||
do { \
|
||||
|
|
|
@ -962,7 +962,7 @@ void RegisterMutexTracer(void (*fn)(const char *msg, const void *obj,
|
|||
//
|
||||
// The function pointer registered here will be called here on various CondVar
|
||||
// events. The callback is given an opaque handle to the CondVar object and
|
||||
// a std::string identifying the event. This is thread-safe, but only a single
|
||||
// a string identifying the event. This is thread-safe, but only a single
|
||||
// tracer can be registered.
|
||||
//
|
||||
// Events that can be sent are "Wait", "Unwait", "Signal wakeup", and
|
||||
|
|
|
@ -666,7 +666,7 @@ std::chrono::hours ToChronoHours(Duration d) {
|
|||
}
|
||||
|
||||
//
|
||||
// To/From std::string formatting.
|
||||
// To/From string formatting.
|
||||
//
|
||||
|
||||
namespace {
|
||||
|
@ -744,7 +744,7 @@ void AppendNumberUnit(std::string* out, double n, DisplayUnit unit) {
|
|||
} // namespace
|
||||
|
||||
// From Go's doc at http://golang.org/pkg/time/#Duration.String
|
||||
// [FormatDuration] returns a std::string representing the duration in the
|
||||
// [FormatDuration] returns a string representing the duration in the
|
||||
// form "72h3m0.5s". Leading zero units are omitted. As a special
|
||||
// case, durations less than one second format use a smaller unit
|
||||
// (milli-, micro-, or nanoseconds) to ensure that the leading digit
|
||||
|
@ -787,8 +787,8 @@ std::string FormatDuration(Duration d) {
|
|||
namespace {
|
||||
|
||||
// A helper for ParseDuration() that parses a leading number from the given
|
||||
// std::string and stores the result in *int_part/*frac_part/*frac_scale. The
|
||||
// given std::string pointer is modified to point to the first unconsumed char.
|
||||
// string and stores the result in *int_part/*frac_part/*frac_scale. The
|
||||
// given string pointer is modified to point to the first unconsumed char.
|
||||
bool ConsumeDurationNumber(const char** dpp, int64_t* int_part,
|
||||
int64_t* frac_part, int64_t* frac_scale) {
|
||||
*int_part = 0;
|
||||
|
@ -816,8 +816,8 @@ bool ConsumeDurationNumber(const char** dpp, int64_t* int_part,
|
|||
}
|
||||
|
||||
// A helper for ParseDuration() that parses a leading unit designator (e.g.,
|
||||
// ns, us, ms, s, m, h) from the given std::string and stores the resulting unit
|
||||
// in "*unit". The given std::string pointer is modified to point to the first
|
||||
// ns, us, ms, s, m, h) from the given string and stores the resulting unit
|
||||
// in "*unit". The given string pointer is modified to point to the first
|
||||
// unconsumed char.
|
||||
bool ConsumeDurationUnit(const char** start, Duration* unit) {
|
||||
const char *s = *start;
|
||||
|
@ -850,7 +850,7 @@ bool ConsumeDurationUnit(const char** start, Duration* unit) {
|
|||
} // namespace
|
||||
|
||||
// From Go's doc at http://golang.org/pkg/time/#ParseDuration
|
||||
// [ParseDuration] parses a duration std::string. A duration std::string is
|
||||
// [ParseDuration] parses a duration string. A duration string is
|
||||
// a possibly signed sequence of decimal numbers, each with optional
|
||||
// fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m".
|
||||
// Valid time units are "ns", "us" "ms", "s", "m", "h".
|
||||
|
|
|
@ -88,7 +88,7 @@ bool ParseTime(const std::string& format, const std::string& input, absl::Time*
|
|||
return absl::ParseTime(format, input, absl::UTCTimeZone(), time, err);
|
||||
}
|
||||
|
||||
// If the input std::string does not contain an explicit UTC offset, interpret
|
||||
// If the input string does not contain an explicit UTC offset, interpret
|
||||
// the fields with respect to the given TimeZone.
|
||||
bool ParseTime(const std::string& format, const std::string& input, absl::TimeZone tz,
|
||||
absl::Time* time, std::string* err) {
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace cctz {
|
|||
// inferior fields to their minimum valid value (as described above). The
|
||||
// following are examples of how each of the six types would align the fields
|
||||
// representing November 22, 2015 at 12:34:56 in the afternoon. (Note: the
|
||||
// std::string format used here is not important; it's just a shorthand way of
|
||||
// string format used here is not important; it's just a shorthand way of
|
||||
// showing the six YMDHMS fields.)
|
||||
//
|
||||
// civil_second 2015-11-22 12:34:56
|
||||
|
|
|
@ -279,7 +279,7 @@ bool parse(const std::string&, const std::string&, const time_zone&,
|
|||
} // namespace detail
|
||||
|
||||
// Formats the given time_point in the given cctz::time_zone according to
|
||||
// the provided format std::string. Uses strftime()-like formatting options,
|
||||
// the provided format string. Uses strftime()-like formatting options,
|
||||
// with the following extensions:
|
||||
//
|
||||
// - %Ez - RFC3339-compatible numeric UTC offset (+hh:mm or -hh:mm)
|
||||
|
@ -298,7 +298,7 @@ bool parse(const std::string&, const std::string&, const time_zone&,
|
|||
// more than four characters, just like %Y.
|
||||
//
|
||||
// Tip: Format strings should include the UTC offset (e.g., %z, %Ez, or %E*z)
|
||||
// so that the resulting std::string uniquely identifies an absolute time.
|
||||
// so that the resulting string uniquely identifies an absolute time.
|
||||
//
|
||||
// Example:
|
||||
// cctz::time_zone lax;
|
||||
|
@ -314,7 +314,7 @@ inline std::string format(const std::string& fmt, const time_point<D>& tp,
|
|||
return detail::format(fmt, p.first, n, tz);
|
||||
}
|
||||
|
||||
// Parses an input std::string according to the provided format std::string and
|
||||
// Parses an input string according to the provided format string and
|
||||
// returns the corresponding time_point. Uses strftime()-like formatting
|
||||
// options, with the same extensions as cctz::format(), but with the
|
||||
// exceptions that %E#S is interpreted as %E*S, and %E#f as %E*f. %Ez
|
||||
|
@ -328,7 +328,7 @@ inline std::string format(const std::string& fmt, const time_point<D>& tp,
|
|||
//
|
||||
// "1970-01-01 00:00:00.0 +0000"
|
||||
//
|
||||
// For example, parsing a std::string of "15:45" (%H:%M) will return a time_point
|
||||
// For example, parsing a string of "15:45" (%H:%M) will return a time_point
|
||||
// that represents "1970-01-01 15:45:00.0 +0000".
|
||||
//
|
||||
// Note that parse() returns time instants, so it makes most sense to parse
|
||||
|
|
|
@ -533,7 +533,7 @@ const char* ParseSubSeconds(const char* dp, detail::femtoseconds* subseconds) {
|
|||
return dp;
|
||||
}
|
||||
|
||||
// Parses a std::string into a std::tm using strptime(3).
|
||||
// Parses a string into a std::tm using strptime(3).
|
||||
const char* ParseTM(const char* dp, const char* fmt, std::tm* tm) {
|
||||
if (dp != nullptr) {
|
||||
dp = strptime(dp, fmt, tm);
|
||||
|
|
|
@ -286,7 +286,7 @@ bool TimeZoneInfo::EquivTransitions(std::uint_fast8_t tt1_index,
|
|||
return true;
|
||||
}
|
||||
|
||||
// Use the POSIX-TZ-environment-variable-style std::string to handle times
|
||||
// Use the POSIX-TZ-environment-variable-style string to handle times
|
||||
// in years after the last transition stored in the zoneinfo data.
|
||||
void TimeZoneInfo::ExtendTransitions(const std::string& name,
|
||||
const Header& hdr) {
|
||||
|
|
|
@ -89,7 +89,7 @@ struct PosixTransition {
|
|||
} time;
|
||||
};
|
||||
|
||||
// The entirety of a POSIX-std::string specified time-zone rule. The standard
|
||||
// The entirety of a POSIX-string specified time-zone rule. The standard
|
||||
// abbreviation and offset are always given. If the time zone includes
|
||||
// daylight saving, then the daylight abbrevation is non-empty and the
|
||||
// remaining fields are also valid. Note that the start/end transitions
|
||||
|
|
|
@ -481,7 +481,7 @@ std::chrono::hours ToChronoHours(Duration d);
|
|||
|
||||
// FormatDuration()
|
||||
//
|
||||
// Returns a std::string representing the duration in the form "72h3m0.5s".
|
||||
// Returns a string representing the duration in the form "72h3m0.5s".
|
||||
// Returns "inf" or "-inf" for +/- `InfiniteDuration()`.
|
||||
std::string FormatDuration(Duration d);
|
||||
|
||||
|
@ -492,7 +492,7 @@ inline std::ostream& operator<<(std::ostream& os, Duration d) {
|
|||
|
||||
// ParseDuration()
|
||||
//
|
||||
// Parses a duration std::string consisting of a possibly signed sequence of
|
||||
// Parses a duration string consisting of a possibly signed sequence of
|
||||
// decimal numbers, each with an optional fractional part and a unit
|
||||
// suffix. The valid suffixes are "ns", "us" "ms", "s", "m", and "h".
|
||||
// Simple examples include "300ms", "-1.5h", and "2h45m". Parses "0" as
|
||||
|
@ -886,7 +886,7 @@ extern const char RFC1123_no_wday[]; // %d %b %E4Y %H:%M:%S %z
|
|||
// FormatTime()
|
||||
//
|
||||
// Formats the given `absl::Time` in the `absl::TimeZone` according to the
|
||||
// provided format std::string. Uses strftime()-like formatting options, with
|
||||
// provided format string. Uses strftime()-like formatting options, with
|
||||
// the following extensions:
|
||||
//
|
||||
// - %Ez - RFC3339-compatible numeric UTC offset (+hh:mm or -hh:mm)
|
||||
|
@ -913,13 +913,13 @@ extern const char RFC1123_no_wday[]; // %d %b %E4Y %H:%M:%S %z
|
|||
// if (!absl::LoadTimeZone("America/Los_Angeles", &lax)) { ... }
|
||||
// absl::Time t = absl::FromDateTime(2013, 1, 2, 3, 4, 5, lax);
|
||||
//
|
||||
// std::string f = absl::FormatTime("%H:%M:%S", t, lax); // "03:04:05"
|
||||
// string f = absl::FormatTime("%H:%M:%S", t, lax); // "03:04:05"
|
||||
// f = absl::FormatTime("%H:%M:%E3S", t, lax); // "03:04:05.000"
|
||||
//
|
||||
// Note: If the given `absl::Time` is `absl::InfiniteFuture()`, the returned
|
||||
// std::string will be exactly "infinite-future". If the given `absl::Time` is
|
||||
// `absl::InfinitePast()`, the returned std::string will be exactly "infinite-past".
|
||||
// In both cases the given format std::string and `absl::TimeZone` are ignored.
|
||||
// string will be exactly "infinite-future". If the given `absl::Time` is
|
||||
// `absl::InfinitePast()`, the returned string will be exactly "infinite-past".
|
||||
// In both cases the given format string and `absl::TimeZone` are ignored.
|
||||
//
|
||||
std::string FormatTime(const std::string& format, Time t, TimeZone tz);
|
||||
|
||||
|
@ -936,7 +936,7 @@ inline std::ostream& operator<<(std::ostream& os, Time t) {
|
|||
|
||||
// ParseTime()
|
||||
//
|
||||
// Parses an input std::string according to the provided format std::string and
|
||||
// Parses an input string according to the provided format string and
|
||||
// returns the corresponding `absl::Time`. Uses strftime()-like formatting
|
||||
// options, with the same extensions as FormatTime(), but with the
|
||||
// exceptions that %E#S is interpreted as %E*S, and %E#f as %E*f. %Ez
|
||||
|
@ -950,7 +950,7 @@ inline std::ostream& operator<<(std::ostream& os, Time t) {
|
|||
//
|
||||
// "1970-01-01 00:00:00.0 +0000"
|
||||
//
|
||||
// For example, parsing a std::string of "15:45" (%H:%M) will return an absl::Time
|
||||
// For example, parsing a string of "15:45" (%H:%M) will return an absl::Time
|
||||
// that represents "1970-01-01 15:45:00.0 +0000".
|
||||
//
|
||||
// Note that since ParseTime() returns time instants, it makes the most sense
|
||||
|
@ -977,15 +977,15 @@ inline std::ostream& operator<<(std::ostream& os, Time t) {
|
|||
// Errors are indicated by returning false and assigning an error message
|
||||
// to the "err" out param if it is non-null.
|
||||
//
|
||||
// Note: If the input std::string is exactly "infinite-future", the returned
|
||||
// Note: If the input string is exactly "infinite-future", the returned
|
||||
// `absl::Time` will be `absl::InfiniteFuture()` and `true` will be returned.
|
||||
// If the input std::string is "infinite-past", the returned `absl::Time` will be
|
||||
// If the input string is "infinite-past", the returned `absl::Time` will be
|
||||
// `absl::InfinitePast()` and `true` will be returned.
|
||||
//
|
||||
bool ParseTime(const std::string& format, const std::string& input, Time* time,
|
||||
std::string* err);
|
||||
|
||||
// Like ParseTime() above, but if the format std::string does not contain a UTC
|
||||
// Like ParseTime() above, but if the format string does not contain a UTC
|
||||
// offset specification (%z/%Ez/%E*z) then the input is interpreted in the
|
||||
// given TimeZone. This means that the input, by itself, does not identify a
|
||||
// unique instant. Being time-zone dependent, it also admits the possibility
|
||||
|
|
|
@ -87,7 +87,7 @@ constexpr auto GetDataImpl(C& c, char) noexcept // NOLINT(runtime/references)
|
|||
return c.data();
|
||||
}
|
||||
|
||||
// Before C++17, std::string::data returns a const char* in all cases.
|
||||
// Before C++17, string::data returns a const char* in all cases.
|
||||
inline char* GetDataImpl(std::string& s, // NOLINT(runtime/references)
|
||||
int) noexcept {
|
||||
return &s[0];
|
||||
|
|
|
@ -235,13 +235,13 @@ auto apply_helper(Functor&& functor, Tuple&& t, index_sequence<Indexes...>)
|
|||
// Example:
|
||||
//
|
||||
// class Foo{void Bar(int);};
|
||||
// void user_function(int, std::string);
|
||||
// void user_function(int, string);
|
||||
// void user_function(std::unique_ptr<Foo>);
|
||||
//
|
||||
// int main()
|
||||
// {
|
||||
// std::tuple<int, std::string> tuple1(42, "bar");
|
||||
// // Invokes the user function overload on int, std::string.
|
||||
// std::tuple<int, string> tuple1(42, "bar");
|
||||
// // Invokes the user function overload on int, string.
|
||||
// absl::apply(&user_function, tuple1);
|
||||
//
|
||||
// auto foo = absl::make_unique<Foo>();
|
||||
|
|
Loading…
Reference in a new issue