[go: nahoru, domu]

[base] Templatize BasicStringPiece by Character Type

This change modifies base::BasicStringPiece to be templatized by char
type rather than string type. This matches more closely
std::basic_string_view or simplifies some implementation details.

This change is purely cosmetic, and does not change functionality.

Bug: 1049498
Change-Id: I2dd968b8f99e313871a5895a81f4ee113423fc0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2784885
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#866832}
diff --git a/base/command_line.h b/base/command_line.h
index 04c76df..a9f4dd2 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -38,8 +38,8 @@
   using StringType = std::string;
 #endif
 
-  using StringPieceType = base::BasicStringPiece<StringType>;
   using CharType = StringType::value_type;
+  using StringPieceType = base::BasicStringPiece<CharType>;
   using StringVector = std::vector<StringType>;
   using SwitchMap = std::map<std::string, StringType, std::less<>>;
 
diff --git a/base/files/file_path.h b/base/files/file_path.h
index c87fe5a..b122de6 100644
--- a/base/files/file_path.h
+++ b/base/files/file_path.h
@@ -161,8 +161,8 @@
   typedef std::string StringType;
 #endif  // OS_WIN
 
-  typedef BasicStringPiece<StringType> StringPieceType;
   typedef StringType::value_type CharType;
+  typedef BasicStringPiece<CharType> StringPieceType;
 
   // Null-terminated array of separators used to separate components in
   // hierarchical paths.  Each character in this array is a valid separator,
diff --git a/base/strings/string_number_conversions_internal.h b/base/strings/string_number_conversions_internal.h
index cb99849..66ff22c 100644
--- a/base/strings/string_number_conversions_internal.h
+++ b/base/strings/string_number_conversions_internal.h
@@ -179,8 +179,8 @@
   };
 };
 
-template <typename Number, int kBase, typename Str>
-auto StringToNumber(BasicStringPiece<Str> input) {
+template <typename Number, int kBase, typename CharT>
+auto StringToNumber(BasicStringPiece<CharT> input) {
   using Parser = StringToNumberParser<Number, kBase>;
   using Result = typename Parser::Result;
 
@@ -212,15 +212,15 @@
   return result;
 }
 
-template <typename STR, typename VALUE>
-bool StringToIntImpl(BasicStringPiece<STR> input, VALUE& output) {
+template <typename CharT, typename VALUE>
+bool StringToIntImpl(BasicStringPiece<CharT> input, VALUE& output) {
   auto result = StringToNumber<VALUE, 10>(input);
   output = result.value;
   return result.valid;
 }
 
-template <typename STR, typename VALUE>
-bool HexStringToIntImpl(BasicStringPiece<STR> input, VALUE& output) {
+template <typename CharT, typename VALUE>
+bool HexStringToIntImpl(BasicStringPiece<CharT> input, VALUE& output) {
   auto result = StringToNumber<VALUE, 16>(input);
   output = result.value;
   return result.valid;
diff --git a/base/strings/string_piece.cc b/base/strings/string_piece.cc
index e9d6f683..cdceb88 100644
--- a/base/strings/string_piece.cc
+++ b/base/strings/string_piece.cc
@@ -37,9 +37,9 @@
 
 // MSVC doesn't like complex extern templates and DLLs.
 #if !defined(COMPILER_MSVC)
-template class BasicStringPiece<std::string>;
-template class BasicStringPiece<std::u16string>;
-template class BasicStringPiece<std::wstring>;
+template class BasicStringPiece<char>;
+template class BasicStringPiece<char16_t>;
+template class BasicStringPiece<wchar_t>;
 #endif
 
 std::ostream& operator<<(std::ostream& o, StringPiece piece) {
@@ -57,16 +57,18 @@
 
 namespace internal {
 
-template <typename STR>
-size_t findT(BasicStringPiece<STR> self, BasicStringPiece<STR> s, size_t pos) {
+template <typename CharT>
+size_t findT(BasicStringPiece<CharT> self,
+             BasicStringPiece<CharT> s,
+             size_t pos) {
   if (pos > self.size())
-    return BasicStringPiece<STR>::npos;
+    return BasicStringPiece<CharT>::npos;
 
-  typename BasicStringPiece<STR>::const_iterator result =
+  typename BasicStringPiece<CharT>::const_iterator result =
       std::search(self.begin() + pos, self.end(), s.begin(), s.end());
   const size_t xpos =
     static_cast<size_t>(result - self.begin());
-  return xpos + s.size() <= self.size() ? xpos : BasicStringPiece<STR>::npos;
+  return xpos + s.size() <= self.size() ? xpos : BasicStringPiece<CharT>::npos;
 }
 
 size_t find(StringPiece self, StringPiece s, size_t pos) {
@@ -77,20 +79,22 @@
   return findT(self, s, pos);
 }
 
-template <typename STR>
-size_t rfindT(BasicStringPiece<STR> self, BasicStringPiece<STR> s, size_t pos) {
+template <typename CharT>
+size_t rfindT(BasicStringPiece<CharT> self,
+              BasicStringPiece<CharT> s,
+              size_t pos) {
   if (self.size() < s.size())
-    return BasicStringPiece<STR>::npos;
+    return BasicStringPiece<CharT>::npos;
 
   if (s.empty())
     return std::min(self.size(), pos);
 
-  typename BasicStringPiece<STR>::const_iterator last =
+  typename BasicStringPiece<CharT>::const_iterator last =
       self.begin() + std::min(self.size() - s.size(), pos) + s.size();
-  typename BasicStringPiece<STR>::const_iterator result =
+  typename BasicStringPiece<CharT>::const_iterator result =
       std::find_end(self.begin(), last, s.begin(), s.end());
-  return result != last ?
-      static_cast<size_t>(result - self.begin()) : BasicStringPiece<STR>::npos;
+  return result != last ? static_cast<size_t>(result - self.begin())
+                        : BasicStringPiece<CharT>::npos;
 }
 
 size_t rfind(StringPiece self, StringPiece s, size_t pos) {
@@ -121,17 +125,17 @@
 }
 
 // Generic brute force version.
-template <typename STR>
-size_t find_first_ofT(BasicStringPiece<STR> self,
-                      BasicStringPiece<STR> s,
+template <typename CharT>
+size_t find_first_ofT(BasicStringPiece<CharT> self,
+                      BasicStringPiece<CharT> s,
                       size_t pos) {
   // Use the faster std::find() if searching for a single character.
-  typename BasicStringPiece<STR>::const_iterator found =
+  typename BasicStringPiece<CharT>::const_iterator found =
       s.size() == 1 ? std::find(self.begin() + pos, self.end(), s[0])
                     : std::find_first_of(self.begin() + pos, self.end(),
                                          s.begin(), s.end());
   if (found == self.end())
-    return BasicStringPiece<STR>::npos;
+    return BasicStringPiece<CharT>::npos;
   return found - self.begin();
 }
 
@@ -162,12 +166,12 @@
 }
 
 // Generic brute-force version.
-template <typename STR>
-size_t find_first_not_ofT(BasicStringPiece<STR> self,
-                          BasicStringPiece<STR> s,
+template <typename CharT>
+size_t find_first_not_ofT(BasicStringPiece<CharT> self,
+                          BasicStringPiece<CharT> s,
                           size_t pos) {
   if (self.size() == 0)
-    return BasicStringPiece<STR>::npos;
+    return BasicStringPiece<CharT>::npos;
 
   for (size_t self_i = pos; self_i < self.size(); ++self_i) {
     bool found = false;
@@ -180,7 +184,7 @@
     if (!found)
       return self_i;
   }
-  return BasicStringPiece<STR>::npos;
+  return BasicStringPiece<CharT>::npos;
 }
 
 size_t find_first_not_of(StringPiece16 self, StringPiece16 s, size_t pos) {
@@ -208,12 +212,12 @@
 }
 
 // Generic brute-force version.
-template <typename STR>
-size_t find_last_ofT(BasicStringPiece<STR> self,
-                     BasicStringPiece<STR> s,
+template <typename CharT>
+size_t find_last_ofT(BasicStringPiece<CharT> self,
+                     BasicStringPiece<CharT> s,
                      size_t pos) {
   if (self.size() == 0)
-    return BasicStringPiece<STR>::npos;
+    return BasicStringPiece<CharT>::npos;
 
   for (size_t self_i = std::min(pos, self.size() - 1); ;
        --self_i) {
@@ -224,7 +228,7 @@
     if (self_i == 0)
       break;
   }
-  return BasicStringPiece<STR>::npos;
+  return BasicStringPiece<CharT>::npos;
 }
 
 size_t find_last_of(StringPiece16 self, StringPiece16 s, size_t pos) {
@@ -256,9 +260,9 @@
 }
 
 // Generic brute-force version.
-template <typename STR>
-size_t find_last_not_ofT(BasicStringPiece<STR> self,
-                         BasicStringPiece<STR> s,
+template <typename CharT>
+size_t find_last_not_ofT(BasicStringPiece<CharT> self,
+                         BasicStringPiece<CharT> s,
                          size_t pos) {
   if (self.size() == 0)
     return StringPiece::npos;
@@ -276,7 +280,7 @@
     if (self_i == 0)
       break;
   }
-  return BasicStringPiece<STR>::npos;
+  return BasicStringPiece<CharT>::npos;
 }
 
 size_t find_last_not_of(StringPiece16 self, StringPiece16 s, size_t pos) {
diff --git a/base/strings/string_piece.h b/base/strings/string_piece.h
index 4923e979..f4f37ad5 100644
--- a/base/strings/string_piece.h
+++ b/base/strings/string_piece.h
@@ -95,20 +95,18 @@
 
 // Defines the types, methods, operators, and data members common to both
 // StringPiece and StringPiece16.
-//
-// This is templatized by string class type rather than character type, so
-// BasicStringPiece<std::string> or BasicStringPiece<std::u16string>.
-template <typename STRING_TYPE> class BasicStringPiece {
+template <typename CharT>
+class BasicStringPiece {
  public:
   // Standard STL container boilerplate.
   typedef size_t size_type;
-  typedef typename STRING_TYPE::traits_type traits_type;
-  typedef typename STRING_TYPE::value_type value_type;
-  typedef const value_type* pointer;
-  typedef const value_type& reference;
-  typedef const value_type& const_reference;
+  typedef std::char_traits<CharT> traits_type;
+  typedef CharT value_type;
+  typedef const CharT* pointer;
+  typedef const CharT& reference;
+  typedef const CharT& const_reference;
   typedef ptrdiff_t difference_type;
-  typedef const value_type* const_iterator;
+  typedef const CharT* const_iterator;
   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
 
   static const size_type npos;
@@ -120,10 +118,10 @@
   constexpr BasicStringPiece() : ptr_(nullptr), length_(0) {}
   // TODO(crbug.com/1049498): Construction from nullptr is not allowed for
   // std::basic_string_view, so remove the special handling for it.
-  // Note: This doesn't just use STRING_TYPE::traits_type::length(), since that
+  // Note: This doesn't just use traits_type::length(), since that
   // isn't constexpr until C++17.
-  constexpr BasicStringPiece(const value_type* str)
-      : ptr_(str), length_(!str ? 0 : CharTraits<value_type>::length(str)) {}
+  constexpr BasicStringPiece(const CharT* str)
+      : ptr_(str), length_(!str ? 0 : CharTraits<CharT>::length(str)) {}
   // Explicitly disallow construction from nullptr. Note that this does not
   // catch construction from runtime strings that might be null.
   // Note: The following is just a more elaborate way of spelling
@@ -137,31 +135,31 @@
                   "StringPiece does not support construction from nullptr, use "
                   "the default constructor instead.");
   }
-  BasicStringPiece(const STRING_TYPE& str)
+  BasicStringPiece(const std::basic_string<CharT>& str)
       : ptr_(str.data()), length_(str.size()) {}
-  constexpr BasicStringPiece(const value_type* offset, size_type len)
+  constexpr BasicStringPiece(const CharT* offset, size_type len)
       : ptr_(offset), length_(len) {}
 
   // data() may return a pointer to a buffer with embedded NULs, and the
   // returned buffer may or may not be null terminated.  Therefore it is
   // typically a mistake to pass data() to a routine that expects a NUL
   // terminated string.
-  constexpr const value_type* data() const { return ptr_; }
+  constexpr const CharT* data() const { return ptr_; }
   constexpr size_type size() const noexcept { return length_; }
   constexpr size_type length() const noexcept { return length_; }
   constexpr bool empty() const noexcept { return length_ == 0; }
 
-  constexpr value_type operator[](size_type i) const {
+  constexpr CharT operator[](size_type i) const {
     CHECK(i < length_);
     return ptr_[i];
   }
 
-  constexpr value_type front() const {
+  constexpr CharT front() const {
     CHECK_NE(0UL, length_);
     return ptr_[0];
   }
 
-  constexpr value_type back() const {
+  constexpr CharT back() const {
     CHECK_NE(0UL, length_);
     return ptr_[length_ - 1];
   }
@@ -178,16 +176,16 @@
   }
 
   // This is the style of conversion preferred by std::string_view in C++17.
-  explicit operator STRING_TYPE() const {
-    return empty() ? STRING_TYPE() : STRING_TYPE(data(), size());
+  explicit operator std::basic_string<CharT>() const {
+    return std::basic_string<CharT>(data(), size());
   }
 
-  // Deprecated, use operator STRING_TYPE() instead.
-  // TODO(crbug.com/1049498): Remove for all STRING_TYPEs.
-  template <typename StrT = STRING_TYPE,
-            typename = std::enable_if_t<std::is_same<StrT, std::string>::value>>
-  STRING_TYPE as_string() const {
-    return STRING_TYPE(*this);
+  // Deprecated, use operator std::basic_string<CharT>() instead.
+  // TODO(crbug.com/1049498): Remove for all CharTs.
+  template <typename ValueT = CharT,
+            typename = std::enable_if_t<std::is_same<ValueT, char>::value>>
+  std::basic_string<CharT> as_string() const {
+    return std::basic_string<CharT>(*this);
   }
 
   constexpr const_iterator begin() const noexcept { return ptr_; }
@@ -203,9 +201,7 @@
   size_type capacity() const { return length_; }
 
   // String operations, see https://wg21.link/string.view.ops.
-  constexpr size_type copy(value_type* s,
-                           size_type n,
-                           size_type pos = 0) const {
+  constexpr size_type copy(CharT* s, size_type n, size_type pos = 0) const {
     CHECK_LE(pos, size());
     size_type rlen = std::min(n, size() - pos);
     traits_type::copy(s, data() + pos, rlen);
@@ -220,7 +216,7 @@
 
   constexpr int compare(BasicStringPiece str) const noexcept {
     size_type rlen = std::min(size(), str.size());
-    int result = CharTraits<value_type>::compare(data(), str.data(), rlen);
+    int result = CharTraits<CharT>::compare(data(), str.data(), rlen);
     if (result == 0)
       result = size() == str.size() ? 0 : (size() < str.size() ? -1 : 1);
     return result;
@@ -240,17 +236,17 @@
     return substr(pos1, n1).compare(str.substr(pos2, n2));
   }
 
-  constexpr int compare(const value_type* s) const {
+  constexpr int compare(const CharT* s) const {
     return compare(BasicStringPiece(s));
   }
 
-  constexpr int compare(size_type pos, size_type n, const value_type* s) const {
+  constexpr int compare(size_type pos, size_type n, const CharT* s) const {
     return substr(pos, n).compare(BasicStringPiece(s));
   }
 
   constexpr int compare(size_type pos,
                         size_type n1,
-                        const value_type* s,
+                        const CharT* s,
                         size_type n2) const {
     return substr(pos, n1).compare(BasicStringPiece(s, n2));
   }
@@ -263,22 +259,20 @@
     return internal::find(*this, s, pos);
   }
 
-  constexpr size_type find(value_type c, size_type pos = 0) const noexcept {
+  constexpr size_type find(CharT c, size_type pos = 0) const noexcept {
     if (pos >= size())
       return npos;
 
-    const value_type* result =
-        base::CharTraits<value_type>::find(data() + pos, size() - pos, c);
+    const CharT* result =
+        base::CharTraits<CharT>::find(data() + pos, size() - pos, c);
     return result ? static_cast<size_type>(result - data()) : npos;
   }
 
-  constexpr size_type find(const value_type* s,
-                           size_type pos,
-                           size_type n) const {
+  constexpr size_type find(const CharT* s, size_type pos, size_type n) const {
     return find(BasicStringPiece(s, n), pos);
   }
 
-  constexpr size_type find(const value_type* s, size_type pos = 0) const {
+  constexpr size_type find(const CharT* s, size_type pos = 0) const {
     return find(BasicStringPiece(s), pos);
   }
 
@@ -288,7 +282,7 @@
     return internal::rfind(*this, s, pos);
   }
 
-  constexpr size_type rfind(value_type c, size_type pos = npos) const noexcept {
+  constexpr size_type rfind(CharT c, size_type pos = npos) const noexcept {
     if (empty())
       return npos;
 
@@ -302,13 +296,11 @@
     return npos;
   }
 
-  constexpr size_type rfind(const value_type* s,
-                            size_type pos,
-                            size_type n) const {
+  constexpr size_type rfind(const CharT* s, size_type pos, size_type n) const {
     return rfind(BasicStringPiece(s, n), pos);
   }
 
-  constexpr size_type rfind(const value_type* s, size_type pos = npos) const {
+  constexpr size_type rfind(const CharT* s, size_type pos = npos) const {
     return rfind(BasicStringPiece(s), pos);
   }
 
@@ -318,19 +310,17 @@
     return internal::find_first_of(*this, s, pos);
   }
 
-  constexpr size_type find_first_of(value_type c,
-                                    size_type pos = 0) const noexcept {
+  constexpr size_type find_first_of(CharT c, size_type pos = 0) const noexcept {
     return find(c, pos);
   }
 
-  constexpr size_type find_first_of(const value_type* s,
+  constexpr size_type find_first_of(const CharT* s,
                                     size_type pos,
                                     size_type n) const {
     return find_first_of(BasicStringPiece(s, n), pos);
   }
 
-  constexpr size_type find_first_of(const value_type* s,
-                                    size_type pos = 0) const {
+  constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const {
     return find_first_of(BasicStringPiece(s), pos);
   }
 
@@ -340,19 +330,18 @@
     return internal::find_last_of(*this, s, pos);
   }
 
-  constexpr size_type find_last_of(value_type c,
+  constexpr size_type find_last_of(CharT c,
                                    size_type pos = npos) const noexcept {
     return rfind(c, pos);
   }
 
-  constexpr size_type find_last_of(const value_type* s,
+  constexpr size_type find_last_of(const CharT* s,
                                    size_type pos,
                                    size_type n) const {
     return find_last_of(BasicStringPiece(s, n), pos);
   }
 
-  constexpr size_type find_last_of(const value_type* s,
-                                   size_type pos = npos) const {
+  constexpr size_type find_last_of(const CharT* s, size_type pos = npos) const {
     return find_last_of(BasicStringPiece(s), pos);
   }
 
@@ -362,7 +351,7 @@
     return internal::find_first_not_of(*this, s, pos);
   }
 
-  constexpr size_type find_first_not_of(value_type c,
+  constexpr size_type find_first_not_of(CharT c,
                                         size_type pos = 0) const noexcept {
     if (empty())
       return npos;
@@ -374,13 +363,13 @@
     return npos;
   }
 
-  constexpr size_type find_first_not_of(const value_type* s,
+  constexpr size_type find_first_not_of(const CharT* s,
                                         size_type pos,
                                         size_type n) const {
     return find_first_not_of(BasicStringPiece(s, n), pos);
   }
 
-  constexpr size_type find_first_not_of(const value_type* s,
+  constexpr size_type find_first_not_of(const CharT* s,
                                         size_type pos = 0) const {
     return find_first_not_of(BasicStringPiece(s), pos);
   }
@@ -391,7 +380,7 @@
     return internal::find_last_not_of(*this, s, pos);
   }
 
-  constexpr size_type find_last_not_of(value_type c,
+  constexpr size_type find_last_not_of(CharT c,
                                        size_type pos = npos) const noexcept {
     if (empty())
       return npos;
@@ -405,38 +394,38 @@
     return npos;
   }
 
-  constexpr size_type find_last_not_of(const value_type* s,
+  constexpr size_type find_last_not_of(const CharT* s,
                                        size_type pos,
                                        size_type n) const {
     return find_last_not_of(BasicStringPiece(s, n), pos);
   }
 
-  constexpr size_type find_last_not_of(const value_type* s,
+  constexpr size_type find_last_not_of(const CharT* s,
                                        size_type pos = npos) const {
     return find_last_not_of(BasicStringPiece(s), pos);
   }
 
  protected:
-  const value_type* ptr_;
+  const CharT* ptr_;
   size_type length_;
 };
 
-template <typename STRING_TYPE>
-const typename BasicStringPiece<STRING_TYPE>::size_type
-BasicStringPiece<STRING_TYPE>::npos =
-    typename BasicStringPiece<STRING_TYPE>::size_type(-1);
+template <typename CharT>
+const typename BasicStringPiece<CharT>::size_type
+    BasicStringPiece<CharT>::npos =
+        typename BasicStringPiece<CharT>::size_type(-1);
 
 // MSVC doesn't like complex extern templates and DLLs.
 #if !defined(COMPILER_MSVC)
-extern template class BASE_EXPORT BasicStringPiece<std::string>;
-extern template class BASE_EXPORT BasicStringPiece<std::u16string>;
+extern template class BASE_EXPORT BasicStringPiece<char>;
+extern template class BASE_EXPORT BasicStringPiece<char16_t>;
 #endif
 
 // Comparison operators --------------------------------------------------------
 // operator ==
-template <typename StringT>
-constexpr bool operator==(BasicStringPiece<StringT> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT>
+constexpr bool operator==(BasicStringPiece<CharT> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return lhs.size() == rhs.size() && lhs.compare(rhs) == 0;
 }
 
@@ -446,116 +435,116 @@
 // https://wg21.link/n3766 for details.
 // Furthermore, we require dummy template parameters for these overloads to work
 // around a name mangling issue on Windows.
-template <typename StringT, int = 1>
+template <typename CharT, int = 1>
 constexpr bool operator==(
-    BasicStringPiece<StringT> lhs,
-    std::common_type_t<BasicStringPiece<StringT>> rhs) noexcept {
+    BasicStringPiece<CharT> lhs,
+    std::common_type_t<BasicStringPiece<CharT>> rhs) noexcept {
   return lhs.size() == rhs.size() && lhs.compare(rhs) == 0;
 }
 
-template <typename StringT, int = 2>
-constexpr bool operator==(std::common_type_t<BasicStringPiece<StringT>> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT, int = 2>
+constexpr bool operator==(std::common_type_t<BasicStringPiece<CharT>> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return lhs.size() == rhs.size() && lhs.compare(rhs) == 0;
 }
 
 // operator !=
-template <typename StringT>
-constexpr bool operator!=(BasicStringPiece<StringT> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT>
+constexpr bool operator!=(BasicStringPiece<CharT> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return !(lhs == rhs);
 }
 
-template <typename StringT, int = 1>
+template <typename CharT, int = 1>
 constexpr bool operator!=(
-    BasicStringPiece<StringT> lhs,
-    std::common_type_t<BasicStringPiece<StringT>> rhs) noexcept {
+    BasicStringPiece<CharT> lhs,
+    std::common_type_t<BasicStringPiece<CharT>> rhs) noexcept {
   return !(lhs == rhs);
 }
 
-template <typename StringT, int = 2>
-constexpr bool operator!=(std::common_type_t<BasicStringPiece<StringT>> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT, int = 2>
+constexpr bool operator!=(std::common_type_t<BasicStringPiece<CharT>> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return !(lhs == rhs);
 }
 
 // operator <
-template <typename StringT>
-constexpr bool operator<(BasicStringPiece<StringT> lhs,
-                         BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT>
+constexpr bool operator<(BasicStringPiece<CharT> lhs,
+                         BasicStringPiece<CharT> rhs) noexcept {
   return lhs.compare(rhs) < 0;
 }
 
-template <typename StringT, int = 1>
+template <typename CharT, int = 1>
 constexpr bool operator<(
-    BasicStringPiece<StringT> lhs,
-    std::common_type_t<BasicStringPiece<StringT>> rhs) noexcept {
+    BasicStringPiece<CharT> lhs,
+    std::common_type_t<BasicStringPiece<CharT>> rhs) noexcept {
   return lhs.compare(rhs) < 0;
 }
 
-template <typename StringT, int = 2>
-constexpr bool operator<(std::common_type_t<BasicStringPiece<StringT>> lhs,
-                         BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT, int = 2>
+constexpr bool operator<(std::common_type_t<BasicStringPiece<CharT>> lhs,
+                         BasicStringPiece<CharT> rhs) noexcept {
   return lhs.compare(rhs) < 0;
 }
 
 // operator >
-template <typename StringT>
-constexpr bool operator>(BasicStringPiece<StringT> lhs,
-                         BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT>
+constexpr bool operator>(BasicStringPiece<CharT> lhs,
+                         BasicStringPiece<CharT> rhs) noexcept {
   return rhs < lhs;
 }
 
-template <typename StringT, int = 1>
+template <typename CharT, int = 1>
 constexpr bool operator>(
-    BasicStringPiece<StringT> lhs,
-    std::common_type_t<BasicStringPiece<StringT>> rhs) noexcept {
+    BasicStringPiece<CharT> lhs,
+    std::common_type_t<BasicStringPiece<CharT>> rhs) noexcept {
   return rhs < lhs;
 }
 
-template <typename StringT, int = 2>
-constexpr bool operator>(std::common_type_t<BasicStringPiece<StringT>> lhs,
-                         BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT, int = 2>
+constexpr bool operator>(std::common_type_t<BasicStringPiece<CharT>> lhs,
+                         BasicStringPiece<CharT> rhs) noexcept {
   return rhs < lhs;
 }
 
 // operator <=
-template <typename StringT>
-constexpr bool operator<=(BasicStringPiece<StringT> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT>
+constexpr bool operator<=(BasicStringPiece<CharT> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return !(rhs < lhs);
 }
 
-template <typename StringT, int = 1>
+template <typename CharT, int = 1>
 constexpr bool operator<=(
-    BasicStringPiece<StringT> lhs,
-    std::common_type_t<BasicStringPiece<StringT>> rhs) noexcept {
+    BasicStringPiece<CharT> lhs,
+    std::common_type_t<BasicStringPiece<CharT>> rhs) noexcept {
   return !(rhs < lhs);
 }
 
-template <typename StringT, int = 2>
-constexpr bool operator<=(std::common_type_t<BasicStringPiece<StringT>> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT, int = 2>
+constexpr bool operator<=(std::common_type_t<BasicStringPiece<CharT>> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return !(rhs < lhs);
 }
 
 // operator >=
-template <typename StringT>
-constexpr bool operator>=(BasicStringPiece<StringT> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT>
+constexpr bool operator>=(BasicStringPiece<CharT> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return !(lhs < rhs);
 }
 
-template <typename StringT, int = 1>
+template <typename CharT, int = 1>
 constexpr bool operator>=(
-    BasicStringPiece<StringT> lhs,
-    std::common_type_t<BasicStringPiece<StringT>> rhs) noexcept {
+    BasicStringPiece<CharT> lhs,
+    std::common_type_t<BasicStringPiece<CharT>> rhs) noexcept {
   return !(lhs < rhs);
 }
 
-template <typename StringT, int = 2>
-constexpr bool operator>=(std::common_type_t<BasicStringPiece<StringT>> lhs,
-                          BasicStringPiece<StringT> rhs) noexcept {
+template <typename CharT, int = 2>
+constexpr bool operator>=(std::common_type_t<BasicStringPiece<CharT>> lhs,
+                          BasicStringPiece<CharT> rhs) noexcept {
   return !(lhs < rhs);
 }
 
diff --git a/base/strings/string_piece_forward.h b/base/strings/string_piece_forward.h
index fe58a578..54dc572 100644
--- a/base/strings/string_piece_forward.h
+++ b/base/strings/string_piece_forward.h
@@ -7,16 +7,13 @@
 #ifndef BASE_STRINGS_STRING_PIECE_FORWARD_H_
 #define BASE_STRINGS_STRING_PIECE_FORWARD_H_
 
-#include <string>
-
-
 namespace base {
 
-template <typename STRING_TYPE>
+template <typename CharT>
 class BasicStringPiece;
-typedef BasicStringPiece<std::string> StringPiece;
-typedef BasicStringPiece<std::u16string> StringPiece16;
-typedef BasicStringPiece<std::wstring> WStringPiece;
+typedef BasicStringPiece<char> StringPiece;
+typedef BasicStringPiece<char16_t> StringPiece16;
+typedef BasicStringPiece<wchar_t> WStringPiece;
 
 }  // namespace base
 
diff --git a/base/strings/string_piece_unittest.cc b/base/strings/string_piece_unittest.cc
index eaf9a38..6f0deaef 100644
--- a/base/strings/string_piece_unittest.cc
+++ b/base/strings/string_piece_unittest.cc
@@ -12,37 +12,35 @@
 
 namespace base {
 
-template <typename T>
+template <typename CharT>
 class CommonStringPieceTest : public ::testing::Test {
  public:
-  static const T as_string(const char* input) {
-    return T(input);
-  }
-  static const T& as_string(const T& input) {
+  static std::string as_string(const char* input) { return input; }
+  static const std::string& as_string(const std::string& input) {
     return input;
   }
 };
 
 template <>
-class CommonStringPieceTest<std::u16string> : public ::testing::Test {
+class CommonStringPieceTest<char16_t> : public ::testing::Test {
  public:
-  static const std::u16string as_string(const char* input) {
-    return ASCIIToUTF16(input);
+  static std::u16string as_string(const char* input) {
+    return UTF8ToUTF16(input);
   }
-  static const std::u16string as_string(const std::string& input) {
-    return ASCIIToUTF16(input);
+  static std::u16string as_string(const std::string& input) {
+    return UTF8ToUTF16(input);
   }
 };
 
-typedef ::testing::Types<std::string, std::u16string> SupportedStringTypes;
+typedef ::testing::Types<char, char16_t> SupportedCharTypes;
 
-TYPED_TEST_SUITE(CommonStringPieceTest, SupportedStringTypes);
+TYPED_TEST_SUITE(CommonStringPieceTest, SupportedCharTypes);
 
 TYPED_TEST(CommonStringPieceTest, CheckComparisonOperators) {
 #define CMP_Y(op, x, y)                                                   \
   {                                                                       \
-    TypeParam lhs(TestFixture::as_string(x));                             \
-    TypeParam rhs(TestFixture::as_string(y));                             \
+    std::basic_string<TypeParam> lhs(TestFixture::as_string(x));          \
+    std::basic_string<TypeParam> rhs(TestFixture::as_string(y));          \
     ASSERT_TRUE((BasicStringPiece<TypeParam>((lhs.c_str()))               \
                      op BasicStringPiece<TypeParam>((rhs.c_str()))));     \
     ASSERT_TRUE(BasicStringPiece<TypeParam>(lhs) op rhs);                 \
@@ -54,8 +52,8 @@
 
 #define CMP_N(op, x, y)                                                    \
   {                                                                        \
-    TypeParam lhs(TestFixture::as_string(x));                              \
-    TypeParam rhs(TestFixture::as_string(y));                              \
+    std::basic_string<TypeParam> lhs(TestFixture::as_string(x));           \
+    std::basic_string<TypeParam> rhs(TestFixture::as_string(y));           \
     ASSERT_FALSE((BasicStringPiece<TypeParam>((lhs.c_str()))               \
                       op BasicStringPiece<TypeParam>((rhs.c_str()))));     \
     ASSERT_FALSE(BasicStringPiece<TypeParam>(lhs) op rhs);                 \
@@ -140,39 +138,39 @@
 }
 
 TYPED_TEST(CommonStringPieceTest, CheckSTL) {
-  TypeParam alphabet(TestFixture::as_string("abcdefghijklmnopqrstuvwxyz"));
-  TypeParam abc(TestFixture::as_string("abc"));
-  TypeParam xyz(TestFixture::as_string("xyz"));
-  TypeParam foobar(TestFixture::as_string("foobar"));
+  std::basic_string<TypeParam> alphabet(
+      TestFixture::as_string("abcdefghijklmnopqrstuvwxyz"));
+  std::basic_string<TypeParam> abc(TestFixture::as_string("abc"));
+  std::basic_string<TypeParam> xyz(TestFixture::as_string("xyz"));
+  std::basic_string<TypeParam> foobar(TestFixture::as_string("foobar"));
 
   BasicStringPiece<TypeParam> a(alphabet);
   BasicStringPiece<TypeParam> b(abc);
   BasicStringPiece<TypeParam> c(xyz);
   BasicStringPiece<TypeParam> d(foobar);
   BasicStringPiece<TypeParam> e;
-  TypeParam temp(TestFixture::as_string("123"));
-  temp += static_cast<typename TypeParam::value_type>(0);
+  std::basic_string<TypeParam> temp(TestFixture::as_string("123"));
+  temp += static_cast<TypeParam>(0);
   temp += TestFixture::as_string("456");
   BasicStringPiece<TypeParam> f(temp);
 
-  ASSERT_EQ(a[6], static_cast<typename TypeParam::value_type>('g'));
-  ASSERT_EQ(b[0], static_cast<typename TypeParam::value_type>('a'));
-  ASSERT_EQ(c[2], static_cast<typename TypeParam::value_type>('z'));
-  ASSERT_EQ(f[3], static_cast<typename TypeParam::value_type>('\0'));
-  ASSERT_EQ(f[5], static_cast<typename TypeParam::value_type>('5'));
+  ASSERT_EQ(a[6], static_cast<TypeParam>('g'));
+  ASSERT_EQ(b[0], static_cast<TypeParam>('a'));
+  ASSERT_EQ(c[2], static_cast<TypeParam>('z'));
+  ASSERT_EQ(f[3], static_cast<TypeParam>('\0'));
+  ASSERT_EQ(f[5], static_cast<TypeParam>('5'));
 
-  ASSERT_EQ(*d.data(), static_cast<typename TypeParam::value_type>('f'));
-  ASSERT_EQ(d.data()[5], static_cast<typename TypeParam::value_type>('r'));
+  ASSERT_EQ(*d.data(), static_cast<TypeParam>('f'));
+  ASSERT_EQ(d.data()[5], static_cast<TypeParam>('r'));
   ASSERT_EQ(e.data(), nullptr);
 
-  ASSERT_EQ(*a.begin(), static_cast<typename TypeParam::value_type>('a'));
-  ASSERT_EQ(*(b.begin() + 2), static_cast<typename TypeParam::value_type>('c'));
-  ASSERT_EQ(*(c.end() - 1), static_cast<typename TypeParam::value_type>('z'));
+  ASSERT_EQ(*a.begin(), static_cast<TypeParam>('a'));
+  ASSERT_EQ(*(b.begin() + 2), static_cast<TypeParam>('c'));
+  ASSERT_EQ(*(c.end() - 1), static_cast<TypeParam>('z'));
 
-  ASSERT_EQ(*a.rbegin(), static_cast<typename TypeParam::value_type>('z'));
-  ASSERT_EQ(*(b.rbegin() + 2),
-            static_cast<typename TypeParam::value_type>('a'));
-  ASSERT_EQ(*(c.rend() - 1), static_cast<typename TypeParam::value_type>('x'));
+  ASSERT_EQ(*a.rbegin(), static_cast<TypeParam>('z'));
+  ASSERT_EQ(*(b.rbegin() + 2), static_cast<TypeParam>('a'));
+  ASSERT_EQ(*(c.rend() - 1), static_cast<TypeParam>('x'));
   ASSERT_EQ(a.rbegin() + 26, a.rend());
 
   ASSERT_EQ(a.size(), 26U);
@@ -202,10 +200,11 @@
 TYPED_TEST(CommonStringPieceTest, CheckFind) {
   typedef BasicStringPiece<TypeParam> Piece;
 
-  TypeParam alphabet(TestFixture::as_string("abcdefghijklmnopqrstuvwxyz"));
-  TypeParam abc(TestFixture::as_string("abc"));
-  TypeParam xyz(TestFixture::as_string("xyz"));
-  TypeParam foobar(TestFixture::as_string("foobar"));
+  std::basic_string<TypeParam> alphabet(
+      TestFixture::as_string("abcdefghijklmnopqrstuvwxyz"));
+  std::basic_string<TypeParam> abc(TestFixture::as_string("abc"));
+  std::basic_string<TypeParam> xyz(TestFixture::as_string("xyz"));
+  std::basic_string<TypeParam> foobar(TestFixture::as_string("foobar"));
 
   BasicStringPiece<TypeParam> a(alphabet);
   BasicStringPiece<TypeParam> b(abc);
@@ -214,12 +213,12 @@
 
   d = Piece();
   Piece e;
-  TypeParam temp(TestFixture::as_string("123"));
+  std::basic_string<TypeParam> temp(TestFixture::as_string("123"));
   temp.push_back('\0');
   temp += TestFixture::as_string("456");
   Piece f(temp);
 
-  typename TypeParam::value_type buf[4] = { '%', '%', '%', '%' };
+  TypeParam buf[4] = {'%', '%', '%', '%'};
   ASSERT_EQ(a.copy(buf, 4), 4U);
   ASSERT_EQ(buf[0], a[0]);
   ASSERT_EQ(buf[1], a[1]);
@@ -236,7 +235,7 @@
   ASSERT_EQ(buf[2], c[2]);
   ASSERT_EQ(buf[3], a[3]);
 
-  ASSERT_EQ(Piece::npos, TypeParam::npos);
+  ASSERT_EQ(Piece::npos, std::basic_string<TypeParam>::npos);
 
   ASSERT_EQ(a.find(b), 0U);
   ASSERT_EQ(a.find(b, 1), Piece::npos);
@@ -249,7 +248,8 @@
   ASSERT_EQ(a.find(e), 0U);
   ASSERT_EQ(a.find(d, 12), 12U);
   ASSERT_EQ(a.find(e, 17), 17U);
-  TypeParam not_found(TestFixture::as_string("xx not found bb"));
+  std::basic_string<TypeParam> not_found(
+      TestFixture::as_string("xx not found bb"));
   Piece g(not_found);
   ASSERT_EQ(a.find(g), Piece::npos);
   // empty string nonsense
@@ -258,7 +258,8 @@
   ASSERT_EQ(d.find(b, 4), Piece::npos);
   ASSERT_EQ(e.find(b, 7), Piece::npos);
 
-  size_t empty_search_pos = TypeParam().find(TypeParam());
+  size_t empty_search_pos =
+      std::basic_string<TypeParam>().find(std::basic_string<TypeParam>());
   ASSERT_EQ(d.find(d), empty_search_pos);
   ASSERT_EQ(d.find(e), empty_search_pos);
   ASSERT_EQ(e.find(d), empty_search_pos);
@@ -268,7 +269,7 @@
   ASSERT_EQ(e.find(d, 4), std::string().find(std::string(), 4));
   ASSERT_EQ(e.find(e, 4), std::string().find(std::string(), 4));
 
-  constexpr typename TypeParam::value_type kNul = '\0';
+  constexpr TypeParam kNul = '\0';
   ASSERT_EQ(a.find('a'), 0U);
   ASSERT_EQ(a.find('c'), 2U);
   ASSERT_EQ(a.find('z'), 25U);
@@ -328,10 +329,14 @@
   ASSERT_EQ(a.rfind(c, 0U), Piece::npos);
   ASSERT_EQ(b.rfind(c), Piece::npos);
   ASSERT_EQ(b.rfind(c, 0U), Piece::npos);
-  ASSERT_EQ(a.rfind(d), static_cast<size_t>(a.rfind(TypeParam())));
-  ASSERT_EQ(a.rfind(e), a.rfind(TypeParam()));
-  ASSERT_EQ(a.rfind(d), static_cast<size_t>(TypeParam(a).rfind(TypeParam())));
-  ASSERT_EQ(a.rfind(e), TypeParam(a).rfind(TypeParam()));
+  ASSERT_EQ(a.rfind(d),
+            static_cast<size_t>(a.rfind(std::basic_string<TypeParam>())));
+  ASSERT_EQ(a.rfind(e), a.rfind(std::basic_string<TypeParam>()));
+  ASSERT_EQ(a.rfind(d),
+            static_cast<size_t>(std::basic_string<TypeParam>(a).rfind(
+                std::basic_string<TypeParam>())));
+  ASSERT_EQ(a.rfind(e), std::basic_string<TypeParam>(a).rfind(
+                            std::basic_string<TypeParam>()));
   ASSERT_EQ(a.rfind(d, 12), 12U);
   ASSERT_EQ(a.rfind(e, 17), 17U);
   ASSERT_EQ(a.rfind(g), Piece::npos);
@@ -380,8 +385,9 @@
   ASSERT_EQ(d.rfind(e.data(), 4), std::string().rfind(std::string()));
   ASSERT_EQ(e.rfind(e.data(), 7), std::string().rfind(std::string()));
 
-  TypeParam one_two_three_four(TestFixture::as_string("one,two:three;four"));
-  TypeParam comma_colon(TestFixture::as_string(",:"));
+  std::basic_string<TypeParam> one_two_three_four(
+      TestFixture::as_string("one,two:three;four"));
+  std::basic_string<TypeParam> comma_colon(TestFixture::as_string(",:"));
   ASSERT_EQ(3U, Piece(one_two_three_four).find_first_of(comma_colon));
   ASSERT_EQ(a.find_first_of(b), 0U);
   ASSERT_EQ(a.find_first_of(b, 0), 0U);
@@ -423,7 +429,7 @@
   ASSERT_EQ(d.find_first_not_of(e), Piece::npos);
   ASSERT_EQ(e.find_first_not_of(e), Piece::npos);
 
-  TypeParam equals(TestFixture::as_string("===="));
+  std::basic_string<TypeParam> equals(TestFixture::as_string("===="));
   Piece h(equals);
   ASSERT_EQ(h.find_first_not_of('='), Piece::npos);
   ASSERT_EQ(h.find_first_not_of('=', 3), Piece::npos);
@@ -439,7 +445,7 @@
   ASSERT_EQ(e.find_first_not_of(kNul), Piece::npos);
 
   //  Piece g("xx not found bb");
-  TypeParam fifty_six(TestFixture::as_string("56"));
+  std::basic_string<TypeParam> fifty_six(TestFixture::as_string("56"));
   Piece i(fifty_six);
   ASSERT_EQ(h.find_last_of(a), Piece::npos);
   ASSERT_EQ(g.find_last_of(a), g.size()-1);
@@ -524,14 +530,14 @@
 }
 
 TYPED_TEST(CommonStringPieceTest, CheckCustom) {
-  TypeParam foobar(TestFixture::as_string("foobar"));
+  std::basic_string<TypeParam> foobar(TestFixture::as_string("foobar"));
   BasicStringPiece<TypeParam> a(foobar);
-  TypeParam s1(TestFixture::as_string("123"));
-  s1 += static_cast<typename TypeParam::value_type>('\0');
+  std::basic_string<TypeParam> s1(TestFixture::as_string("123"));
+  s1 += static_cast<TypeParam>('\0');
   s1 += TestFixture::as_string("456");
   BasicStringPiece<TypeParam> b(s1);
   BasicStringPiece<TypeParam> e;
-  TypeParam s2;
+  std::basic_string<TypeParam> s2;
 
   // remove_prefix
   BasicStringPiece<TypeParam> c(a);
@@ -564,9 +570,10 @@
   ASSERT_NE(c, a);
 
   // operator STRING_TYPE()
-  TypeParam s5(TypeParam(a).c_str(), 7);  // Note, has an embedded NULL
+  std::basic_string<TypeParam> s5(std::basic_string<TypeParam>(a).c_str(),
+                                  7);  // Note, has an embedded NULL
   ASSERT_EQ(c, s5);
-  TypeParam s6(e);
+  std::basic_string<TypeParam> s6(e);
   ASSERT_TRUE(s6.empty());
 }
 
@@ -593,15 +600,18 @@
   ASSERT_EQ(s.data(), nullptr);
   ASSERT_EQ(s.size(), 0U);
 
-  TypeParam str(s);
+  std::basic_string<TypeParam> str(s);
   ASSERT_EQ(str.length(), 0U);
-  ASSERT_EQ(str, TypeParam());
+  ASSERT_EQ(str, std::basic_string<TypeParam>());
 }
 
 TYPED_TEST(CommonStringPieceTest, CheckComparisons2) {
-  TypeParam alphabet(TestFixture::as_string("abcdefghijklmnopqrstuvwxyz"));
-  TypeParam alphabet_z(TestFixture::as_string("abcdefghijklmnopqrstuvwxyzz"));
-  TypeParam alphabet_y(TestFixture::as_string("abcdefghijklmnopqrstuvwxyy"));
+  std::basic_string<TypeParam> alphabet(
+      TestFixture::as_string("abcdefghijklmnopqrstuvwxyz"));
+  std::basic_string<TypeParam> alphabet_z(
+      TestFixture::as_string("abcdefghijklmnopqrstuvwxyzz"));
+  std::basic_string<TypeParam> alphabet_y(
+      TestFixture::as_string("abcdefghijklmnopqrstuvwxyy"));
   BasicStringPiece<TypeParam> abc(alphabet);
 
   // check comparison operations on strings longer than 4 bytes.
@@ -623,7 +633,7 @@
 }
 
 TYPED_TEST(CommonStringPieceTest, HeterogenousStringPieceEquals) {
-  TypeParam hello(TestFixture::as_string("hello"));
+  std::basic_string<TypeParam> hello(TestFixture::as_string("hello"));
 
   ASSERT_EQ(BasicStringPiece<TypeParam>(hello), hello);
   ASSERT_EQ(hello.c_str(), BasicStringPiece<TypeParam>(hello));
@@ -653,8 +663,8 @@
 }
 
 TYPED_TEST(CommonStringPieceTest, CheckConstructors) {
-  TypeParam str(TestFixture::as_string("hello world"));
-  TypeParam empty;
+  std::basic_string<TypeParam> str(TestFixture::as_string("hello world"));
+  std::basic_string<TypeParam> empty;
 
   ASSERT_EQ(str, BasicStringPiece<TypeParam>(str));
   ASSERT_EQ(str, BasicStringPiece<TypeParam>(str.c_str()));
diff --git a/base/strings/string_split_internal.h b/base/strings/string_split_internal.h
index 2eff3de..d5bf462 100644
--- a/base/strings/string_split_internal.h
+++ b/base/strings/string_split_internal.h
@@ -15,24 +15,24 @@
 namespace internal {
 
 // Returns either the ASCII or UTF-16 whitespace.
-template <typename Str>
-BasicStringPiece<Str> WhitespaceForType();
+template <typename CharT>
+BasicStringPiece<CharT> WhitespaceForType();
 
 template <>
-inline StringPiece16 WhitespaceForType<std::u16string>() {
+inline StringPiece16 WhitespaceForType<char16_t>() {
   return kWhitespaceUTF16;
 }
 template <>
-inline StringPiece WhitespaceForType<std::string>() {
+inline StringPiece WhitespaceForType<char>() {
   return kWhitespaceASCII;
 }
 
 // General string splitter template. Can take 8- or 16-bit input, can produce
 // the corresponding string or StringPiece output.
-template <typename OutputStringType, typename Str>
+template <typename OutputStringType, typename CharT>
 static std::vector<OutputStringType> SplitStringT(
-    BasicStringPiece<Str> str,
-    BasicStringPiece<Str> delimiter,
+    BasicStringPiece<CharT> str,
+    BasicStringPiece<CharT> delimiter,
     WhitespaceHandling whitespace,
     SplitResult result_type) {
   std::vector<OutputStringType> result;
@@ -40,20 +40,20 @@
     return result;
 
   size_t start = 0;
-  while (start != Str::npos) {
+  while (start != std::basic_string<CharT>::npos) {
     size_t end = str.find_first_of(delimiter, start);
 
-    BasicStringPiece<Str> piece;
-    if (end == Str::npos) {
+    BasicStringPiece<CharT> piece;
+    if (end == std::basic_string<CharT>::npos) {
       piece = str.substr(start);
-      start = Str::npos;
+      start = std::basic_string<CharT>::npos;
     } else {
       piece = str.substr(start, end - start);
       start = end + 1;
     }
 
     if (whitespace == TRIM_WHITESPACE)
-      piece = TrimString(piece, WhitespaceForType<Str>(), TRIM_ALL);
+      piece = TrimString(piece, WhitespaceForType<CharT>(), TRIM_ALL);
 
     if (result_type == SPLIT_WANT_ALL || !piece.empty())
       result.emplace_back(piece);
@@ -61,13 +61,13 @@
   return result;
 }
 
-template <typename OutputStringType, typename Str>
+template <typename OutputStringType, typename CharT>
 std::vector<OutputStringType> SplitStringUsingSubstrT(
-    BasicStringPiece<Str> input,
-    BasicStringPiece<Str> delimiter,
+    BasicStringPiece<CharT> input,
+    BasicStringPiece<CharT> delimiter,
     WhitespaceHandling whitespace,
     SplitResult result_type) {
-  using Piece = BasicStringPiece<Str>;
+  using Piece = BasicStringPiece<CharT>;
   using size_type = typename Piece::size_type;
 
   std::vector<OutputStringType> result;
@@ -84,7 +84,7 @@
                      : input.substr(begin_index, end_index - begin_index);
 
     if (whitespace == TRIM_WHITESPACE)
-      term = TrimString(term, WhitespaceForType<Str>(), TRIM_ALL);
+      term = TrimString(term, WhitespaceForType<CharT>(), TRIM_ALL);
 
     if (result_type == SPLIT_WANT_ALL || !term.empty())
       result.emplace_back(term);
diff --git a/base/strings/string_split_win.cc b/base/strings/string_split_win.cc
index ec06b42..2820842 100644
--- a/base/strings/string_split_win.cc
+++ b/base/strings/string_split_win.cc
@@ -15,7 +15,7 @@
 namespace internal {
 
 template <>
-inline WStringPiece WhitespaceForType<std::wstring>() {
+inline WStringPiece WhitespaceForType<wchar_t>() {
   return kWhitespaceWide;
 }
 
diff --git a/base/strings/string_tokenizer.h b/base/strings/string_tokenizer.h
index 9b1d42b..9e6f3bd3 100644
--- a/base/strings/string_tokenizer.h
+++ b/base/strings/string_tokenizer.h
@@ -190,9 +190,8 @@
   const_iterator token_begin() const { return token_begin_; }
   const_iterator token_end() const { return token_end_; }
   str token() const { return str(token_begin_, token_end_); }
-  BasicStringPiece<str> token_piece() const {
-    return BasicStringPiece<str>(&*token_begin_,
-                                 std::distance(token_begin_, token_end_));
+  BasicStringPiece<char_type> token_piece() const {
+    return MakeBasicStringPiece<char_type>(token_begin_, token_end_);
   }
 
  private:
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
index f6d9aaf..fe6e78f9 100644
--- a/base/strings/string_util.cc
+++ b/base/strings/string_util.cc
@@ -358,7 +358,7 @@
                                       StringPiece16 find_this,
                                       StringPiece16 replace_with) {
   internal::DoReplaceMatchesAfterOffset(
-      str, start_offset, internal::SubstringMatcher<std::u16string>{find_this},
+      str, start_offset, internal::MakeSubstringMatcher(find_this),
       replace_with, internal::ReplaceType::REPLACE_FIRST);
 }
 
@@ -367,7 +367,7 @@
                                       StringPiece find_this,
                                       StringPiece replace_with) {
   internal::DoReplaceMatchesAfterOffset(
-      str, start_offset, internal::SubstringMatcher<std::string>{find_this},
+      str, start_offset, internal::MakeSubstringMatcher(find_this),
       replace_with, internal::ReplaceType::REPLACE_FIRST);
 }
 
@@ -376,7 +376,7 @@
                                   StringPiece16 find_this,
                                   StringPiece16 replace_with) {
   internal::DoReplaceMatchesAfterOffset(
-      str, start_offset, internal::SubstringMatcher<std::u16string>{find_this},
+      str, start_offset, internal::MakeSubstringMatcher(find_this),
       replace_with, internal::ReplaceType::REPLACE_ALL);
 }
 
@@ -385,7 +385,7 @@
                                   StringPiece find_this,
                                   StringPiece replace_with) {
   internal::DoReplaceMatchesAfterOffset(
-      str, start_offset, internal::SubstringMatcher<std::string>{find_this},
+      str, start_offset, internal::MakeSubstringMatcher(find_this),
       replace_with, internal::ReplaceType::REPLACE_ALL);
 }
 
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index fe791d8..ab8d4fd 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -85,8 +85,8 @@
 
 // Simplified implementation of C++20's std::basic_string_view(It, End).
 // Reference: https://wg21.link/string.view.cons
-template <typename StringT, typename Iter>
-constexpr BasicStringPiece<StringT> MakeBasicStringPiece(Iter begin, Iter end) {
+template <typename CharT, typename Iter>
+constexpr BasicStringPiece<CharT> MakeBasicStringPiece(Iter begin, Iter end) {
   DCHECK_GE(end - begin, 0);
   return {base::to_address(begin), static_cast<size_t>(end - begin)};
 }
@@ -95,17 +95,17 @@
 // aliases defined in base/strings/string_piece_forward.h
 template <typename Iter>
 constexpr StringPiece MakeStringPiece(Iter begin, Iter end) {
-  return MakeBasicStringPiece<std::string>(begin, end);
+  return MakeBasicStringPiece<char>(begin, end);
 }
 
 template <typename Iter>
 constexpr StringPiece16 MakeStringPiece16(Iter begin, Iter end) {
-  return MakeBasicStringPiece<std::u16string>(begin, end);
+  return MakeBasicStringPiece<char16_t>(begin, end);
 }
 
 template <typename Iter>
 constexpr WStringPiece MakeWStringPiece(Iter begin, Iter end) {
-  return MakeBasicStringPiece<std::wstring>(begin, end);
+  return MakeBasicStringPiece<wchar_t>(begin, end);
 }
 
 // ASCII-specific tolower.  The standard library's tolower is locale sensitive,
diff --git a/base/strings/string_util_internal.h b/base/strings/string_util_internal.h
index 9385160..3c64603 100644
--- a/base/strings/string_util_internal.h
+++ b/base/strings/string_util_internal.h
@@ -43,34 +43,34 @@
   return !(reinterpret_cast<MachineWord>(pointer) & (sizeof(MachineWord) - 1));
 }
 
-template <typename StringType>
-StringType ToLowerASCIIImpl(BasicStringPiece<StringType> str) {
-  StringType ret;
+template <typename CharT>
+std::basic_string<CharT> ToLowerASCIIImpl(BasicStringPiece<CharT> str) {
+  std::basic_string<CharT> ret;
   ret.reserve(str.size());
   for (size_t i = 0; i < str.size(); i++)
     ret.push_back(ToLowerASCII(str[i]));
   return ret;
 }
 
-template <typename StringType>
-StringType ToUpperASCIIImpl(BasicStringPiece<StringType> str) {
-  StringType ret;
+template <typename CharT>
+std::basic_string<CharT> ToUpperASCIIImpl(BasicStringPiece<CharT> str) {
+  std::basic_string<CharT> ret;
   ret.reserve(str.size());
   for (size_t i = 0; i < str.size(); i++)
     ret.push_back(ToUpperASCII(str[i]));
   return ret;
 }
 
-template <class StringType>
-int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a,
-                                 BasicStringPiece<StringType> b) {
+template <class CharT>
+int CompareCaseInsensitiveASCIIT(BasicStringPiece<CharT> a,
+                                 BasicStringPiece<CharT> b) {
   // Find the first characters that aren't equal and compare them.  If the end
   // of one of the strings is found before a nonequal character, the lengths
   // of the strings are compared.
   size_t i = 0;
   while (i < a.length() && i < b.length()) {
-    typename StringType::value_type lower_a = ToLowerASCII(a[i]);
-    typename StringType::value_type lower_b = ToLowerASCII(b[i]);
+    CharT lower_a = ToLowerASCII(a[i]);
+    CharT lower_b = ToLowerASCII(b[i]);
     if (lower_a < lower_b)
       return -1;
     if (lower_a > lower_b)
@@ -88,11 +88,11 @@
   return 1;
 }
 
-template <typename Str>
-TrimPositions TrimStringT(BasicStringPiece<Str> input,
-                          BasicStringPiece<Str> trim_chars,
+template <typename CharT>
+TrimPositions TrimStringT(BasicStringPiece<CharT> input,
+                          BasicStringPiece<CharT> trim_chars,
                           TrimPositions positions,
-                          Str* output) {
+                          std::basic_string<CharT>* output) {
   // Find the edges of leading/trailing whitespace as desired. Need to use
   // a StringPiece version of input to be able to call find* on it with the
   // StringPiece version of trim_chars (normally the trim_chars will be a
@@ -107,8 +107,8 @@
   // When the string was all trimmed, report that we stripped off characters
   // from whichever position the caller was interested in. For empty input, we
   // stripped no characters, but we still need to clear |output|.
-  if (input.empty() || first_good_char == Str::npos ||
-      last_good_char == Str::npos) {
+  if (input.empty() || first_good_char == std::basic_string<CharT>::npos ||
+      last_good_char == std::basic_string<CharT>::npos) {
     bool input_was_empty = input.empty();  // in case output == &input
     output->clear();
     return input_was_empty ? TRIM_NONE : positions;
@@ -124,10 +124,10 @@
       (last_good_char == last_char ? TRIM_NONE : TRIM_TRAILING));
 }
 
-template <typename Str>
-BasicStringPiece<Str> TrimStringPieceT(BasicStringPiece<Str> input,
-                                       BasicStringPiece<Str> trim_chars,
-                                       TrimPositions positions) {
+template <typename CharT>
+BasicStringPiece<CharT> TrimStringPieceT(BasicStringPiece<CharT> input,
+                                         BasicStringPiece<CharT> trim_chars,
+                                         TrimPositions positions) {
   size_t begin =
       (positions & TRIM_LEADING) ? input.find_first_not_of(trim_chars) : 0;
   size_t end = (positions & TRIM_TRAILING)
@@ -136,10 +136,11 @@
   return input.substr(std::min(begin, input.size()), end - begin);
 }
 
-template <typename STR>
-STR CollapseWhitespaceT(BasicStringPiece<STR> text,
-                        bool trim_sequences_with_line_breaks) {
-  STR result;
+template <typename CharT>
+std::basic_string<CharT> CollapseWhitespaceT(
+    BasicStringPiece<CharT> text,
+    bool trim_sequences_with_line_breaks) {
+  std::basic_string<CharT> result;
   result.resize(text.size());
 
   // Set flags to pretend we're already in a trimmed whitespace sequence, so we
@@ -257,31 +258,30 @@
 // The hardcoded strings are typically very short so it doesn't matter, and the
 // string piece gives additional flexibility for the caller (doesn't have to be
 // null terminated) so we choose the StringPiece route.
-template <typename Str>
-inline bool DoLowerCaseEqualsASCII(BasicStringPiece<Str> str,
+template <typename CharT>
+inline bool DoLowerCaseEqualsASCII(BasicStringPiece<CharT> str,
                                    StringPiece lowercase_ascii) {
   return std::equal(
       str.begin(), str.end(), lowercase_ascii.begin(), lowercase_ascii.end(),
       [](auto lhs, auto rhs) { return ToLowerASCII(lhs) == rhs; });
 }
 
-template <typename Str>
-bool StartsWithT(BasicStringPiece<Str> str,
-                 BasicStringPiece<Str> search_for,
+template <typename CharT>
+bool StartsWithT(BasicStringPiece<CharT> str,
+                 BasicStringPiece<CharT> search_for,
                  CompareCase case_sensitivity) {
   if (search_for.size() > str.size())
     return false;
 
-  BasicStringPiece<Str> source = str.substr(0, search_for.size());
+  BasicStringPiece<CharT> source = str.substr(0, search_for.size());
 
   switch (case_sensitivity) {
     case CompareCase::SENSITIVE:
       return source == search_for;
 
     case CompareCase::INSENSITIVE_ASCII:
-      return std::equal(
-          search_for.begin(), search_for.end(), source.begin(),
-          CaseInsensitiveCompareASCII<typename Str::value_type>());
+      return std::equal(search_for.begin(), search_for.end(), source.begin(),
+                        CaseInsensitiveCompareASCII<CharT>());
 
     default:
       NOTREACHED();
@@ -289,14 +289,14 @@
   }
 }
 
-template <typename Str>
-bool EndsWithT(BasicStringPiece<Str> str,
-               BasicStringPiece<Str> search_for,
+template <typename CharT>
+bool EndsWithT(BasicStringPiece<CharT> str,
+               BasicStringPiece<CharT> search_for,
                CompareCase case_sensitivity) {
   if (search_for.size() > str.size())
     return false;
 
-  BasicStringPiece<Str> source =
+  BasicStringPiece<CharT> source =
       str.substr(str.size() - search_for.size(), search_for.size());
 
   switch (case_sensitivity) {
@@ -304,9 +304,8 @@
       return source == search_for;
 
     case CompareCase::INSENSITIVE_ASCII:
-      return std::equal(
-          source.begin(), source.end(), search_for.begin(),
-          CaseInsensitiveCompareASCII<typename Str::value_type>());
+      return std::equal(source.begin(), source.end(), search_for.begin(),
+                        CaseInsensitiveCompareASCII<CharT>());
 
     default:
       NOTREACHED();
@@ -315,28 +314,40 @@
 }
 
 // A Matcher for DoReplaceMatchesAfterOffset() that matches substrings.
-template <class StringType>
+template <class CharT>
 struct SubstringMatcher {
-  BasicStringPiece<StringType> find_this;
+  BasicStringPiece<CharT> find_this;
 
-  size_t Find(const StringType& input, size_t pos) {
+  size_t Find(const std::basic_string<CharT>& input, size_t pos) {
     return input.find(find_this.data(), pos, find_this.length());
   }
   size_t MatchSize() { return find_this.length(); }
 };
 
-// A Matcher for DoReplaceMatchesAfterOffset() that matches single characters.
-template <class StringType>
-struct CharacterMatcher {
-  BasicStringPiece<StringType> find_any_of_these;
+// Type deduction helper for SubstringMatcher.
+template <class CharT>
+auto MakeSubstringMatcher(BasicStringPiece<CharT> find_this) {
+  return SubstringMatcher<CharT>{find_this};
+}
 
-  size_t Find(const StringType& input, size_t pos) {
+// A Matcher for DoReplaceMatchesAfterOffset() that matches single characters.
+template <class CharT>
+struct CharacterMatcher {
+  BasicStringPiece<CharT> find_any_of_these;
+
+  size_t Find(const std::basic_string<CharT>& input, size_t pos) {
     return input.find_first_of(find_any_of_these.data(), pos,
                                find_any_of_these.length());
   }
   constexpr size_t MatchSize() { return 1; }
 };
 
+// Type deduction helper for CharacterMatcher.
+template <class CharT>
+auto MakeCharacterMatcher(BasicStringPiece<CharT> find_any_of_these) {
+  return CharacterMatcher<CharT>{find_any_of_these};
+}
+
 enum class ReplaceType { REPLACE_ALL, REPLACE_FIRST };
 
 // Runs in O(n) time in the length of |str|, and transforms the string without
@@ -344,13 +355,13 @@
 //
 // This is parameterized on a |Matcher| traits type, so that it can be the
 // implementation for both ReplaceChars() and ReplaceSubstringsAfterOffset().
-template <class StringType, class Matcher>
-bool DoReplaceMatchesAfterOffset(StringType* str,
+template <class CharT, class Matcher>
+bool DoReplaceMatchesAfterOffset(std::basic_string<CharT>* str,
                                  size_t initial_offset,
                                  Matcher matcher,
-                                 BasicStringPiece<StringType> replace_with,
+                                 BasicStringPiece<CharT> replace_with,
                                  ReplaceType replace_type) {
-  using CharTraits = typename StringType::traits_type;
+  using CharTraits = std::char_traits<CharT>;
 
   const size_t find_length = matcher.MatchSize();
   if (!find_length)
@@ -358,7 +369,7 @@
 
   // If the find string doesn't appear, there's nothing to do.
   size_t first_match = matcher.Find(*str, initial_offset);
-  if (first_match == StringType::npos)
+  if (first_match == std::basic_string<CharT>::npos)
     return false;
 
   // If we're only replacing one instance, there's no need to do anything
@@ -373,7 +384,7 @@
   // replace() on each instance, and finish the entire operation in O(n) time.
   if (find_length == replace_length) {
     auto* buffer = &((*str)[0]);
-    for (size_t offset = first_match; offset != StringType::npos;
+    for (size_t offset = first_match; offset != std::basic_string<CharT>::npos;
          offset = matcher.Find(*str, offset + replace_length)) {
       CharTraits::copy(buffer + offset, replace_with.data(), replace_length);
     }
@@ -403,7 +414,7 @@
     // matches.
     const size_t expansion_per_match = (replace_length - find_length);
     size_t num_matches = 0;
-    for (size_t match = first_match; match != StringType::npos;
+    for (size_t match = first_match; match != std::basic_string<CharT>::npos;
          match = matcher.Find(*str, match + find_length)) {
       expansion += expansion_per_match;
       ++num_matches;
@@ -413,7 +424,7 @@
     if (str->capacity() < final_length) {
       // If we'd have to allocate a new buffer to grow the string, build the
       // result directly into the new allocation via append().
-      StringType src(str->get_allocator());
+      std::basic_string<CharT> src(str->get_allocator());
       str->swap(src);
       str->reserve(final_length);
 
@@ -471,7 +482,8 @@
     }
     read_offset += find_length;
 
-    // min() clamps StringType::npos (the largest unsigned value) to str_length.
+    // min() clamps std::basic_string<CharT>::npos (the largest unsigned value)
+    // to str_length.
     size_t match = std::min(matcher.Find(*str, read_offset), str_length);
 
     size_t length = match - read_offset;
@@ -487,19 +499,19 @@
   return true;
 }
 
-template <class StringType>
-bool ReplaceCharsT(BasicStringPiece<StringType> input,
-                   BasicStringPiece<StringType> find_any_of_these,
-                   BasicStringPiece<StringType> replace_with,
-                   StringType* output) {
+template <class CharT>
+bool ReplaceCharsT(BasicStringPiece<CharT> input,
+                   BasicStringPiece<CharT> find_any_of_these,
+                   BasicStringPiece<CharT> replace_with,
+                   std::basic_string<CharT>* output) {
   // Commonly, this is called with output and input being the same string; in
   // that case, skip the copy.
   if (input.data() != output->data() || input.size() != output->size())
     output->assign(input.data(), input.size());
 
-  return DoReplaceMatchesAfterOffset(
-      output, 0, CharacterMatcher<StringType>{find_any_of_these}, replace_with,
-      ReplaceType::REPLACE_ALL);
+  return DoReplaceMatchesAfterOffset(output, 0,
+                                     MakeCharacterMatcher(find_any_of_these),
+                                     replace_with, ReplaceType::REPLACE_ALL);
 }
 
 template <class string_type>
@@ -513,20 +525,20 @@
 
 // Generic version for all JoinString overloads. |list_type| must be a sequence
 // (base::span or std::initializer_list) of strings/StringPieces (std::string,
-// std::u16string, StringPiece or StringPiece16). |string_type| is either
-// std::string or std::u16string.
-template <typename list_type, typename string_type>
-static string_type JoinStringT(list_type parts,
-                               BasicStringPiece<string_type> sep) {
+// std::u16string, StringPiece or StringPiece16). |CharT| is either char or
+// char16_t.
+template <typename list_type, typename CharT>
+static std::basic_string<CharT> JoinStringT(list_type parts,
+                                            BasicStringPiece<CharT> sep) {
   if (base::empty(parts))
-    return string_type();
+    return std::basic_string<CharT>();
 
   // Pre-allocate the eventual size of the string. Start with the size of all of
   // the separators (note that this *assumes* parts.size() > 0).
   size_t total_size = (parts.size() - 1) * sep.size();
   for (const auto& part : parts)
     total_size += part.size();
-  string_type result;
+  std::basic_string<CharT> result;
   result.reserve(total_size);
 
   auto iter = parts.begin();
@@ -545,10 +557,10 @@
   return result;
 }
 
-template <class StringType>
-StringType DoReplaceStringPlaceholders(
-    BasicStringPiece<StringType> format_string,
-    const std::vector<StringType>& subst,
+template <class CharT>
+std::basic_string<CharT> DoReplaceStringPlaceholders(
+    BasicStringPiece<CharT> format_string,
+    const std::vector<std::basic_string<CharT>>& subst,
     std::vector<size_t>* offsets) {
   size_t substitutions = subst.size();
   DCHECK_LT(substitutions, 10U);
@@ -557,7 +569,7 @@
   for (const auto& cur : subst)
     sub_length += cur.length();
 
-  StringType formatted;
+  std::basic_string<CharT> formatted;
   formatted.reserve(format_string.length() + sub_length);
 
   std::vector<ReplacementOffset> r_offsets;
diff --git a/base/strings/string_util_win.cc b/base/strings/string_util_win.cc
index 3c2da65..72a0403c 100644
--- a/base/strings/string_util_win.cc
+++ b/base/strings/string_util_win.cc
@@ -101,7 +101,7 @@
                                       WStringPiece find_this,
                                       WStringPiece replace_with) {
   internal::DoReplaceMatchesAfterOffset(
-      str, start_offset, internal::SubstringMatcher<std::wstring>{find_this},
+      str, start_offset, internal::MakeSubstringMatcher(find_this),
       replace_with, internal::ReplaceType::REPLACE_FIRST);
 }
 
@@ -110,7 +110,7 @@
                                   WStringPiece find_this,
                                   WStringPiece replace_with) {
   internal::DoReplaceMatchesAfterOffset(
-      str, start_offset, internal::SubstringMatcher<std::wstring>{find_this},
+      str, start_offset, internal::MakeSubstringMatcher(find_this),
       replace_with, internal::ReplaceType::REPLACE_ALL);
 }
 
diff --git a/base/strings/sys_string_conversions_mac.mm b/base/strings/sys_string_conversions_mac.mm
index 5fb45f6..f8d0f4ba 100644
--- a/base/strings/sys_string_conversions_mac.mm
+++ b/base/strings/sys_string_conversions_mac.mm
@@ -95,9 +95,9 @@
 
 // Given a StringPiece |in| with an encoding specified by |in_encoding|, return
 // it as a CFStringRef.  Returns NULL on failure.
-template <typename StringType>
+template <typename CharT>
 static ScopedCFTypeRef<CFStringRef> StringPieceToCFStringWithEncodingsT(
-    BasicStringPiece<StringType> in,
+    BasicStringPiece<CharT> in,
     CFStringEncoding in_encoding) {
   const auto in_length = in.length();
   if (in_length == 0)
@@ -105,8 +105,7 @@
 
   return ScopedCFTypeRef<CFStringRef>(CFStringCreateWithBytes(
       kCFAllocatorDefault, reinterpret_cast<const UInt8*>(in.data()),
-      in_length * sizeof(typename BasicStringPiece<StringType>::value_type),
-      in_encoding, false));
+      in_length * sizeof(CharT), in_encoding, false));
 }
 
 // Specify the byte ordering explicitly, otherwise CFString will be confused
diff --git a/chrome/updater/tag.cc b/chrome/updater/tag.cc
index 0a0d5940..25aca505 100644
--- a/chrome/updater/tag.cc
+++ b/chrome/updater/tag.cc
@@ -109,7 +109,7 @@
 }
 
 // A custom comparator functor class for the parse tables.
-using ParseTableCompare = CaseInsensitiveASCIICompare<std::string>;
+using ParseTableCompare = CaseInsensitiveASCIICompare;
 
 namespace global_attributes {
 
diff --git a/chrome/updater/util.h b/chrome/updater/util.h
index 619f2b8..2d0cc2f 100644
--- a/chrome/updater/util.h
+++ b/chrome/updater/util.h
@@ -51,12 +51,11 @@
 base::CommandLine MakeElevated(base::CommandLine command_line);
 
 // Functor used by associative containers of strings as a case-insensitive ASCII
-// compare. |T| could be std::string or std::u16string.
-template <typename T>
+// compare. |StringT| could be either UTF-8 or UTF-16.
 struct CaseInsensitiveASCIICompare {
  public:
-  bool operator()(base::BasicStringPiece<T> x,
-                  base::BasicStringPiece<T> y) const {
+  template <typename StringT>
+  bool operator()(const StringT& x, const StringT& y) const {
     return base::CompareCaseInsensitiveASCII(x, y) > 0;
   }
 };
diff --git a/chrome/updater/win/setup/setup_util.cc b/chrome/updater/win/setup/setup_util.cc
index 0ceb0bb..dbe6ed7d 100644
--- a/chrome/updater/win/setup/setup_util.cc
+++ b/chrome/updater/win/setup/setup_util.cc
@@ -262,8 +262,7 @@
   std::string contents;
   if (!base::ReadFileToStringWithMaxSize(deps, &contents, kDepsFileSizeMax))
     return {};
-  const base::flat_set<const wchar_t*,
-                       CaseInsensitiveASCIICompare<std::wstring>>
+  const base::flat_set<const wchar_t*, CaseInsensitiveASCIICompare>
       exclude_extensions = {L".pdb", L".js"};
   std::vector<base::FilePath> result;
   for (const auto& line :
diff --git a/components/autofill/core/common/logging/log_buffer.cc b/components/autofill/core/common/logging/log_buffer.cc
index 961e66e4..0020815c 100644
--- a/components/autofill/core/common/logging/log_buffer.cc
+++ b/components/autofill/core/common/logging/log_buffer.cc
@@ -238,10 +238,10 @@
 
 namespace {
 // Highlights the first |needle| in |haystack| by wrapping it in <b> tags.
-template <typename STRING_TYPE>
-LogBuffer HighlightValueInternal(base::BasicStringPiece<STRING_TYPE> haystack,
-                                 base::BasicStringPiece<STRING_TYPE> needle) {
-  using StringPieceT = base::BasicStringPiece<STRING_TYPE>;
+template <typename CharT>
+LogBuffer HighlightValueInternal(base::BasicStringPiece<CharT> haystack,
+                                 base::BasicStringPiece<CharT> needle) {
+  using StringPieceT = base::BasicStringPiece<CharT>;
   LogBuffer buffer;
   size_t pos = haystack.find(needle);
   if (pos == StringPieceT::npos || needle.empty()) {
diff --git a/components/autofill_assistant/browser/service/server_url_fetcher.cc b/components/autofill_assistant/browser/service/server_url_fetcher.cc
index 5657d88..e95c131f9 100644
--- a/components/autofill_assistant/browser/service/server_url_fetcher.cc
+++ b/components/autofill_assistant/browser/service/server_url_fetcher.cc
@@ -40,19 +40,19 @@
 }
 
 GURL ServerUrlFetcher::GetSupportsScriptEndpoint() const {
-  url::StringPieceReplacements<std::string> script_replacements;
+  GURL::Replacements script_replacements;
   script_replacements.SetPathStr(kScriptEndpoint);
   return server_url_.ReplaceComponents(script_replacements);
 }
 
 GURL ServerUrlFetcher::GetNextActionsEndpoint() const {
-  url::StringPieceReplacements<std::string> action_replacements;
+  GURL::Replacements action_replacements;
   action_replacements.SetPathStr(kActionEndpoint);
   return server_url_.ReplaceComponents(action_replacements);
 }
 
 GURL ServerUrlFetcher::GetTriggerScriptsEndpoint() const {
-  url::StringPieceReplacements<std::string> trigger_replacements;
+  GURL::Replacements trigger_replacements;
   trigger_replacements.SetPathStr(kTriggersEndpoint);
   return server_url_.ReplaceComponents(trigger_replacements);
 }
diff --git a/components/autofill_assistant/browser/service/service_request_sender_impl.cc b/components/autofill_assistant/browser/service/service_request_sender_impl.cc
index eabeb73..ececd87 100644
--- a/components/autofill_assistant/browser/service/service_request_sender_impl.cc
+++ b/components/autofill_assistant/browser/service/service_request_sender_impl.cc
@@ -101,7 +101,7 @@
 
   std::string query_str = base::StrCat({"key=", api_key});
   // query_str must remain valid until ReplaceComponents() has returned.
-  url::StringPieceReplacements<std::string> add_key;
+  GURL::Replacements add_key;
   add_key.SetQueryStr(query_str);
   GURL modified_url = url.ReplaceComponents(add_key);
 
diff --git a/components/password_manager/core/browser/leak_detection/encryption_utils.cc b/components/password_manager/core/browser/leak_detection/encryption_utils.cc
index 3bf9d44..d8e0d3f5 100644
--- a/components/password_manager/core/browser/leak_detection/encryption_utils.cc
+++ b/components/password_manager/core/browser/leak_detection/encryption_utils.cc
@@ -23,17 +23,17 @@
 
 namespace {
 
-template <typename StringT>
-StringT CanonicalizeUsernameT(base::BasicStringPiece<StringT> username) {
-  // String literal containing a single period (i.e. "."). Spelt out explicitly,
-  // because there is no short-form syntax for std::u16string.
-  static constexpr typename StringT::value_type kPeriod[] = {'.', '\0'};
+template <typename CharT>
+std::basic_string<CharT> CanonicalizeUsernameT(
+    base::BasicStringPiece<CharT> username) {
+  static constexpr CharT kPeriod = '.';
 
-  StringT email_lower = base::ToLowerASCII(username);
+  std::basic_string<CharT> email_lower = base::ToLowerASCII(username);
   // |email_lower| might be an email address. Strip off the mail-address host,
   // remove periods from the username and return the result.
-  StringT user_lower = email_lower.substr(0, email_lower.find_last_of('@'));
-  base::RemoveChars(user_lower, kPeriod, &user_lower);
+  std::basic_string<CharT> user_lower =
+      email_lower.substr(0, email_lower.find_last_of('@'));
+  base::RemoveChars(user_lower, {&kPeriod, 1}, &user_lower);
   return user_lower;
 }
 
diff --git a/content/common/content_switches_internal.cc b/content/common/content_switches_internal.cc
index 95eacdb..7cd1e042 100644
--- a/content/common/content_switches_internal.cc
+++ b/content/common/content_switches_internal.cc
@@ -127,7 +127,7 @@
     const base::CommandLine& command_line,
     const char* switch_name) {
   using NativeString = base::CommandLine::StringType;
-  using NativeStringPiece = base::BasicStringPiece<NativeString>;
+  using NativeStringPiece = base::CommandLine::StringPieceType;
 
   std::vector<std::string> features;
   if (!command_line.HasSwitch(switch_name))
diff --git a/net/base/escape.cc b/net/base/escape.cc
index 88f9dc9..552a86b0 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -84,9 +84,10 @@
 }
 
 // Convert |input| string to a form that will not be interpreted as HTML.
-template <class str>
-str EscapeForHTMLImpl(base::BasicStringPiece<str> input) {
-  str result;
+template <class CharT>
+std::basic_string<CharT> EscapeForHTMLImpl(
+    base::BasicStringPiece<CharT> input) {
+  std::basic_string<CharT> result;
   result.reserve(input.size());  // Optimize for no escaping.
 
   for (auto c : input) {
diff --git a/net/base/registry_controlled_domains/registry_controlled_domain.cc b/net/base/registry_controlled_domains/registry_controlled_domain.cc
index 0c44e8b7..6bd1d46 100644
--- a/net/base/registry_controlled_domains/registry_controlled_domain.cc
+++ b/net/base/registry_controlled_domains/registry_controlled_domain.cc
@@ -226,10 +226,9 @@
 }
 
 // Backend for PermissiveGetHostRegistryLength that handles both UTF-8 and
-// UTF-16 input. The template type is the std::string type to use (it makes the
-// typedefs easier than using the character type).
-template <typename Str>
-size_t DoPermissiveGetHostRegistryLength(base::BasicStringPiece<Str> host,
+// UTF-16 input.
+template <typename CharT>
+size_t DoPermissiveGetHostRegistryLength(base::BasicStringPiece<CharT> host,
                                          UnknownRegistryFilter unknown_filter,
                                          PrivateRegistryFilter private_filter) {
   std::string canonical_host;  // Do not modify outside of canon_output.
@@ -445,15 +444,15 @@
 size_t PermissiveGetHostRegistryLength(base::StringPiece host,
                                        UnknownRegistryFilter unknown_filter,
                                        PrivateRegistryFilter private_filter) {
-  return DoPermissiveGetHostRegistryLength<std::string>(host, unknown_filter,
-                                                        private_filter);
+  return DoPermissiveGetHostRegistryLength(host, unknown_filter,
+                                           private_filter);
 }
 
 size_t PermissiveGetHostRegistryLength(base::StringPiece16 host,
                                        UnknownRegistryFilter unknown_filter,
                                        PrivateRegistryFilter private_filter) {
-  return DoPermissiveGetHostRegistryLength<std::u16string>(host, unknown_filter,
-                                                           private_filter);
+  return DoPermissiveGetHostRegistryLength(host, unknown_filter,
+                                           private_filter);
 }
 
 void SetFindDomainGraph() {
diff --git a/net/log/net_log_values.h b/net/log/net_log_values.h
index d7e5401..6e1a362 100644
--- a/net/log/net_log_values.h
+++ b/net/log/net_log_values.h
@@ -5,6 +5,7 @@
 #ifndef NET_LOG_NET_LOG_VALUES_H_
 #define NET_LOG_NET_LOG_VALUES_H_
 
+#include <stddef.h>
 #include <stdint.h>
 
 #include "base/strings/string_piece_forward.h"
diff --git a/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-expected.cc b/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-expected.cc
index 1a089e30..0fcc784 100644
--- a/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-expected.cc
+++ b/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-expected.cc
@@ -278,11 +278,11 @@
 namespace implicit_constructors {
 
 // Based on //base/strings/string_piece_forward.h:
-template <typename STRING_TYPE>
+template <typename CharT>
 class BasicStringPiece;
-typedef BasicStringPiece<std::string> StringPiece;
+typedef BasicStringPiece<char> StringPiece;
 // Based on //base/strings/string_piece.h:
-template <typename STRING_TYPE>
+template <typename CharT>
 class BasicStringPiece {
  public:
   constexpr BasicStringPiece(const char* str) {}
@@ -305,8 +305,7 @@
   // error: no matching function for call to 'FunctionTakingBasicStringPiece'
   // note: candidate function not viable: no known conversion from
   // 'base::CheckedPtr<const char>' to 'templated_functions::StringPiece' (aka
-  // 'BasicStringPiece<basic_string<char, char_traits<char>, allocator<char>>>')
-  // for 1st argument
+  // 'BasicStringPiece<char>') for 1st argument
   FunctionTakingBasicStringPiece(my_struct.const_char_ptr.get());
   FunctionTakingBasicStringPieceRef(my_struct.const_char_ptr.get());
 
diff --git a/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-original.cc b/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-original.cc
index 122b3c4b..e84a461 100644
--- a/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-original.cc
+++ b/tools/clang/rewrite_raw_ptr_fields/tests/affected-expr-original.cc
@@ -276,11 +276,11 @@
 namespace implicit_constructors {
 
 // Based on //base/strings/string_piece_forward.h:
-template <typename STRING_TYPE>
+template <typename CharT>
 class BasicStringPiece;
-typedef BasicStringPiece<std::string> StringPiece;
+typedef BasicStringPiece<char> StringPiece;
 // Based on //base/strings/string_piece.h:
-template <typename STRING_TYPE>
+template <typename CharT>
 class BasicStringPiece {
  public:
   constexpr BasicStringPiece(const char* str) {}
@@ -303,8 +303,7 @@
   // error: no matching function for call to 'FunctionTakingBasicStringPiece'
   // note: candidate function not viable: no known conversion from
   // 'base::CheckedPtr<const char>' to 'templated_functions::StringPiece' (aka
-  // 'BasicStringPiece<basic_string<char, char_traits<char>, allocator<char>>>')
-  // for 1st argument
+  // 'BasicStringPiece<char>') for 1st argument
   FunctionTakingBasicStringPiece(my_struct.const_char_ptr);
   FunctionTakingBasicStringPieceRef(my_struct.const_char_ptr);
 
diff --git a/url/gurl.cc b/url/gurl.cc
index c656255..2107c30b 100644
--- a/url/gurl.cc
+++ b/url/gurl.cc
@@ -68,8 +68,8 @@
   InitializeFromCanonicalSpec();
 }
 
-template<typename STR>
-void GURL::InitCanonical(base::BasicStringPiece<STR> input_spec,
+template <typename CharT>
+void GURL::InitCanonical(base::BasicStringPiece<CharT> input_spec,
                          bool trim_path_end) {
   url::StdStringCanonOutput output(&spec_);
   is_valid_ = url::Canonicalize(
diff --git a/url/gurl.h b/url/gurl.h
index f8ee81e..7dcf1d55 100644
--- a/url/gurl.h
+++ b/url/gurl.h
@@ -45,8 +45,8 @@
 // will know to escape this and produce the desired result.
 class COMPONENT_EXPORT(URL) GURL {
  public:
-  typedef url::StringPieceReplacements<std::string> Replacements;
-  typedef url::StringPieceReplacements<std::u16string> ReplacementsW;
+  typedef url::StringPieceReplacements<char> Replacements;
+  typedef url::StringPieceReplacements<char16_t> ReplacementsW;
 
   // Creates an empty, invalid URL.
   GURL();
@@ -448,8 +448,8 @@
   enum RetainWhiteSpaceSelector { RETAIN_TRAILING_PATH_WHITEPACE };
   GURL(const std::string& url_string, RetainWhiteSpaceSelector);
 
-  template<typename STR>
-  void InitCanonical(base::BasicStringPiece<STR> input_spec,
+  template <typename CharT>
+  void InitCanonical(base::BasicStringPiece<CharT> input_spec,
                      bool trim_path_end);
 
   void InitializeFromCanonicalSpec();
diff --git a/url/url_canon_stdstring.h b/url/url_canon_stdstring.h
index c9a3fee..44edab7f 100644
--- a/url/url_canon_stdstring.h
+++ b/url/url_canon_stdstring.h
@@ -59,11 +59,11 @@
 // references to std::strings.
 // Note: Extra const char* overloads are necessary to break ambiguities that
 // would otherwise exist for char literals.
-template <typename STR>
-class StringPieceReplacements : public Replacements<typename STR::value_type> {
+template <typename CharT>
+class StringPieceReplacements : public Replacements<CharT> {
  private:
-  using CharT = typename STR::value_type;
-  using StringPieceT = base::BasicStringPiece<STR>;
+  using StringT = std::basic_string<CharT>;
+  using StringPieceT = base::BasicStringPiece<CharT>;
   using ParentT = Replacements<CharT>;
   using SetterFun = void (ParentT::*)(const CharT*, const Component&);
 
@@ -74,35 +74,35 @@
  public:
   void SetSchemeStr(const CharT* str) { SetImpl(&ParentT::SetScheme, str); }
   void SetSchemeStr(StringPieceT str) { SetImpl(&ParentT::SetScheme, str); }
-  void SetSchemeStr(const STR&&) = delete;
+  void SetSchemeStr(const StringT&&) = delete;
 
   void SetUsernameStr(const CharT* str) { SetImpl(&ParentT::SetUsername, str); }
   void SetUsernameStr(StringPieceT str) { SetImpl(&ParentT::SetUsername, str); }
-  void SetUsernameStr(const STR&&) = delete;
+  void SetUsernameStr(const StringT&&) = delete;
 
   void SetPasswordStr(const CharT* str) { SetImpl(&ParentT::SetPassword, str); }
   void SetPasswordStr(StringPieceT str) { SetImpl(&ParentT::SetPassword, str); }
-  void SetPasswordStr(const STR&&) = delete;
+  void SetPasswordStr(const StringT&&) = delete;
 
   void SetHostStr(const CharT* str) { SetImpl(&ParentT::SetHost, str); }
   void SetHostStr(StringPieceT str) { SetImpl(&ParentT::SetHost, str); }
-  void SetHostStr(const STR&&) = delete;
+  void SetHostStr(const StringT&&) = delete;
 
   void SetPortStr(const CharT* str) { SetImpl(&ParentT::SetPort, str); }
   void SetPortStr(StringPieceT str) { SetImpl(&ParentT::SetPort, str); }
-  void SetPortStr(const STR&&) = delete;
+  void SetPortStr(const StringT&&) = delete;
 
   void SetPathStr(const CharT* str) { SetImpl(&ParentT::SetPath, str); }
   void SetPathStr(StringPieceT str) { SetImpl(&ParentT::SetPath, str); }
-  void SetPathStr(const STR&&) = delete;
+  void SetPathStr(const StringT&&) = delete;
 
   void SetQueryStr(const CharT* str) { SetImpl(&ParentT::SetQuery, str); }
   void SetQueryStr(StringPieceT str) { SetImpl(&ParentT::SetQuery, str); }
-  void SetQueryStr(const STR&&) = delete;
+  void SetQueryStr(const StringT&&) = delete;
 
   void SetRefStr(const CharT* str) { SetImpl(&ParentT::SetRef, str); }
   void SetRefStr(StringPieceT str) { SetImpl(&ParentT::SetRef, str); }
-  void SetRefStr(const STR&&) = delete;
+  void SetRefStr(const StringT&&) = delete;
 };
 
 }  // namespace url