summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-06 21:32:31 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-06 21:32:31 +0000
commit7ec490096f5508b0cae67cf1cc0664eaabd090f9 (patch)
tree7b5b2191e6bc52f5c04ef0437f687780a96067b5
parent12e60fdb9c4c0c5cdb95c5fabebb15b4c161718c (diff)
downloadchromium_src-7ec490096f5508b0cae67cf1cc0664eaabd090f9.zip
chromium_src-7ec490096f5508b0cae67cf1cc0664eaabd090f9.tar.gz
chromium_src-7ec490096f5508b0cae67cf1cc0664eaabd090f9.tar.bz2
Move utf_string_conversions to strings/ and add namespace.
This keeps a forwarding header in the old location and adds "using" statements to avoid changing all callers. BUG=None R=tfarina@chromium.org Review URL: https://codereview.chromium.org/14126006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198542 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gyp2
-rw-r--r--base/base.gypi4
-rw-r--r--base/strings/utf_string_conversions.cc (renamed from base/utf_string_conversions.cc)19
-rw-r--r--base/strings/utf_string_conversions.h72
-rw-r--r--base/strings/utf_string_conversions_unittest.cc (renamed from base/utf_string_conversions_unittest.cc)2
-rw-r--r--base/utf_string_conversions.h56
6 files changed, 87 insertions, 68 deletions
diff --git a/base/base.gyp b/base/base.gyp
index e362a70..8b3ebac 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -582,6 +582,7 @@
'strings/sys_string_conversions_mac_unittest.mm',
'strings/sys_string_conversions_unittest.cc',
'strings/utf_offset_string_conversions_unittest.cc',
+ 'strings/utf_string_conversions_unittest.cc',
'synchronization/cancellation_flag_unittest.cc',
'synchronization/condition_variable_unittest.cc',
'synchronization/lock_unittest.cc',
@@ -613,7 +614,6 @@
'tools_sanity_unittest.cc',
'tracked_objects_unittest.cc',
'tuple_unittest.cc',
- 'utf_string_conversions_unittest.cc',
'values_unittest.cc',
'version_unittest.cc',
'vlog_unittest.cc',
diff --git a/base/base.gypi b/base/base.gypi
index 151ff3d..7194f24 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -426,6 +426,8 @@
'strings/utf_offset_string_conversions.h',
'strings/utf_string_conversion_utils.cc',
'strings/utf_string_conversion_utils.h',
+ 'strings/utf_string_conversions.cc',
+ 'strings/utf_string_conversions.h',
'supports_user_data.cc',
'supports_user_data.h',
'synchronization/cancellation_flag.cc',
@@ -523,8 +525,6 @@
'tracking_info.cc',
'tracking_info.h',
'tuple.h',
- 'utf_string_conversions.cc',
- 'utf_string_conversions.h',
'values.cc',
'values.h',
'value_conversions.cc',
diff --git a/base/utf_string_conversions.cc b/base/strings/utf_string_conversions.cc
index ae96c64..b75ed0c 100644
--- a/base/utf_string_conversions.cc
+++ b/base/strings/utf_string_conversions.cc
@@ -2,16 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/utf_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/string_util.h"
#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversion_utils.h"
-using base::PrepareForUTF8Output;
-using base::PrepareForUTF16Or32Output;
-using base::ReadUnicodeCharacter;
-using base::WriteUnicodeCharacter;
+namespace base {
namespace {
@@ -63,7 +60,7 @@ bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) {
return ConvertUnicode(src, src_len, output);
}
-std::wstring UTF8ToWide(const base::StringPiece& utf8) {
+std::wstring UTF8ToWide(const StringPiece& utf8) {
std::wstring ret;
UTF8ToWide(utf8.data(), utf8.length(), &ret);
return ret;
@@ -133,7 +130,7 @@ bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
return ConvertUnicode(src, src_len, output);
}
-string16 UTF8ToUTF16(const base::StringPiece& utf8) {
+string16 UTF8ToUTF16(const StringPiece& utf8) {
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.
@@ -161,7 +158,7 @@ bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
return UTF8ToWide(src, src_len, output);
}
-string16 UTF8ToUTF16(const base::StringPiece& utf8) {
+string16 UTF8ToUTF16(const StringPiece& utf8) {
return UTF8ToWide(utf8);
}
@@ -175,12 +172,14 @@ std::string UTF16ToUTF8(const string16& utf16) {
#endif
-std::wstring ASCIIToWide(const base::StringPiece& ascii) {
+std::wstring ASCIIToWide(const StringPiece& ascii) {
DCHECK(IsStringASCII(ascii)) << ascii;
return std::wstring(ascii.begin(), ascii.end());
}
-string16 ASCIIToUTF16(const base::StringPiece& ascii) {
+string16 ASCIIToUTF16(const StringPiece& ascii) {
DCHECK(IsStringASCII(ascii)) << ascii;
return string16(ascii.begin(), ascii.end());
}
+
+} // namespace base
diff --git a/base/strings/utf_string_conversions.h b/base/strings/utf_string_conversions.h
new file mode 100644
index 0000000..ec6a87f
--- /dev/null
+++ b/base/strings/utf_string_conversions.h
@@ -0,0 +1,72 @@
+// Copyright (c) 2011 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.
+
+#ifndef BASE_STRINGS_UTF_STRING_CONVERSIONS_H_
+#define BASE_STRINGS_UTF_STRING_CONVERSIONS_H_
+
+#include <string>
+
+#include "base/base_export.h"
+#include "base/string16.h"
+#include "base/strings/string_piece.h"
+
+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.
+BASE_EXPORT bool WideToUTF8(const wchar_t* src, size_t src_len,
+ std::string* output);
+BASE_EXPORT std::string WideToUTF8(const std::wstring& wide);
+BASE_EXPORT bool UTF8ToWide(const char* src, size_t src_len,
+ std::wstring* output);
+BASE_EXPORT std::wstring UTF8ToWide(const StringPiece& utf8);
+
+BASE_EXPORT bool WideToUTF16(const wchar_t* src, size_t src_len,
+ string16* output);
+BASE_EXPORT string16 WideToUTF16(const std::wstring& wide);
+BASE_EXPORT bool UTF16ToWide(const char16* src, size_t src_len,
+ std::wstring* output);
+BASE_EXPORT std::wstring UTF16ToWide(const string16& utf16);
+
+BASE_EXPORT bool UTF8ToUTF16(const char* src, size_t src_len, string16* output);
+BASE_EXPORT string16 UTF8ToUTF16(const StringPiece& utf8);
+BASE_EXPORT bool UTF16ToUTF8(const char16* src, size_t src_len,
+ std::string* output);
+BASE_EXPORT std::string UTF16ToUTF8(const string16& utf16);
+
+// We are trying to get rid of wstring as much as possible, but it's too big
+// a mess to do it all at once. These conversions should be used when we
+// really should just be passing a string16 around, but we haven't finished
+// porting whatever module uses wstring and the conversion is being used as a
+// stopcock. This makes it easy to grep for the ones that should be removed.
+#if defined(OS_WIN)
+# define WideToUTF16Hack
+# define UTF16ToWideHack
+#else
+# define WideToUTF16Hack WideToUTF16
+# define UTF16ToWideHack UTF16ToWide
+#endif
+
+// These convert an ASCII string, typically a hardcoded constant, to a
+// UTF16/Wide string.
+BASE_EXPORT std::wstring ASCIIToWide(const StringPiece& ascii);
+BASE_EXPORT string16 ASCIIToUTF16(const StringPiece& ascii);
+
+} // namespace base
+
+// TODO(brettw) remove these when callers are fixed up.
+using base::WideToUTF8;
+using base::UTF8ToWide;
+using base::WideToUTF16;
+using base::UTF16ToWide;
+using base::UTF8ToUTF16;
+using base::UTF16ToUTF8;
+using base::ASCIIToWide;
+using base::ASCIIToUTF16;
+
+#endif // BASE_STRINGS_UTF_STRING_CONVERSIONS_H_
diff --git a/base/utf_string_conversions_unittest.cc b/base/strings/utf_string_conversions_unittest.cc
index b44e309..974184e 100644
--- a/base/utf_string_conversions_unittest.cc
+++ b/base/strings/utf_string_conversions_unittest.cc
@@ -6,7 +6,7 @@
#include "base/logging.h"
#include "base/string_util.h"
#include "base/strings/string_piece.h"
-#include "base/utf_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
diff --git a/base/utf_string_conversions.h b/base/utf_string_conversions.h
index ee4265a..284f45c 100644
--- a/base/utf_string_conversions.h
+++ b/base/utf_string_conversions.h
@@ -2,57 +2,5 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_UTF_STRING_CONVERSIONS_H_
-#define BASE_UTF_STRING_CONVERSIONS_H_
-
-#include <string>
-
-#include "base/base_export.h"
-#include "base/string16.h"
-#include "base/strings/string_piece.h"
-
-// 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.
-BASE_EXPORT bool WideToUTF8(const wchar_t* src, size_t src_len,
- std::string* output);
-BASE_EXPORT std::string WideToUTF8(const std::wstring& wide);
-BASE_EXPORT bool UTF8ToWide(const char* src, size_t src_len,
- std::wstring* output);
-BASE_EXPORT std::wstring UTF8ToWide(const base::StringPiece& utf8);
-
-BASE_EXPORT bool WideToUTF16(const wchar_t* src, size_t src_len,
- string16* output);
-BASE_EXPORT string16 WideToUTF16(const std::wstring& wide);
-BASE_EXPORT bool UTF16ToWide(const char16* src, size_t src_len,
- std::wstring* output);
-BASE_EXPORT std::wstring UTF16ToWide(const string16& utf16);
-
-BASE_EXPORT bool UTF8ToUTF16(const char* src, size_t src_len, string16* output);
-BASE_EXPORT string16 UTF8ToUTF16(const base::StringPiece& utf8);
-BASE_EXPORT bool UTF16ToUTF8(const char16* src, size_t src_len,
- std::string* output);
-BASE_EXPORT std::string UTF16ToUTF8(const string16& utf16);
-
-// We are trying to get rid of wstring as much as possible, but it's too big
-// a mess to do it all at once. These conversions should be used when we
-// really should just be passing a string16 around, but we haven't finished
-// porting whatever module uses wstring and the conversion is being used as a
-// stopcock. This makes it easy to grep for the ones that should be removed.
-#if defined(OS_WIN)
-# define WideToUTF16Hack
-# define UTF16ToWideHack
-#else
-# define WideToUTF16Hack WideToUTF16
-# define UTF16ToWideHack UTF16ToWide
-#endif
-
-// These convert an ASCII string, typically a hardcoded constant, to a
-// UTF16/Wide string.
-BASE_EXPORT std::wstring ASCIIToWide(const base::StringPiece& ascii);
-BASE_EXPORT string16 ASCIIToUTF16(const base::StringPiece& ascii);
-
-#endif // BASE_UTF_STRING_CONVERSIONS_H_
+// TODO(brettw) remove this header once all callers are fixed up.
+#include "base/strings/utf_string_conversions.h"