From c551f43206405019121bd2b2c93714319a0a3300 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 23 Jan 2020 17:21:03 +0100 Subject: BASELINE: Update Chromium to 79.0.3945.139 Change-Id: I336b7182fab9bca80b709682489c07db112eaca5 Reviewed-by: Allan Sandfeld Jensen --- chromium/base/strings/string_util.h | 47 ++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'chromium/base/strings/string_util.h') diff --git a/chromium/base/strings/string_util.h b/chromium/base/strings/string_util.h index 1398a9ba542..ec0bee3b824 100644 --- a/chromium/base/strings/string_util.h +++ b/chromium/base/strings/string_util.h @@ -204,10 +204,10 @@ enum TrimPositions { // // It is safe to use the same variable for both |input| and |output| (this is // the normal usage to trim in-place). -BASE_EXPORT bool TrimString(const string16& input, +BASE_EXPORT bool TrimString(StringPiece16 input, StringPiece16 trim_chars, string16* output); -BASE_EXPORT bool TrimString(const std::string& input, +BASE_EXPORT bool TrimString(StringPiece input, StringPiece trim_chars, std::string* output); @@ -269,6 +269,24 @@ inline const char16* as_u16cstr(const wchar_t* str) { inline const char16* as_u16cstr(WStringPiece str) { return reinterpret_cast(str.data()); } + +// Utility functions to convert between base::WStringPiece and +// base::StringPiece16. +inline WStringPiece AsWStringPiece(StringPiece16 str) { + return WStringPiece(as_wcstr(str.data()), str.size()); +} + +inline StringPiece16 AsStringPiece16(WStringPiece str) { + return StringPiece16(as_u16cstr(str.data()), str.size()); +} + +inline std::wstring AsWString(StringPiece16 str) { + return std::wstring(as_wcstr(str.data()), str.size()); +} + +inline string16 AsString16(WStringPiece str) { + return string16(as_u16cstr(str.data()), str.size()); +} #endif // defined(WCHAR_T_IS_UTF16) // Trims any whitespace from either end of the input string. @@ -278,12 +296,12 @@ inline const char16* as_u16cstr(WStringPiece str) { // // The std::string versions return where whitespace was found. // NOTE: Safe to use the same variable for both input and output. -BASE_EXPORT TrimPositions TrimWhitespace(const string16& input, +BASE_EXPORT TrimPositions TrimWhitespace(StringPiece16 input, TrimPositions positions, string16* output); BASE_EXPORT StringPiece16 TrimWhitespace(StringPiece16 input, TrimPositions positions); -BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input, +BASE_EXPORT TrimPositions TrimWhitespaceASCII(StringPiece input, TrimPositions positions, std::string* output); BASE_EXPORT StringPiece TrimWhitespaceASCII(StringPiece input, @@ -457,10 +475,6 @@ BASE_EXPORT void ReplaceSubstringsAfterOffset( // convenient in that is can be used inline in the call, and fast in that it // avoids copying the results of the call from a char* into a string. // -// |length_with_null| must be at least 2, since otherwise the underlying string -// would have size 0, and trying to access &((*str)[0]) in that case can result -// in a number of problems. -// // Internally, this takes linear time because the resize() call 0-fills the // underlying array for potentially all // (|length_with_null - 1| * sizeof(string_type::value_type)) bytes. Ideally we @@ -518,6 +532,23 @@ BASE_EXPORT string16 ReplaceStringPlaceholders(const string16& format_string, const string16& a, size_t* offset); +#if defined(OS_WIN) && defined(BASE_STRING16_IS_STD_U16STRING) +BASE_EXPORT TrimPositions TrimWhitespace(WStringPiece input, + TrimPositions positions, + std::wstring* output); + +BASE_EXPORT WStringPiece TrimWhitespace(WStringPiece input, + TrimPositions positions); + +BASE_EXPORT bool TrimString(WStringPiece input, + WStringPiece trim_chars, + std::wstring* output); + +BASE_EXPORT WStringPiece TrimString(WStringPiece input, + WStringPiece trim_chars, + TrimPositions positions); +#endif + } // namespace base #if defined(OS_WIN) -- cgit v1.2.3