Skip to content

Commit

Permalink
Reland "[base] Change string16 to std::u16string everywhere"
Browse files Browse the repository at this point in the history
This is a reland of 7c12965

In addition to the initial changes it addresses the compiliation failure
in tools/ipc_fuzzer/message_dump/message_dump.cc.

Original change's description:
> [base] Change string16 to std::u16string everywhere
>
> This change modifies base::string16 to be an alias of std::u16string
> on all platforms. base::char16, blink::WebUChar and the STRING16_LITERAL
> macro are modified accordingly.
>
> Bug: 911896
> Change-Id: I15aec7b9f50288291219426857e8a1b5d93ad852
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1776026
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Commit-Queue: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#858728}

Bug: 911896
Change-Id: I87ab070e1f865ae4c7d0fb518855c2bb51de3958
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2727825
Owners-Override: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#859028}
  • Loading branch information
jdoerrie authored and Chromium LUCI CQ committed Mar 2, 2021
1 parent c80b54f commit 33685a1
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 30 deletions.
17 changes: 3 additions & 14 deletions base/strings/string16.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,21 @@

#include <string>

#include "build/build_config.h"

#if defined(WCHAR_T_IS_UTF16)

// Define a macro for wrapping construction of char16 arrays and string16s from
// a literal string. This indirection allows for an easier migration of
// base::char16 to char16_t on platforms where WCHAR_T_IS_UTF16, as only a one
// character change to the macro will be necessary.
// TODO(https://crbug.com/911896): Remove this macro once base::char16 is
// char16_t on all platforms.
#define STRING16_LITERAL(x) L##x

namespace base {
using char16 = wchar_t;
using string16 = std::wstring;
} // namespace base

#else

#define STRING16_LITERAL(x) u##x

namespace base {
using char16 = char16_t;
using string16 = std::u16string;
} // namespace base

#endif // WCHAR_T_IS_UTF16
#ifndef BASE_STRING16_IS_STD_U16STRING
#define BASE_STRING16_IS_STD_U16STRING
#endif // BASE_STRING16_IS_STD_U16STRING

#endif // BASE_STRINGS_STRING16_H_
6 changes: 1 addition & 5 deletions base/strings/string_piece.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ inline void BuildLookupTable(StringPiece characters_wanted, bool* table) {
#if !defined(COMPILER_MSVC)
template class BasicStringPiece<std::string>;
template class BasicStringPiece<string16>;
template class BasicStringPiece<std::wstring>;
#endif

std::ostream& operator<<(std::ostream& o, StringPiece piece) {
Expand All @@ -50,11 +51,9 @@ std::ostream& operator<<(std::ostream& o, StringPiece16 piece) {
return o << UTF16ToUTF8(piece);
}

#if !defined(WCHAR_T_IS_UTF16)
std::ostream& operator<<(std::ostream& o, WStringPiece piece) {
return o << WideToUTF8(piece);
}
#endif

namespace internal {

Expand Down Expand Up @@ -284,7 +283,6 @@ size_t find_last_not_of(StringPiece16 self, StringPiece16 s, size_t pos) {
return find_last_not_ofT(self, s, pos);
}

#if !defined(WCHAR_T_IS_UTF16)
size_t find(WStringPiece self, WStringPiece s, size_t pos) {
return findT(self, s, pos);
}
Expand All @@ -308,7 +306,5 @@ size_t find_last_of(WStringPiece self, WStringPiece s, size_t pos) {
size_t find_last_not_of(WStringPiece self, WStringPiece s, size_t pos) {
return find_last_not_ofT(self, s, pos);
}
#endif

} // namespace internal
} // namespace base
6 changes: 0 additions & 6 deletions base/strings/string_piece.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ BASE_EXPORT size_t find_last_not_of(StringPiece16 self,
StringPiece16 s,
size_t pos);

// Overloads for WStringPiece in case it is not the same type as StringPiece16.
#if !defined(WCHAR_T_IS_UTF16)
BASE_EXPORT size_t find(WStringPiece self, WStringPiece s, size_t pos);
BASE_EXPORT size_t rfind(WStringPiece self, WStringPiece s, size_t pos);
BASE_EXPORT size_t find_first_of(WStringPiece self, WStringPiece s, size_t pos);
Expand All @@ -91,7 +89,6 @@ BASE_EXPORT size_t find_last_of(WStringPiece self, WStringPiece s, size_t pos);
BASE_EXPORT size_t find_last_not_of(WStringPiece self,
WStringPiece s,
size_t pos);
#endif

} // namespace internal

Expand Down Expand Up @@ -565,10 +562,7 @@ constexpr bool operator>=(std::common_type_t<BasicStringPiece<StringT>> lhs,

BASE_EXPORT std::ostream& operator<<(std::ostream& o, StringPiece piece);
BASE_EXPORT std::ostream& operator<<(std::ostream& o, StringPiece16 piece);

#if !defined(WCHAR_T_IS_UTF16)
BASE_EXPORT std::ostream& operator<<(std::ostream& o, WStringPiece piece);
#endif

// Hashing ---------------------------------------------------------------------

Expand Down
4 changes: 0 additions & 4 deletions third_party/blink/public/platform/web_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ namespace blink {
typedef int32_t WebUChar32;

// UTF-16 character type
#if defined(WIN32)
typedef wchar_t WebUChar;
#else
typedef char16_t WebUChar;
#endif

// Latin-1 character type
typedef unsigned char WebLChar;
Expand Down
2 changes: 1 addition & 1 deletion tools/ipc_fuzzer/message_dump/message_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "tools/ipc_fuzzer/message_lib/message_file.h"

#if defined(OS_WIN)
#define PidToStringType base::NumberToString16
#define PidToStringType base::NumberToWString
#define MESSAGE_DUMP_EXPORT __declspec(dllexport)
#else
#define PidToStringType base::NumberToString
Expand Down

0 comments on commit 33685a1

Please sign in to comment.