summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/SConscript1
-rw-r--r--base/base.xcodeproj/project.pbxproj4
-rw-r--r--base/clipboard_mac.mm2
-rw-r--r--base/string16.cc68
-rw-r--r--base/string16.h156
-rw-r--r--base/string_util.h12
-rw-r--r--base/string_util_icu.cc58
-rw-r--r--net/base/net_util.cc6
-rw-r--r--net/base/net_util_unittest.cc4
-rw-r--r--webkit/glue/glue_util.cc16
-rw-r--r--webkit/glue/glue_util.h2
-rw-r--r--webkit/glue/password_form_dom_manager.cc2
-rw-r--r--webkit/glue/weberror_impl.cc2
13 files changed, 178 insertions, 155 deletions
diff --git a/base/SConscript b/base/SConscript
index eb1ff71..2114560 100644
--- a/base/SConscript
+++ b/base/SConscript
@@ -155,6 +155,7 @@ if env['PLATFORM'] in ('darwin', 'posix'):
'platform_thread_posix.cc',
'process_util_posix.cc',
'shared_memory_posix.cc',
+ 'string16.cc',
'thread_local_storage_posix.cc',
'time_posix.cc',
'waitable_event_generic.cc',
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index a863ce0..da15715 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -82,6 +82,7 @@
7BD8F4D30E65B55000034DE9 /* tuple_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BD8F4D00E65B54B00034DE9 /* tuple_unittest.cc */; };
7BD8F4D50E65B55000034DE9 /* scoped_ptr_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BD8F4CF0E65B4A900034DE9 /* scoped_ptr_unittest.cc */; };
7BD8F6D30E65DB0200034DE9 /* bzip2_error_handler.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BD8F6D20E65DB0200034DE9 /* bzip2_error_handler.cc */; };
+ 7BD8F7740E65E89800034DE9 /* string16.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BD8F7730E65E89800034DE9 /* string16.cc */; };
820EB4F70E3A613F009668FC /* string_piece.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4F50E3A613F009668FC /* string_piece.cc */; };
820EB4FA0E3A6178009668FC /* string_util_icu.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4F90E3A6178009668FC /* string_util_icu.cc */; };
820EB5020E3A618B009668FC /* tracked.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4FE0E3A618B009668FC /* tracked.cc */; };
@@ -351,6 +352,7 @@
7BD8F4D00E65B54B00034DE9 /* tuple_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tuple_unittest.cc; sourceTree = "<group>"; };
7BD8F4D10E65B54B00034DE9 /* waitable_event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = waitable_event.h; sourceTree = "<group>"; };
7BD8F6D20E65DB0200034DE9 /* bzip2_error_handler.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bzip2_error_handler.cc; sourceTree = "<group>"; };
+ 7BD8F7730E65E89800034DE9 /* string16.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = string16.cc; sourceTree = "<group>"; };
7BD9E84E0DA447F800FC7A01 /* singleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = singleton.h; sourceTree = "<group>"; };
7BEB81100D9AD288009BA8DD /* prcpucfg_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prcpucfg_mac.h; path = third_party/nspr/prcpucfg_mac.h; sourceTree = "<group>"; };
7BEB81490D9B0F33009BA8DD /* time_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = time_posix.cc; sourceTree = "<group>"; };
@@ -833,6 +835,7 @@
825403780D92D2CF0006B936 /* stats_counters.h */,
825403790D92D2CF0006B936 /* stats_table.cc */,
8254037A0D92D2CF0006B936 /* stats_table.h */,
+ 7BD8F7730E65E89800034DE9 /* string16.cc */,
821B91680DAABD7F00F350D7 /* string16.h */,
E4A133420E37A3C400110AA2 /* string_escape.cc */,
E4A133430E37A3C400110AA2 /* string_escape.h */,
@@ -1194,6 +1197,7 @@
ABF4B9BE0DC2BD1500A6E319 /* sha512.cc in Sources */,
824653740DC12D0E007C2BAA /* shared_memory_posix.cc in Sources */,
829E365F0DC0FB1C00819EBF /* stats_table.cc in Sources */,
+ 7BD8F7740E65E89800034DE9 /* string16.cc in Sources */,
E4A133440E37A3C400110AA2 /* string_escape.cc in Sources */,
820EB4F70E3A613F009668FC /* string_piece.cc in Sources */,
829E36460DC0F6AC00819EBF /* string_util.cc in Sources */,
diff --git a/base/clipboard_mac.mm b/base/clipboard_mac.mm
index e04849c..58c16d7 100644
--- a/base/clipboard_mac.mm
+++ b/base/clipboard_mac.mm
@@ -15,7 +15,7 @@ namespace {
const NSString* kUTTypeURLName = @"public.url-name";
NSString* nsStringForWString(const std::wstring& string) {
- std::string16 text16 = WideToUTF16(string);
+ string16 text16 = WideToUTF16(string);
return [NSString stringWithCharacters:text16.c_str() length:text16.length()];
}
diff --git a/base/string16.cc b/base/string16.cc
new file mode 100644
index 0000000..2a7ec9c
--- /dev/null
+++ b/base/string16.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2006-2008 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/string16.h"
+
+#if defined(WCHAR_T_IS_UTF16)
+
+#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)
+
+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 0;
+}
+
+char16* c16memmove(char16* s1, const char16* s2, size_t n) {
+ return reinterpret_cast<char16*>(memmove(s1, s2, n * sizeof(char16)));
+}
+
+char16* c16memcpy(char16* s1, const char16* s2, size_t n) {
+ return reinterpret_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 base
+
+#endif // WCHAR_T_IS_UTF32
diff --git a/base/string16.h b/base/string16.h
index 25725af..f545286 100644
--- a/base/string16.h
+++ b/base/string16.h
@@ -6,112 +6,62 @@
#define BASE_STRING16_H_
// WHAT:
-// A version of std::basic_string that works even on Linux when 2-byte wchar_t
-// values (-fshort-wchar) are used. You can access this class as std::string16.
-// We also define char16, which std::string16 is based upon.
+// 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:
-// Firefox uses 2-byte wide characters (UTF-16). On Windows, this is
-// mostly compatible with wchar_t, which is 2 bytes (UCS2).
+// 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 Linux, sizeof(wchar_t) is 4 bytes by default. We can make it 2 bytes
-// using the GCC flag -fshort-wchar. But then std::wstring fails at run time,
-// because it calls some functions (like wcslen) that come from glibc -- which
-// was built with a 4-byte wchar_t!
+// 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.
//
-// So we define std::string16, which is similar to std::wstring but replaces
-// all glibc functions with custom, 2-byte-char compatible routines. Fortuntely
-// for us, std::wstring uses mostly *inline* wchar_t-based functions (like
-// wmemcmp) that are defined in .h files and do not need to be overridden.
+// 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 <string>
-#include "build/build_config.h"
+#include "base/basictypes.h"
-#ifdef WCHAR_T_IS_UTF16
+#if defined(WCHAR_T_IS_UTF16)
typedef wchar_t char16;
+typedef std::wstring string16;
-namespace std {
-typedef wstring string16;
-}
+#elif defined(WCHAR_T_IS_UTF32)
-#else // !WCHAR_T_IS_UTF16
+typedef uint16 char16;
-typedef unsigned short char16;
+namespace base {
-namespace std {
-typedef basic_string<char16> string16;
-}
-
-
-// Define char16 versions of functions required below in char_traits<char16>
-extern "C" {
-
-inline char16 *char16_wmemmove(char16 *s1, const char16 *s2, size_t n) {
- return reinterpret_cast<char16*>(memmove(s1, s2, n * sizeof(char16)));
-}
-
-inline char16 *char16_wmemcpy(char16 *s1, const char16 *s2, size_t n) {
- return reinterpret_cast<char16*>(memcpy(s1, s2, n * sizeof(char16)));
-}
-
-inline int char16_wmemcmp(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;
- --n;
- }
- return 0;
-}
-
-inline const char16 *char16_wmemchr(const char16 *s, char16 c, size_t n) {
- while (n > 0) {
- if (*s == c) {
- return s;
- }
- ++s;
- --n;
- }
- return 0;
-}
-
-inline char16 *char16_wmemset(char16 *s, char16 c, size_t n) {
- char16 *s_orig = s;
- while (n > 0) {
- *s = c;
- ++s;
- --n;
- }
- return s_orig;
-}
-
-inline size_t char16_wcslen(const char16 *s) {
- const char16 *s_orig = s;
- while (*s)
- ++s;
- return (s - s_orig);
-}
-
-} // extern "C"
+// 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);
+struct string16_char_traits {
+ typedef char16 char_type;
+ typedef int int_type;
-// Definition of char_traits<char16>, which enables basic_string<char16>
-//
-// This is a slightly modified version of char_traits<wchar_t> from gcc 3.2.2
-namespace std {
+ // int_type needs to be able to hold each possible value of char_type, and in
+ // addition, the distinct value of eof().
+ COMPILE_ASSERT(sizeof(int_type) > sizeof(char_type), unexpected_type_width);
-template<> struct char_traits<char16> {
- typedef char16 char_type;
- typedef wint_t int_type;
- typedef streamoff off_type;
- typedef wstreampos pos_type;
+ 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;
@@ -125,51 +75,55 @@ template<> struct char_traits<char16> {
}
static int compare(const char_type* s1, const char_type* s2, size_t n) {
- return char16_wmemcmp(s1, s2, n);
+ return c16memcmp(s1, s2, n);
}
static size_t length(const char_type* s) {
- return char16_wcslen(s);
+ return c16len(s);
}
static const char_type* find(const char_type* s, size_t n,
const char_type& a) {
- return char16_wmemchr(s, a, n);
+ return c16memchr(s, a, n);
}
static char_type* move(char_type* s1, const char_type* s2, int_type n) {
- return char16_wmemmove(s1, s2, n);
+ return c16memmove(s1, s2, n);
}
static char_type* copy(char_type* s1, const char_type* s2, size_t n) {
- return char16_wmemcpy(s1, s2, n);
+ return c16memcpy(s1, s2, n);
}
static char_type* assign(char_type* s, size_t n, char_type a) {
- return char16_wmemset(s, a, n);
+ 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>(WEOF);
- }
- static int_type not_eof(const int_type& c) {
- return eq_int_type(c, eof()) ? 0 : c;
+ return static_cast<int_type>(EOF);
}
};
-} // namespace std
+} // namespace base
-#endif // !WCHAR_T_IS_UTF16
+typedef std::basic_string<char16, base::string16_char_traits> string16;
-#endif // BASE_STRING16_H_
+#endif // WCHAR_T_IS_UTF32
+#endif // BASE_STRING16_H_
diff --git a/base/string_util.h b/base/string_util.h
index bd95589..69ac608 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -175,15 +175,15 @@ std::string WideToUTF8(const std::wstring& wide);
bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output);
std::wstring UTF8ToWide(const std::string& utf8);
-bool WideToUTF16(const wchar_t* src, size_t src_len, std::string16* output);
-std::string16 WideToUTF16(const std::wstring& wide);
+bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output);
+string16 WideToUTF16(const std::wstring& wide);
bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output);
-std::wstring UTF16ToWide(const std::string16& utf8);
+std::wstring UTF16ToWide(const string16& utf8);
-bool UTF8ToUTF16(const char* src, size_t src_len, std::string16* output);
-std::string16 UTF8ToUTF16(const std::string& utf8);
+bool UTF8ToUTF16(const char* src, size_t src_len, string16* output);
+string16 UTF8ToUTF16(const std::string& utf8);
bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output);
-std::string UTF16ToUTF8(const std::string16& utf16);
+std::string UTF16ToUTF8(const string16& utf16);
// Defines the error handling modes of WideToCodepage and CodepageToWide.
class OnStringUtilConversionError {
diff --git a/base/string_util_icu.cc b/base/string_util_icu.cc
index 1c15062..2287ba5 100644
--- a/base/string_util_icu.cc
+++ b/base/string_util_icu.cc
@@ -80,7 +80,7 @@ bool ReadUnicodeCharacter(const wchar_t* src, int32 src_len,
// WriteUnicodeCharacter -------------------------------------------------------
// Appends a UTF-8 character to the given 8-bit string.
-void WriteUnicodeCharacter(uint32 code_point, std::basic_string<char>* output) {
+void WriteUnicodeCharacter(uint32 code_point, std::string* output) {
if (code_point <= 0x7f) {
// Fast path the common case of one byte.
output->push_back(code_point);
@@ -99,8 +99,7 @@ void WriteUnicodeCharacter(uint32 code_point, std::basic_string<char>* output) {
}
// Appends the given code point as a UTF-16 character to the STL string.
-void WriteUnicodeCharacter(uint32 code_point,
- std::basic_string<char16>* output) {
+void WriteUnicodeCharacter(uint32 code_point, string16* output) {
if (U16_LENGTH(code_point) == 1) {
// Thie code point is in the Basic Multilingual Plane (BMP).
output->push_back(static_cast<char16>(code_point));
@@ -114,8 +113,7 @@ void WriteUnicodeCharacter(uint32 code_point,
#if defined(WCHAR_T_IS_UTF32)
// Appends the given UTF-32 character to the given 32-bit string.
-inline void WriteUnicodeCharacter(uint32 code_point,
- std::basic_string<wchar_t>* output) {
+inline void WriteUnicodeCharacter(uint32 code_point, std::wstring* output) {
// This is the easy case, just append the character.
output->push_back(code_point);
}
@@ -127,9 +125,8 @@ inline void WriteUnicodeCharacter(uint32 code_point,
// Unicode character type as a STL string. The given input buffer and size
// determine the source, and the given output STL string will be replaced by
// the result.
-template<typename SRC_CHAR, typename DEST_CHAR>
-bool ConvertUnicode(const SRC_CHAR* src, size_t src_len,
- std::basic_string<DEST_CHAR>* output) {
+template<typename SRC_CHAR, typename DEST_STRING>
+bool ConvertUnicode(const SRC_CHAR* src, size_t src_len, DEST_STRING* output) {
output->clear();
// ICU requires 32-bit numbers.
@@ -164,9 +161,8 @@ void ReserveUTF8Output(const CHAR* src, size_t src_len, std::string* output) {
// Guesses the size of the output buffer (containing either UTF-16 or -32 data)
// given some UTF-8 input that will be converted to it. See ReserveUTF8Output.
// We assume the source length is > 0.
-template<typename CHAR>
-void ReserveUTF16Or32Output(const char* src, size_t src_len,
- std::basic_string<CHAR>* output) {
+template<typename STRING>
+void ReserveUTF16Or32Output(const char* src, size_t src_len, STRING* output) {
if (static_cast<unsigned char>(src[0]) < 0x80) {
// Assume the input is all ASCII, which means 1:1 correspondence.
output->reserve(src_len);
@@ -199,7 +195,7 @@ bool WideToUTF8(const wchar_t* src, size_t src_len, std::string* output) {
}
ReserveUTF8Output(src, src_len, output);
- return ConvertUnicode<wchar_t, char>(src, src_len, output);
+ return ConvertUnicode<wchar_t, std::string>(src, src_len, output);
}
std::wstring UTF8ToWide(const std::string& utf8) {
@@ -218,7 +214,7 @@ bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) {
}
ReserveUTF16Or32Output(src, src_len, output);
- return ConvertUnicode<char, wchar_t>(src, src_len, output);
+ return ConvertUnicode<char, std::wstring>(src, src_len, output);
}
// UTF-16 <-> Wide -------------------------------------------------------------
@@ -226,16 +222,16 @@ bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) {
#if defined(WCHAR_T_IS_UTF16)
// When wide == UTF-16, then conversions are a NOP.
-std::string16 WideToUTF16(const std::wstring& wide) {
+string16 WideToUTF16(const std::wstring& wide) {
return wide;
}
-bool WideToUTF16(const wchar_t* src, size_t src_len, std::string16* output) {
+bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output) {
output->assign(src, src_len);
return true;
}
-std::wstring UTF16ToWide(const std::string16& utf16) {
+std::wstring UTF16ToWide(const string16& utf16) {
return utf16;
}
@@ -246,8 +242,8 @@ bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output) {
#elif defined(WCHAR_T_IS_UTF32)
-std::string16 WideToUTF16(const std::wstring& wide) {
- std::string16 ret;
+string16 WideToUTF16(const std::wstring& wide) {
+ string16 ret;
if (wide.empty())
return ret;
@@ -255,7 +251,7 @@ std::string16 WideToUTF16(const std::wstring& wide) {
return ret;
}
-bool WideToUTF16(const wchar_t* src, size_t src_len, std::string16* output) {
+bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output) {
if (src_len == 0) {
output->clear();
return true;
@@ -264,10 +260,10 @@ bool WideToUTF16(const wchar_t* src, size_t src_len, std::string16* output) {
// Assume that normally we won't have any non-BMP characters so the counts
// will be the same.
output->reserve(src_len);
- return ConvertUnicode<wchar_t, char16>(src, src_len, output);
+ return ConvertUnicode<wchar_t, string16>(src, src_len, output);
}
-std::wstring UTF16ToWide(const std::string16& utf16) {
+std::wstring UTF16ToWide(const string16& utf16) {
std::wstring ret;
if (utf16.empty())
return ret;
@@ -285,7 +281,7 @@ bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output) {
// Assume that normally we won't have any non-BMP characters so the counts
// will be the same.
output->reserve(src_len);
- return ConvertUnicode<char16, wchar_t>(src, src_len, output);
+ return ConvertUnicode<char16, std::wstring>(src, src_len, output);
}
#endif // defined(WCHAR_T_IS_UTF32)
@@ -294,18 +290,18 @@ bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output) {
#if defined(WCHAR_T_IS_UTF32)
-bool UTF8ToUTF16(const char* src, size_t src_len, std::string16* output) {
+bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
if (src_len == 0) {
output->clear();
return true;
}
ReserveUTF16Or32Output(src, src_len, output);
- return ConvertUnicode<char, char16>(src, src_len, output);
+ return ConvertUnicode<char, string16>(src, src_len, output);
}
-std::string16 UTF8ToUTF16(const std::string& utf8) {
- std::string16 ret;
+string16 UTF8ToUTF16(const std::string& utf8) {
+ string16 ret;
if (utf8.empty())
return ret;
@@ -322,10 +318,10 @@ bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) {
}
ReserveUTF8Output(src, src_len, output);
- return ConvertUnicode<char16, char>(src, src_len, output);
+ return ConvertUnicode<char16, std::string>(src, src_len, output);
}
-std::string UTF16ToUTF8(const std::string16& utf16) {
+std::string UTF16ToUTF8(const string16& utf16) {
std::string ret;
if (utf16.empty())
return ret;
@@ -339,11 +335,11 @@ std::string UTF16ToUTF8(const std::string16& utf16) {
#elif defined(WCHAR_T_IS_UTF16)
// Easy case since we can use the "wide" versions we already wrote above.
-bool UTF8ToUTF16(const char* src, size_t src_len, std::string16* output) {
+bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
return UTF8ToWide(src, src_len, output);
}
-std::string16 UTF8ToUTF16(const std::string& utf8) {
+string16 UTF8ToUTF16(const std::string& utf8) {
return UTF8ToWide(utf8);
}
@@ -351,7 +347,7 @@ bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) {
return WideToUTF8(src, src_len, output);
}
-std::string UTF16ToUTF8(const std::string16& utf16) {
+std::string UTF16ToUTF8(const string16& utf16) {
return WideToUTF8(utf16);
}
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index c558787..df012a2 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -568,7 +568,7 @@ bool IsIDNComponentSafe(const char16* str,
void IDNToUnicodeOneComponent(const char16* comp,
int comp_len,
const std::wstring& languages,
- std::string16* out) {
+ string16* out) {
DCHECK(comp_len >= 0);
if (comp_len == 0)
return;
@@ -696,12 +696,12 @@ void IDNToUnicode(const char* host,
const std::wstring& languages,
std::wstring* out) {
// Convert the ASCII input to a wide string for ICU.
- std::string16 input16;
+ string16 input16;
input16.reserve(host_len);
for (int i = 0; i < host_len; i++)
input16.push_back(host[i]);
- std::string16 out16;
+ string16 out16;
// The output string is appended to, so convert what's already there if
// needed.
#if defined(WCHAR_T_IS_UTF32)
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 40dce3a..94017fc 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -124,7 +124,7 @@ TEST(NetUtilTest, FileURLConversion) {
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_cases); i++) {
- net::FileURLToFilePath(GURL(WideToUTF16(url_cases[i].url)), &output);
+ net::FileURLToFilePath(GURL(WideToUTF8(url_cases[i].url)), &output);
EXPECT_EQ(std::wstring(url_cases[i].file), output);
}
@@ -137,7 +137,7 @@ TEST(NetUtilTest, FileURLConversion) {
#elif defined(OS_POSIX)
const wchar_t wide[] = L"/d:/Chinese/\xe6\x89\x80\xe6\x9c\x89\xe4\xb8\xad\xe6\x96\x87\xe7\xbd\x91\xe9\xa1\xb5.doc";
#endif
- EXPECT_TRUE(net::FileURLToFilePath(GURL(WideToUTF16(utf8)), &output));
+ EXPECT_TRUE(net::FileURLToFilePath(GURL(WideToUTF8(utf8)), &output));
EXPECT_EQ(std::wstring(wide), output);
// Unfortunately, UTF8ToWide discards invalid UTF8 input.
diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc
index da61bd2..e2d40f6 100644
--- a/webkit/glue/glue_util.cc
+++ b/webkit/glue/glue_util.cc
@@ -34,15 +34,15 @@ std::wstring StringToStdWString(const WebCore::String& str) {
#if defined(WCHAR_T_IS_UTF16)
return std::wstring(chars ? chars : L"", str.length());
#elif defined(WCHAR_T_IS_UTF32)
- std::string16 str16(chars ? chars : reinterpret_cast<const char16 *>(L""),
- str.length());
+ string16 str16(chars ? chars : reinterpret_cast<const char16 *>(L""),
+ str.length());
return UTF16ToWide(str16);
#endif
}
-std::string16 StringToStdString16(const WebCore::String& str) {
+string16 StringToString16(const WebCore::String& str) {
const UChar* chars = str.characters();
- return std::string16(chars ? chars : (UChar *)L"", str.length());
+ return string16(chars ? chars : (UChar *)L"", str.length());
}
std::string StringToStdString(const WebCore::String& str) {
@@ -57,7 +57,7 @@ WebCore::String StdWStringToString(const std::wstring& str) {
#if defined(WCHAR_T_IS_UTF16)
return WebCore::String(str.data(), static_cast<unsigned>(str.length()));
#elif defined(WCHAR_T_IS_UTF32)
- std::string16 str16 = WideToUTF16(str);
+ string16 str16 = WideToUTF16(str);
return WebCore::String(str16.data(), static_cast<unsigned>(str16.length()));
#endif
}
@@ -73,7 +73,7 @@ WebCore::DeprecatedString StdWStringToDeprecatedString(
reinterpret_cast<const WebCore::DeprecatedChar*>(str.c_str()),
static_cast<int>(str.size()));
#elif defined(WCHAR_T_IS_UTF32)
- std::string16 str16 = WideToUTF16(str);
+ string16 str16 = WideToUTF16(str);
return WebCore::DeprecatedString(
reinterpret_cast<const WebCore::DeprecatedChar*>(str16.c_str()),
static_cast<int>(str16.size()));
@@ -86,8 +86,8 @@ std::wstring DeprecatedStringToStdWString(
return std::wstring(reinterpret_cast<const wchar_t*>(dep.unicode()),
dep.length());
#elif defined(WCHAR_T_IS_UTF32)
- std::string16 str16(reinterpret_cast<const char16*>(dep.unicode()),
- dep.length());
+ string16 str16(reinterpret_cast<const char16*>(dep.unicode()),
+ dep.length());
return UTF16ToWide(str16);
#endif
}
diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h
index 55f8ea3..2451a2d 100644
--- a/webkit/glue/glue_util.h
+++ b/webkit/glue/glue_util.h
@@ -22,7 +22,7 @@ namespace webkit_glue {
std::string CStringToStdString(const WebCore::CString& str);
WebCore::CString StdStringToCString(const std::string& str);
std::wstring StringToStdWString(const WebCore::String& str);
-std::string16 StringToStdString16(const WebCore::String& str);
+string16 StringToString16(const WebCore::String& str);
std::string StringToStdString(const WebCore::String& str);
WebCore::String StdWStringToString(const std::wstring& str);
diff --git a/webkit/glue/password_form_dom_manager.cc b/webkit/glue/password_form_dom_manager.cc
index 036a464..ccc89df 100644
--- a/webkit/glue/password_form_dom_manager.cc
+++ b/webkit/glue/password_form_dom_manager.cc
@@ -42,7 +42,7 @@ PasswordForm* PasswordFormDomManager::CreatePasswordForm(
// Get the document URL
WebCore::String origin_string = form->document()->documentURI();
- GURL full_origin(webkit_glue::StringToStdString16(origin_string));
+ GURL full_origin(webkit_glue::StringToStdString(origin_string));
// Calculate the canonical action URL
GURL full_action(webkit_glue::KURLToGURL(loader->completeURL(form->action())));
diff --git a/webkit/glue/weberror_impl.cc b/webkit/glue/weberror_impl.cc
index 52584d9..721336e 100644
--- a/webkit/glue/weberror_impl.cc
+++ b/webkit/glue/weberror_impl.cc
@@ -13,7 +13,7 @@
WebErrorImpl::WebErrorImpl(const WebCore::ResourceError& e)
: error_code_(e.errorCode()),
- failed_url_(webkit_glue::StringToStdString16(e.failingURL())) {
+ failed_url_(webkit_glue::StringToStdString(e.failingURL())) {
}
WebErrorImpl::WebErrorImpl(const WebError& e)