Define string16 in terms of std::u16string.

This can be done now that we have C++17 support. The typedef is left for
simplicity. It will be replaced in a separate pass.

Remove wstring completely. On Windows we now use explicit 16-bit strings
and cast to make syscalls work. A new helper is added to support this.

Remove some unnecessary conversion functions and NACL defines.

Change-Id: I30c5b35c31e59510474fff71dc7256fb56cda641
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/6020
Commit-Queue: Brett Wilson <brettw@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
diff --git a/base/strings/string16.cc b/base/strings/string16.cc
deleted file mode 100644
index 997ab20..0000000
--- a/base/strings/string16.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/strings/string16.h"
-
-#if defined(WCHAR_T_IS_UTF16) && !defined(_AIX)
-
-#error This file should not be used on 2-byte wchar_t systems
-// If this winds up being needed on 2-byte wchar_t systems, either the
-// definitions below can be used, or the host system's wide character
-// functions like wmemcmp can be wrapped.
-
-#elif defined(WCHAR_T_IS_UTF32)
-
-#include <ostream>
-
-#include "base/strings/utf_string_conversions.h"
-
-namespace base {
-
-int c16memcmp(const char16* s1, const char16* s2, size_t n) {
-  // We cannot call memcmp because that changes the semantics.
-  while (n-- > 0) {
-    if (*s1 != *s2) {
-      // We cannot use (*s1 - *s2) because char16 is unsigned.
-      return ((*s1 < *s2) ? -1 : 1);
-    }
-    ++s1;
-    ++s2;
-  }
-  return 0;
-}
-
-size_t c16len(const char16* s) {
-  const char16* s_orig = s;
-  while (*s) {
-    ++s;
-  }
-  return s - s_orig;
-}
-
-const char16* c16memchr(const char16* s, char16 c, size_t n) {
-  while (n-- > 0) {
-    if (*s == c) {
-      return s;
-    }
-    ++s;
-  }
-  return nullptr;
-}
-
-char16* c16memmove(char16* s1, const char16* s2, size_t n) {
-  return static_cast<char16*>(memmove(s1, s2, n * sizeof(char16)));
-}
-
-char16* c16memcpy(char16* s1, const char16* s2, size_t n) {
-  return static_cast<char16*>(memcpy(s1, s2, n * sizeof(char16)));
-}
-
-char16* c16memset(char16* s, char16 c, size_t n) {
-  char16* s_orig = s;
-  while (n-- > 0) {
-    *s = c;
-    ++s;
-  }
-  return s_orig;
-}
-
-namespace string16_internals {
-
-std::ostream& operator<<(std::ostream& out, const string16& str) {
-  return out << UTF16ToUTF8(str);
-}
-
-void PrintTo(const string16& str, std::ostream* out) {
-  *out << str;
-}
-
-}  // namespace string16_internals
-
-}  // namespace base
-
-template class std::
-    basic_string<base::char16, base::string16_internals::string16_char_traits>;
-
-#endif  // WCHAR_T_IS_UTF32
diff --git a/base/strings/string16.h b/base/strings/string16.h
index 59bf6d7..a8e6ae3 100644
--- a/base/strings/string16.h
+++ b/base/strings/string16.h
@@ -5,199 +5,15 @@
 #ifndef BASE_STRINGS_STRING16_H_
 #define BASE_STRINGS_STRING16_H_
 
-// WHAT:
-// A version of std::basic_string that provides 2-byte characters even when
-// wchar_t is not implemented as a 2-byte type. You can access this class as
-// string16. We also define char16, which string16 is based upon.
-//
-// WHY:
-// On Windows, wchar_t is 2 bytes, and it can conveniently handle UTF-16/UCS-2
-// data. Plenty of existing code operates on strings encoded as UTF-16.
-//
-// On many other platforms, sizeof(wchar_t) is 4 bytes by default. We can make
-// it 2 bytes by using the GCC flag -fshort-wchar. But then std::wstring fails
-// at run time, because it calls some functions (like wcslen) that come from
-// the system's native C library -- which was built with a 4-byte wchar_t!
-// It's wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it's
-// entirely improper on those systems where the encoding of wchar_t is defined
-// as UTF-32.
-//
-// Here, we define string16, which is similar to std::wstring but replaces all
-// libc functions with custom, 2-byte-char compatible routines. It is capable
-// of carrying UTF-16-encoded data.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-
-#include <functional>
 #include <string>
 
-#include "util/build_config.h"
-
-#if defined(WCHAR_T_IS_UTF16)
-
 namespace base {
 
-typedef wchar_t char16;
-typedef std::wstring string16;
+// Temporary definitions. These should be removed and code using the standard
+// ones.
+using char16 = char16_t;
+using string16 = std::u16string;
 
 }  // namespace base
 
-#elif defined(WCHAR_T_IS_UTF32)
-
-#include <wchar.h>  // for mbstate_t
-
-namespace base {
-
-typedef uint16_t char16;
-
-// char16 versions of the functions required by string16_char_traits; these
-// are based on the wide character functions of similar names ("w" or "wcs"
-// instead of "c16").
-int c16memcmp(const char16* s1, const char16* s2, size_t n);
-size_t c16len(const char16* s);
-const char16* c16memchr(const char16* s, char16 c, size_t n);
-char16* c16memmove(char16* s1, const char16* s2, size_t n);
-char16* c16memcpy(char16* s1, const char16* s2, size_t n);
-char16* c16memset(char16* s, char16 c, size_t n);
-
-// This namespace contains the implementation of base::string16 along with
-// things that need to be found via argument-dependent lookup from a
-// base::string16.
-namespace string16_internals {
-
-struct string16_char_traits {
-  typedef char16 char_type;
-  typedef int int_type;
-
-  // int_type needs to be able to hold each possible value of char_type, and in
-  // addition, the distinct value of eof().
-  static_assert(sizeof(int_type) > sizeof(char_type),
-                "int must be larger than 16 bits wide");
-
-  typedef std::streamoff off_type;
-  typedef mbstate_t state_type;
-  typedef std::fpos<state_type> pos_type;
-
-  static void assign(char_type& c1, const char_type& c2) { c1 = c2; }
-
-  static bool eq(const char_type& c1, const char_type& c2) { return c1 == c2; }
-  static bool lt(const char_type& c1, const char_type& c2) { return c1 < c2; }
-
-  static int compare(const char_type* s1, const char_type* s2, size_t n) {
-    return c16memcmp(s1, s2, n);
-  }
-
-  static size_t length(const char_type* s) { return c16len(s); }
-
-  static const char_type* find(const char_type* s,
-                               size_t n,
-                               const char_type& a) {
-    return c16memchr(s, a, n);
-  }
-
-  static char_type* move(char_type* s1, const char_type* s2, size_t n) {
-    return c16memmove(s1, s2, n);
-  }
-
-  static char_type* copy(char_type* s1, const char_type* s2, size_t n) {
-    return c16memcpy(s1, s2, n);
-  }
-
-  static char_type* assign(char_type* s, size_t n, char_type a) {
-    return c16memset(s, a, n);
-  }
-
-  static int_type not_eof(const int_type& c) {
-    return eq_int_type(c, eof()) ? 0 : c;
-  }
-
-  static char_type to_char_type(const int_type& c) { return char_type(c); }
-
-  static int_type to_int_type(const char_type& c) { return int_type(c); }
-
-  static bool eq_int_type(const int_type& c1, const int_type& c2) {
-    return c1 == c2;
-  }
-
-  static int_type eof() { return static_cast<int_type>(EOF); }
-};
-
-}  // namespace string16_internals
-
-typedef std::basic_string<char16,
-                          base::string16_internals::string16_char_traits>
-    string16;
-
-namespace string16_internals {
-
-extern std::ostream& operator<<(std::ostream& out, const string16& str);
-
-// This is required by googletest to print a readable output on test failures.
-extern void PrintTo(const string16& str, std::ostream* out);
-
-}  // namespace string16_internals
-
-}  // namespace base
-
-// The string class will be explicitly instantiated only once, in string16.cc.
-//
-// std::basic_string<> in GNU libstdc++ contains a static data member,
-// _S_empty_rep_storage, to represent empty strings.  When an operation such
-// as assignment or destruction is performed on a string, causing its existing
-// data member to be invalidated, it must not be freed if this static data
-// member is being used.  Otherwise, it counts as an attempt to free static
-// (and not allocated) data, which is a memory error.
-//
-// Generally, due to C++ template magic, _S_empty_rep_storage will be marked
-// as a coalesced symbol, meaning that the linker will combine multiple
-// instances into a single one when generating output.
-//
-// If a string class is used by multiple shared libraries, a problem occurs.
-// Each library will get its own copy of _S_empty_rep_storage.  When strings
-// are passed across a library boundary for alteration or destruction, memory
-// errors will result.  GNU libstdc++ contains a configuration option,
-// --enable-fully-dynamic-string (_GLIBCXX_FULLY_DYNAMIC_STRING), which
-// disables the static data member optimization, but it's a good optimization
-// and non-STL code is generally at the mercy of the system's STL
-// configuration.  Fully-dynamic strings are not the default for GNU libstdc++
-// libstdc++ itself or for the libstdc++ installations on the systems we care
-// about, such as Mac OS X and relevant flavors of Linux.
-//
-// See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24196 .
-//
-// To avoid problems, string classes need to be explicitly instantiated only
-// once, in exactly one library.  All other string users see it via an "extern"
-// declaration.  This is precisely how GNU libstdc++ handles
-// std::basic_string<char> (string) and std::basic_string<wchar_t> (wstring).
-//
-// This also works around a Mac OS X linker bug in ld64-85.2.1 (Xcode 3.1.2),
-// in which the linker does not fully coalesce symbols when dead code
-// stripping is enabled.  This bug causes the memory errors described above
-// to occur even when a std::basic_string<> does not cross shared library
-// boundaries, such as in statically-linked executables.
-//
-// TODO(mark): File this bug with Apple and update this note with a bug number.
-
-extern template class std::
-    basic_string<base::char16, base::string16_internals::string16_char_traits>;
-
-// Specialize std::hash for base::string16. Although the style guide forbids
-// this in general, it is necessary for consistency with WCHAR_T_IS_UTF16
-// platforms, where base::string16 is a type alias for std::wstring.
-namespace std {
-template <>
-struct hash<base::string16> {
-  std::size_t operator()(const base::string16& s) const {
-    std::size_t result = 0;
-    for (base::char16 c : s)
-      result = (result * 131) + c;
-    return result;
-  }
-};
-}  // namespace std
-
-#endif  // WCHAR_T_IS_UTF32
-
 #endif  // BASE_STRINGS_STRING16_H_
diff --git a/base/strings/string_number_conversions.h b/base/strings/string_number_conversions.h
index ecf950e..8ffdd36 100644
--- a/base/strings/string_number_conversions.h
+++ b/base/strings/string_number_conversions.h
@@ -15,26 +15,6 @@
 #include "base/strings/string_piece.h"
 #include "util/build_config.h"
 
-// ----------------------------------------------------------------------------
-// IMPORTANT MESSAGE FROM YOUR SPONSOR
-//
-// This file contains no "wstring" variants. New code should use string16. If
-// you need to make old code work, use the UTF8 version and convert. Please do
-// not add wstring variants.
-//
-// Please do not add "convenience" functions for converting strings to integers
-// that return the value and ignore success/failure. That encourages people to
-// write code that doesn't properly handle the error conditions.
-//
-// DO NOT use these functions in any UI unless it's NOT localized on purpose.
-// Instead, use base::MessageFormatter for a complex message with numbers
-// (integer, float) embedded or base::Format{Number,Percent} to
-// just format a single number/percent. Note that some languages use native
-// digits instead of ASCII digits while others use a group separator or decimal
-// point different from ',' and '.'. Using these functions in the UI would lead
-// numbers to be formatted in a non-native way.
-// ----------------------------------------------------------------------------
-
 namespace base {
 
 // Number -> string conversions ------------------------------------------------
diff --git a/base/strings/string_piece.h b/base/strings/string_piece.h
index 8e4deae..0722269 100644
--- a/base/strings/string_piece.h
+++ b/base/strings/string_piece.h
@@ -428,11 +428,6 @@
     HASH_STRING_PIECE(StringPiece16, sp16);
   }
 };
-struct WStringPieceHash {
-  std::size_t operator()(const WStringPiece& wsp) const {
-    HASH_STRING_PIECE(WStringPiece, wsp);
-  }
-};
 
 }  // namespace base
 
diff --git a/base/strings/string_piece_forward.h b/base/strings/string_piece_forward.h
index b50b980..86c1d5f 100644
--- a/base/strings/string_piece_forward.h
+++ b/base/strings/string_piece_forward.h
@@ -17,7 +17,6 @@
 class BasicStringPiece;
 typedef BasicStringPiece<std::string> StringPiece;
 typedef BasicStringPiece<string16> StringPiece16;
-typedef BasicStringPiece<std::wstring> WStringPiece;
 
 }  // namespace base
 
diff --git a/base/strings/string_tokenizer.h b/base/strings/string_tokenizer.h
index 451a011..9c3b5fa 100644
--- a/base/strings/string_tokenizer.h
+++ b/base/strings/string_tokenizer.h
@@ -242,7 +242,7 @@
 
 typedef StringTokenizerT<std::string, std::string::const_iterator>
     StringTokenizer;
-typedef StringTokenizerT<std::wstring, std::wstring::const_iterator>
+typedef StringTokenizerT<std::u16string, std::u16string::const_iterator>
     WStringTokenizer;
 typedef StringTokenizerT<std::string, const char*> CStringTokenizer;
 
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
index 9b03c26..f3e8257 100644
--- a/base/strings/string_util.cc
+++ b/base/strings/string_util.cc
@@ -97,54 +97,9 @@
 struct NonASCIIMask<8, char> {
   static inline uint64_t value() { return 0x8080808080808080ULL; }
 };
-#if defined(WCHAR_T_IS_UTF32)
-template <>
-struct NonASCIIMask<4, wchar_t> {
-  static inline uint32_t value() { return 0xFFFFFF80U; }
-};
-template <>
-struct NonASCIIMask<8, wchar_t> {
-  static inline uint64_t value() { return 0xFFFFFF80FFFFFF80ULL; }
-};
-#endif  // WCHAR_T_IS_UTF32
 
 }  // namespace
 
-bool IsWprintfFormatPortable(const wchar_t* format) {
-  for (const wchar_t* position = format; *position != '\0'; ++position) {
-    if (*position == '%') {
-      bool in_specification = true;
-      bool modifier_l = false;
-      while (in_specification) {
-        // Eat up characters until reaching a known specifier.
-        if (*++position == '\0') {
-          // The format string ended in the middle of a specification.  Call
-          // it portable because no unportable specifications were found.  The
-          // string is equally broken on all platforms.
-          return true;
-        }
-
-        if (*position == 'l') {
-          // 'l' is the only thing that can save the 's' and 'c' specifiers.
-          modifier_l = true;
-        } else if (((*position == 's' || *position == 'c') && !modifier_l) ||
-                   *position == 'S' || *position == 'C' || *position == 'F' ||
-                   *position == 'D' || *position == 'O' || *position == 'U') {
-          // Not portable.
-          return false;
-        }
-
-        if (wcschr(L"diouxXeEfgGaAcspn%", *position)) {
-          // Portable, keep scanning the rest of the format string.
-          in_specification = false;
-        }
-      }
-    }
-  }
-
-  return true;
-}
-
 namespace {
 
 template <typename StringType>
@@ -489,12 +444,6 @@
   return DoIsStringASCII(str.data(), str.length());
 }
 
-#if defined(WCHAR_T_IS_UTF32)
-bool IsStringASCII(WStringPiece str) {
-  return DoIsStringASCII(str.data(), str.length());
-}
-#endif
-
 bool IsStringUTF8(StringPiece str) {
   const char* src = str.data();
   int32_t src_len = static_cast<int32_t>(str.length());
@@ -623,7 +572,7 @@
   return EndsWithT<string16>(str, search_for, case_sensitivity);
 }
 
-char HexDigitToInt(wchar_t c) {
+char HexDigitToInt(char16_t c) {
   DCHECK(IsHexDigit(c));
   if (c >= '0' && c <= '9')
     return static_cast<char>(c - '0');
@@ -634,9 +583,9 @@
   return 0;
 }
 
-bool IsUnicodeWhitespace(wchar_t c) {
+bool IsUnicodeWhitespace(char16_t c) {
   // kWhitespaceWide is a NULL-terminated string
-  for (const wchar_t* cur = kWhitespaceWide; *cur; ++cur) {
+  for (const char16_t* cur = kWhitespaceUTF16; *cur; ++cur) {
     if (*cur == c)
       return true;
   }
@@ -1091,11 +1040,4 @@
 
 }  // namespace
 
-size_t strlcpy(char* dst, const char* src, size_t dst_size) {
-  return lcpyT<char>(dst, src, dst_size);
-}
-size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
-  return lcpyT<wchar_t>(dst, src, dst_size);
-}
-
 }  // namespace base
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index 2d5d01c..9b3c608 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -53,38 +53,6 @@
   return result;
 }
 
-// BSD-style safe and consistent string copy functions.
-// Copies |src| to |dst|, where |dst_size| is the total allocated size of |dst|.
-// Copies at most |dst_size|-1 characters, and always NULL terminates |dst|, as
-// long as |dst_size| is not 0.  Returns the length of |src| in characters.
-// If the return value is >= dst_size, then the output was truncated.
-// NOTE: All sizes are in number of characters, NOT in bytes.
-size_t strlcpy(char* dst, const char* src, size_t dst_size);
-size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size);
-
-// Scan a wprintf format string to determine whether it's portable across a
-// variety of systems.  This function only checks that the conversion
-// specifiers used by the format string are supported and have the same meaning
-// on a variety of systems.  It doesn't check for other errors that might occur
-// within a format string.
-//
-// Nonportable conversion specifiers for wprintf are:
-//  - 's' and 'c' without an 'l' length modifier.  %s and %c operate on char
-//     data on all systems except Windows, which treat them as wchar_t data.
-//     Use %ls and %lc for wchar_t data instead.
-//  - 'S' and 'C', which operate on wchar_t data on all systems except Windows,
-//     which treat them as char data.  Use %ls and %lc for wchar_t data
-//     instead.
-//  - 'F', which is not identified by Windows wprintf documentation.
-//  - 'D', 'O', and 'U', which are deprecated and not available on all systems.
-//     Use %ld, %lo, and %lu instead.
-//
-// Note that there is no portable conversion specifier for char data when
-// working with wprintf.
-//
-// This function is intended to be called from base::vswprintf.
-bool IsWprintfFormatPortable(const wchar_t* format);
-
 // ASCII-specific tolower.  The standard library's tolower is locale sensitive,
 // so we don't want to use it here.
 inline char ToLowerASCII(char c) {
@@ -146,7 +114,6 @@
 // Contains the set of characters representing whitespace in the corresponding
 // encoding. Null-terminated. The ASCII versions are the whitespaces as defined
 // by HTML5, and don't include control characters.
-extern const wchar_t kWhitespaceWide[];  // Includes Unicode.
 extern const char16 kWhitespaceUTF16[];  // Includes Unicode.
 extern const char kWhitespaceASCII[];
 extern const char16 kWhitespaceASCIIAs16[];  // No unicode.
@@ -264,9 +231,6 @@
 bool IsStringUTF8(StringPiece str);
 bool IsStringASCII(StringPiece str);
 bool IsStringASCII(StringPiece16 str);
-#if defined(WCHAR_T_IS_UTF32)
-bool IsStringASCII(WStringPiece str);
-#endif
 
 // Compare the lower-case form of the given string against the given
 // previously-lower-cased ASCII string (typically a constant).
@@ -338,10 +302,10 @@
 //    'a' -> 10
 //    'B' -> 11
 // Assumes the input is a valid hex character. DCHECKs in debug builds if not.
-char HexDigitToInt(wchar_t c);
+char HexDigitToInt(char16_t c);
 
 // Returns true if it's a Unicode whitespace character.
-bool IsUnicodeWhitespace(wchar_t c);
+bool IsUnicodeWhitespace(char16_t c);
 
 // Return a byte string in human-readable format with a unit suffix. Not
 // appropriate for use in any UI; use of FormatBytes and friends in ui/base is
diff --git a/base/strings/string_util_constants.cc b/base/strings/string_util_constants.cc
index 37ff95f..ed17fcd 100644
--- a/base/strings/string_util_constants.cc
+++ b/base/strings/string_util_constants.cc
@@ -34,8 +34,6 @@
       0x3000, /* IDEOGRAPHIC SPACE */         \
       0
 
-const wchar_t kWhitespaceWide[] = {WHITESPACE_UNICODE};
-
 const char16 kWhitespaceUTF16[] = {WHITESPACE_UNICODE};
 
 const char kWhitespaceASCII[] = {0x09,  // CHARACTER TABULATION
diff --git a/base/strings/string_util_posix.h b/base/strings/string_util_posix.h
index 6868a65..83be1db 100644
--- a/base/strings/string_util_posix.h
+++ b/base/strings/string_util_posix.h
@@ -7,20 +7,12 @@
 
 #include <stdarg.h>
 #include <stddef.h>
-#include <stdio.h>
 #include <string.h>
-#include <wchar.h>
 
 #include "base/logging.h"
 
 namespace base {
 
-// Chromium code style is to not use malloc'd strings; this is only for use
-// for interaction with APIs that require it.
-inline char* strdup(const char* str) {
-  return ::strdup(str);
-}
-
 inline int vsnprintf(char* buffer,
                      size_t size,
                      const char* format,
@@ -28,14 +20,6 @@
   return ::vsnprintf(buffer, size, format, arguments);
 }
 
-inline int vswprintf(wchar_t* buffer,
-                     size_t size,
-                     const wchar_t* format,
-                     va_list arguments) {
-  DCHECK(IsWprintfFormatPortable(format));
-  return ::vswprintf(buffer, size, format, arguments);
-}
-
 }  // namespace base
 
 #endif  // BASE_STRINGS_STRING_UTIL_POSIX_H_
diff --git a/base/strings/string_util_win.h b/base/strings/string_util_win.h
index 8f9fa81..717a72c 100644
--- a/base/strings/string_util_win.h
+++ b/base/strings/string_util_win.h
@@ -9,18 +9,11 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
-#include <wchar.h>
 
 #include "base/logging.h"
 
 namespace base {
 
-// Chromium code style is to not use malloc'd strings; this is only for use
-// for interaction with APIs that require it.
-inline char* strdup(const char* str) {
-  return _strdup(str);
-}
-
 inline int vsnprintf(char* buffer,
                      size_t size,
                      const char* format,
@@ -31,18 +24,6 @@
   return length;
 }
 
-inline int vswprintf(wchar_t* buffer,
-                     size_t size,
-                     const wchar_t* format,
-                     va_list arguments) {
-  DCHECK(IsWprintfFormatPortable(format));
-
-  int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments);
-  if (length < 0)
-    return _vscwprintf(format, arguments);
-  return length;
-}
-
 }  // namespace base
 
 #endif  // BASE_STRINGS_STRING_UTIL_WIN_H_
diff --git a/base/strings/stringprintf.cc b/base/strings/stringprintf.cc
index c7d141b..20ddfc6 100644
--- a/base/strings/stringprintf.cc
+++ b/base/strings/stringprintf.cc
@@ -32,15 +32,6 @@
   return base::vsnprintf(buffer, buf_size, format, argptr);
 }
 
-#if defined(OS_WIN)
-inline int vsnprintfT(wchar_t* buffer,
-                      size_t buf_size,
-                      const wchar_t* format,
-                      va_list argptr) {
-  return base::vswprintf(buffer, buf_size, format, argptr);
-}
-#endif
-
 // Templatized backend for StringPrintF/StringAppendF. This does not finalize
 // the va_list, the caller is expected to do that.
 template <class StringType>
@@ -122,17 +113,6 @@
   return result;
 }
 
-#if defined(OS_WIN)
-std::wstring StringPrintf(const wchar_t* format, ...) {
-  va_list ap;
-  va_start(ap, format);
-  std::wstring result;
-  StringAppendV(&result, format, ap);
-  va_end(ap);
-  return result;
-}
-#endif
-
 std::string StringPrintV(const char* format, va_list ap) {
   std::string result;
   StringAppendV(&result, format, ap);
@@ -148,19 +128,6 @@
   return *dst;
 }
 
-#if defined(OS_WIN)
-const std::wstring& SStringPrintf(std::wstring* dst,
-                                  const wchar_t* format,
-                                  ...) {
-  va_list ap;
-  va_start(ap, format);
-  dst->clear();
-  StringAppendV(dst, format, ap);
-  va_end(ap);
-  return *dst;
-}
-#endif
-
 void StringAppendF(std::string* dst, const char* format, ...) {
   va_list ap;
   va_start(ap, format);
@@ -168,23 +135,8 @@
   va_end(ap);
 }
 
-#if defined(OS_WIN)
-void StringAppendF(std::wstring* dst, const wchar_t* format, ...) {
-  va_list ap;
-  va_start(ap, format);
-  StringAppendV(dst, format, ap);
-  va_end(ap);
-}
-#endif
-
 void StringAppendV(std::string* dst, const char* format, va_list ap) {
   StringAppendVT(dst, format, ap);
 }
 
-#if defined(OS_WIN)
-void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
-  StringAppendVT(dst, format, ap);
-}
-#endif
-
 }  // namespace base
diff --git a/base/strings/stringprintf.h b/base/strings/stringprintf.h
index 8c12aca..e6e0746 100644
--- a/base/strings/stringprintf.h
+++ b/base/strings/stringprintf.h
@@ -17,10 +17,6 @@
 // Return a C++ string given printf-like input.
 std::string StringPrintf(_Printf_format_string_ const char* format, ...)
     PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
-#if defined(OS_WIN)
-std::wstring StringPrintf(_Printf_format_string_ const wchar_t* format, ...)
-    WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
-#endif
 
 // Return a C++ string given vprintf-like input.
 std::string StringPrintV(const char* format, va_list ap)
@@ -30,30 +26,16 @@
 const std::string& SStringPrintf(std::string* dst,
                                  _Printf_format_string_ const char* format,
                                  ...) PRINTF_FORMAT(2, 3);
-#if defined(OS_WIN)
-const std::wstring& SStringPrintf(std::wstring* dst,
-                                  _Printf_format_string_ const wchar_t* format,
-                                  ...) WPRINTF_FORMAT(2, 3);
-#endif
 
 // Append result to a supplied string.
 void StringAppendF(std::string* dst,
                    _Printf_format_string_ const char* format,
                    ...) PRINTF_FORMAT(2, 3);
-#if defined(OS_WIN)
-void StringAppendF(std::wstring* dst,
-                   _Printf_format_string_ const wchar_t* format,
-                   ...) WPRINTF_FORMAT(2, 3);
-#endif
 
 // Lower-level routine that takes a va_list and appends to a specified
 // string.  All other routines are just convenience wrappers around it.
 void StringAppendV(std::string* dst, const char* format, va_list ap)
     PRINTF_FORMAT(2, 0);
-#if defined(OS_WIN)
-void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap)
-    WPRINTF_FORMAT(2, 0);
-#endif
 
 }  // namespace base
 
diff --git a/base/strings/utf_string_conversion_utils.cc b/base/strings/utf_string_conversion_utils.cc
index c962411..4e5f890 100644
--- a/base/strings/utf_string_conversion_utils.cc
+++ b/base/strings/utf_string_conversion_utils.cc
@@ -53,19 +53,6 @@
   return IsValidCodepoint(*code_point);
 }
 
-#if defined(WCHAR_T_IS_UTF32)
-bool ReadUnicodeCharacter(const wchar_t* src,
-                          int32_t src_len,
-                          int32_t* char_index,
-                          uint32_t* code_point) {
-  // Conversion is easy since the source is 32-bit.
-  *code_point = src[*char_index];
-
-  // Validate the value.
-  return IsValidCodepoint(*code_point);
-}
-#endif  // defined(WCHAR_T_IS_UTF32)
-
 // WriteUnicodeCharacter -------------------------------------------------------
 
 size_t WriteUnicodeCharacter(uint32_t code_point, std::string* output) {
@@ -120,10 +107,6 @@
 }
 
 // Instantiate versions we know callers will need.
-#if !defined(OS_WIN)
-// wchar_t and char16 are the same thing on Windows.
-template void PrepareForUTF8Output(const wchar_t*, size_t, std::string*);
-#endif
 template void PrepareForUTF8Output(const char16*, size_t, std::string*);
 
 template <typename STRING>
@@ -144,10 +127,6 @@
 }
 
 // Instantiate versions we know callers will need.
-#if !defined(OS_WIN)
-// std::wstring and string16 are the same thing on Windows.
-template void PrepareForUTF16Or32Output(const char*, size_t, std::wstring*);
-#endif
 template void PrepareForUTF16Or32Output(const char*, size_t, string16*);
 
 }  // namespace base
diff --git a/base/strings/utf_string_conversion_utils.h b/base/strings/utf_string_conversion_utils.h
index 6f89652..78cbde7 100644
--- a/base/strings/utf_string_conversion_utils.h
+++ b/base/strings/utf_string_conversion_utils.h
@@ -52,14 +52,6 @@
                           int32_t* char_index,
                           uint32_t* code_point);
 
-#if defined(WCHAR_T_IS_UTF32)
-// Reads UTF-32 character. The usage is the same as the 8-bit version above.
-bool ReadUnicodeCharacter(const wchar_t* src,
-                          int32_t src_len,
-                          int32_t* char_index,
-                          uint32_t* code_point);
-#endif  // defined(WCHAR_T_IS_UTF32)
-
 // WriteUnicodeCharacter -------------------------------------------------------
 
 // Appends a UTF-8 character to the given 8-bit string.  Returns the number of
@@ -70,16 +62,6 @@
 // string.  Returns the number of 16-bit values written.
 size_t WriteUnicodeCharacter(uint32_t code_point, string16* output);
 
-#if defined(WCHAR_T_IS_UTF32)
-// Appends the given UTF-32 character to the given 32-bit string.  Returns the
-// number of 32-bit values written.
-inline size_t WriteUnicodeCharacter(uint32_t code_point, std::wstring* output) {
-  // This is the easy case, just append the character.
-  output->push_back(code_point);
-  return 1;
-}
-#endif  // defined(WCHAR_T_IS_UTF32)
-
 // Generalized Unicode converter -----------------------------------------------
 
 // Guesses the length of the output in UTF-8 in bytes, clears that output
diff --git a/base/strings/utf_string_conversions.cc b/base/strings/utf_string_conversions.cc
index b04d54d..15f12f6 100644
--- a/base/strings/utf_string_conversions.cc
+++ b/base/strings/utf_string_conversions.cc
@@ -37,20 +37,6 @@
   static constexpr int value = 3;
 };
 
-#if defined(WCHAR_T_IS_UTF32)
-template <>
-struct SizeCoefficient<wchar_t, char> {
-  // UTF-8 uses at most 4 codeunits per character.
-  static constexpr int value = 4;
-};
-
-template <>
-struct SizeCoefficient<wchar_t, char16> {
-  // UTF-16 uses at most 2 codeunits per character.
-  static constexpr int value = 2;
-};
-#endif  // defined(WCHAR_T_IS_UTF32)
-
 template <typename SrcChar, typename DestChar>
 constexpr int size_coefficient_v =
     SizeCoefficient<std::decay_t<SrcChar>, std::decay_t<DestChar>>::value;
@@ -67,14 +53,6 @@
   CBU16_APPEND_UNSAFE(out, *size, code_point);
 }
 
-#if defined(WCHAR_T_IS_UTF32)
-
-void UnicodeAppendUnsafe(wchar_t* out, int32_t* size, uint32_t code_point) {
-  out[(*size)++] = code_point;
-}
-
-#endif  // defined(WCHAR_T_IS_UTF32)
-
 // DoUTFConversion ------------------------------------------------------------
 // Main driver of UTFConversion specialized for different Src encodings.
 // dest has to have enough room for the converted text.
@@ -144,31 +122,6 @@
   return success;
 }
 
-#if defined(WCHAR_T_IS_UTF32)
-
-template <typename DestChar>
-bool DoUTFConversion(const wchar_t* src,
-                     int32_t src_len,
-                     DestChar* dest,
-                     int32_t* dest_len) {
-  bool success = true;
-
-  for (int32_t i = 0; i < src_len; ++i) {
-    int32_t code_point = src[i];
-
-    if (!IsValidCodepoint(code_point)) {
-      success = false;
-      code_point = kErrorCodePoint;
-    }
-
-    UnicodeAppendUnsafe(dest, dest_len, code_point);
-  }
-
-  return success;
-}
-
-#endif  // defined(WCHAR_T_IS_UTF32)
-
 // UTFConversion --------------------------------------------------------------
 // Function template for generating all UTF conversions.
 
@@ -226,99 +179,7 @@
   return ret;
 }
 
-// UTF-16 <-> Wide -------------------------------------------------------------
-
-#if defined(WCHAR_T_IS_UTF16)
-// When wide == UTF-16 the conversions are a NOP.
-
-bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output) {
-  output->assign(src, src_len);
-  return true;
-}
-
-string16 WideToUTF16(WStringPiece wide) {
-  return wide.as_string();
-}
-
-bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output) {
-  output->assign(src, src_len);
-  return true;
-}
-
-std::wstring UTF16ToWide(StringPiece16 utf16) {
-  return utf16.as_string();
-}
-
-#elif defined(WCHAR_T_IS_UTF32)
-
-bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output) {
-  return UTFConversion(base::WStringPiece(src, src_len), output);
-}
-
-string16 WideToUTF16(WStringPiece wide) {
-  string16 ret;
-  // Ignore the success flag of this call, it will do the best it can for
-  // invalid input, which is what we want here.
-  WideToUTF16(wide.data(), wide.length(), &ret);
-  return ret;
-}
-
-bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output) {
-  return UTFConversion(StringPiece16(src, src_len), output);
-}
-
-std::wstring UTF16ToWide(StringPiece16 utf16) {
-  std::wstring ret;
-  // Ignore the success flag of this call, it will do the best it can for
-  // invalid input, which is what we want here.
-  UTF16ToWide(utf16.data(), utf16.length(), &ret);
-  return ret;
-}
-
-#endif  // defined(WCHAR_T_IS_UTF32)
-
-// UTF-8 <-> Wide --------------------------------------------------------------
-
-// UTF8ToWide is the same code, regardless of whether wide is 16 or 32 bits
-
-bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) {
-  return UTFConversion(StringPiece(src, src_len), output);
-}
-
-std::wstring UTF8ToWide(StringPiece utf8) {
-  std::wstring ret;
-  // Ignore the success flag of this call, it will do the best it can for
-  // invalid input, which is what we want here.
-  UTF8ToWide(utf8.data(), utf8.length(), &ret);
-  return ret;
-}
-
-#if defined(WCHAR_T_IS_UTF16)
-// Easy case since we can use the "utf" versions we already wrote above.
-
-bool WideToUTF8(const wchar_t* src, size_t src_len, std::string* output) {
-  return UTF16ToUTF8(src, src_len, output);
-}
-
-std::string WideToUTF8(WStringPiece wide) {
-  return UTF16ToUTF8(wide);
-}
-
-#elif defined(WCHAR_T_IS_UTF32)
-
-bool WideToUTF8(const wchar_t* src, size_t src_len, std::string* output) {
-  return UTFConversion(WStringPiece(src, src_len), output);
-}
-
-std::string WideToUTF8(WStringPiece wide) {
-  std::string ret;
-  // Ignore the success flag of this call, it will do the best it can for
-  // invalid input, which is what we want here.
-  WideToUTF8(wide.data(), wide.length(), &ret);
-  return ret;
-}
-
-#endif  // defined(WCHAR_T_IS_UTF32)
+// ASCII <-> UTF-16 -----------------------------------------------------------
 
 string16 ASCIIToUTF16(StringPiece ascii) {
   DCHECK(IsStringASCII(ascii)) << ascii;
diff --git a/base/strings/utf_string_conversions.h b/base/strings/utf_string_conversions.h
index 704943e..c4c2b11 100644
--- a/base/strings/utf_string_conversions.h
+++ b/base/strings/utf_string_conversions.h
@@ -14,22 +14,6 @@
 
 namespace base {
 
-// These convert between UTF-8, -16, and -32 strings. They are potentially slow,
-// so avoid unnecessary conversions. The low-level versions return a boolean
-// indicating whether the conversion was 100% valid. In this case, it will still
-// do the best it can and put the result in the output buffer. The versions that
-// return strings ignore this error and just return the best conversion
-// possible.
-bool WideToUTF8(const wchar_t* src, size_t src_len, std::string* output);
-std::string WideToUTF8(WStringPiece wide);
-bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output);
-std::wstring UTF8ToWide(StringPiece utf8);
-
-bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output);
-string16 WideToUTF16(WStringPiece wide);
-bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output);
-std::wstring UTF16ToWide(StringPiece16 utf16);
-
 bool UTF8ToUTF16(const char* src, size_t src_len, string16* output);
 string16 UTF8ToUTF16(StringPiece utf8);
 bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output);