summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-31 17:47:09 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-31 17:47:09 +0000
commitf1d8192134f870445ae76be8c16b1566981c9cce (patch)
tree99a0bc223c4e8a7715479f7c35cd95c8e85a2f98 /base
parent34877b3b302e3cb456a705b4b45dd72ae6947c79 (diff)
downloadchromium_src-f1d8192134f870445ae76be8c16b1566981c9cce.zip
chromium_src-f1d8192134f870445ae76be8c16b1566981c9cce.tar.gz
chromium_src-f1d8192134f870445ae76be8c16b1566981c9cce.tar.bz2
Move ASCIIToWide and ASCIIToUTF16 to utf_string_conversions.h. I've found it
weird that UTF8ToWide is in utf_string_conversions, but ASCIIToWide is in string_util.h. This should help some dependencies since string_util changes much more frequently than utf_string_conversions and fewer files will now need string_utils. Since this requires a lot of changes, this keeps a forward-declaration in string_util so I can update the entire project incrementally. This change updates base and net only. I removed some includes of string_util from header files in net. In particular, url_request_context which involved creating a new .cc file to implement a function (already virtual so there's no speed penalty). It turns out a lot of files were getting string_util from this include, so I had to update a bunch of random files to now explicitly include string_util.h TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3076013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc2
-rw-r--r--base/native_library_linux.cc4
-rw-r--r--base/string_util.cc11
-rw-r--r--base/string_util.h15
-rw-r--r--base/utf_string_conversions.cc23
-rw-r--r--base/utf_string_conversions.h14
6 files changed, 52 insertions, 17 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index de7870d..e180ddf 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -21,9 +21,9 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/singleton.h"
-#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
+#include "base/utf_string_conversions.h"
#if defined(OS_LINUX)
// Linux/glibc doesn't natively have setproctitle().
diff --git a/base/native_library_linux.cc b/base/native_library_linux.cc
index 99e32c6..b6d7aef 100644
--- a/base/native_library_linux.cc
+++ b/base/native_library_linux.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -8,7 +8,7 @@
#include "base/file_path.h"
#include "base/logging.h"
-#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
namespace base {
diff --git a/base/string_util.cc b/base/string_util.cc
index 2488b0b..98f48c7 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -25,6 +25,7 @@
#include "base/singleton.h"
#include "base/third_party/dmg_fp/dmg_fp.h"
#include "base/utf_string_conversion_utils.h"
+#include "base/utf_string_conversions.h"
#include "base/third_party/icu/icu_utf.h"
namespace {
@@ -653,21 +654,11 @@ std::string WideToASCII(const std::wstring& wide) {
return std::string(wide.begin(), wide.end());
}
-std::wstring ASCIIToWide(const base::StringPiece& ascii) {
- DCHECK(IsStringASCII(ascii)) << ascii;
- return std::wstring(ascii.begin(), ascii.end());
-}
-
std::string UTF16ToASCII(const string16& utf16) {
DCHECK(IsStringASCII(utf16)) << utf16;
return std::string(utf16.begin(), utf16.end());
}
-string16 ASCIIToUTF16(const base::StringPiece& ascii) {
- DCHECK(IsStringASCII(ascii)) << ascii;
- return string16(ascii.begin(), ascii.end());
-}
-
// Latin1 is just the low range of Unicode, so we can copy directly to convert.
bool WideToLatin1(const std::wstring& wide, std::string* latin1) {
std::string output;
diff --git a/base/string_util.h b/base/string_util.h
index 8e3ae83..762779c 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -227,11 +227,20 @@ bool ContainsOnlyChars(const std::wstring& input,
bool ContainsOnlyChars(const string16& input, const string16& characters);
bool ContainsOnlyChars(const std::string& input, const std::string& characters);
-// These convert between ASCII (7-bit) and Wide/UTF16 strings.
+// Converts to 7-bit ASCII by truncating. The result must be known to be ASCII
+// beforehand.
std::string WideToASCII(const std::wstring& wide);
-std::wstring ASCIIToWide(const base::StringPiece& ascii);
std::string UTF16ToASCII(const string16& utf16);
-string16 ASCIIToUTF16(const base::StringPiece& ascii);
+
+// Forward-declares for functions in utf_string_conversions.h. They used to
+// be here and they were moved. We keep these here so the entire project
+// doesn't need to be switched at once.
+// TODO(brettw) delete these when everybody includes utf_string_conversions.h
+// instead.
+std::wstring ASCIIToWide(const char* ascii);
+std::wstring ASCIIToWide(const std::string& ascii);
+string16 ASCIIToUTF16(const char* ascii);
+string16 ASCIIToUTF16(const std::string& ascii);
// Converts the given wide string to the corresponding Latin1. This will fail
// (return false) if any characters are more than 255.
diff --git a/base/utf_string_conversions.cc b/base/utf_string_conversions.cc
index d517e1b..41a70db 100644
--- a/base/utf_string_conversions.cc
+++ b/base/utf_string_conversions.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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/utf_string_conversions.h"
#include "base/string_piece.h"
+#include "base/string_util.h"
#include "base/utf_string_conversion_utils.h"
using base::PrepareForUTF8Output;
@@ -173,3 +174,23 @@ std::string UTF16ToUTF8(const string16& utf16) {
}
#endif
+
+std::wstring ASCIIToWide(const char* ascii) {
+ DCHECK(IsStringASCII(ascii)) << ascii;
+ return std::wstring(ascii, &ascii[strlen(ascii)]);
+}
+
+std::wstring ASCIIToWide(const std::string& ascii) {
+ DCHECK(IsStringASCII(ascii)) << ascii;
+ return std::wstring(ascii.begin(), ascii.end());
+}
+
+string16 ASCIIToUTF16(const char* ascii) {
+ DCHECK(IsStringASCII(ascii)) << ascii;
+ return string16(ascii, &ascii[strlen(ascii)]);
+}
+
+string16 ASCIIToUTF16(const std::string& ascii) {
+ DCHECK(IsStringASCII(ascii)) << ascii;
+ return string16(ascii.begin(), ascii.end());
+}
diff --git a/base/utf_string_conversions.h b/base/utf_string_conversions.h
index 0ffd480..6c49b41 100644
--- a/base/utf_string_conversions.h
+++ b/base/utf_string_conversions.h
@@ -48,4 +48,18 @@ std::string UTF16ToUTF8(const string16& utf16);
# define UTF16ToWideHack UTF16ToWide
#endif
+// These convert an ASCII string, typically a hardcoded constant, to a
+// UTF16/Wide string.
+//
+// Note that this doesn't use StringPiece because it's very common to need
+// ASCIIToUTF16("foo"), and either we have to include it in this file, or
+// forward declare it and force all callers to include string_piece.h. Given
+// that string_piece brings in complicated stuff like <algorithm>, it's
+// easier to just duplicate these very simple definitions for the two calling
+// cases we actually use.
+std::wstring ASCIIToWide(const char* ascii);
+std::wstring ASCIIToWide(const std::string& ascii);
+string16 ASCIIToUTF16(const char* ascii);
+string16 ASCIIToUTF16(const std::string& ascii);
+
#endif // BASE_UTF_STRING_CONVERSIONS_H_