Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2483)

Unified Diff: base/strings/utf_string_conversions.cc

Issue 1259673002: Make UTF16ToASCII and UTF16TOUTF8 take a StringPiece (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/strings/utf_string_conversions.h ('k') | components/autofill/content/renderer/form_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/utf_string_conversions.cc
diff --git a/base/strings/utf_string_conversions.cc b/base/strings/utf_string_conversions.cc
index 1480d48086fed618ffbcc95cf918d8a0c1ebcb7e..b6cf6ff9b101446d026484df7e1c569fcec434bf 100644
--- a/base/strings/utf_string_conversions.cc
+++ b/base/strings/utf_string_conversions.cc
@@ -73,7 +73,7 @@ bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) {
}
}
-std::wstring UTF8ToWide(const StringPiece& utf8) {
+std::wstring UTF8ToWide(StringPiece utf8) {
if (IsStringASCII(utf8)) {
return std::wstring(utf8.begin(), utf8.end());
}
@@ -153,7 +153,7 @@ bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
}
}
-string16 UTF8ToUTF16(const StringPiece& utf8) {
+string16 UTF8ToUTF16(StringPiece utf8) {
if (IsStringASCII(utf8)) {
return string16(utf8.begin(), utf8.end());
}
@@ -176,7 +176,7 @@ bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) {
}
}
-std::string UTF16ToUTF8(const string16& utf16) {
+std::string UTF16ToUTF8(StringPiece16 utf16) {
if (IsStringASCII(utf16)) {
return std::string(utf16.begin(), utf16.end());
}
@@ -195,7 +195,7 @@ bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
return UTF8ToWide(src, src_len, output);
}
-string16 UTF8ToUTF16(const StringPiece& utf8) {
+string16 UTF8ToUTF16(StringPiece utf8) {
return UTF8ToWide(utf8);
}
@@ -203,18 +203,24 @@ bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) {
return WideToUTF8(src, src_len, output);
}
-std::string UTF16ToUTF8(const string16& utf16) {
- return WideToUTF8(utf16);
+std::string UTF16ToUTF8(StringPiece16 utf16) {
+ if (IsStringASCII(utf16))
+ return std::string(utf16.data(), utf16.data() + utf16.length());
+
+ std::string ret;
+ PrepareForUTF8Output(utf16.data(), utf16.length(), &ret);
+ ConvertUnicode(utf16.data(), utf16.length(), &ret);
+ return ret;
}
#endif
-string16 ASCIIToUTF16(const StringPiece& ascii) {
+string16 ASCIIToUTF16(StringPiece ascii) {
DCHECK(IsStringASCII(ascii)) << ascii;
return string16(ascii.begin(), ascii.end());
}
-std::string UTF16ToASCII(const string16& utf16) {
+std::string UTF16ToASCII(StringPiece16 utf16) {
DCHECK(IsStringASCII(utf16)) << UTF16ToUTF8(utf16);
return std::string(utf16.begin(), utf16.end());
}
« no previous file with comments | « base/strings/utf_string_conversions.h ('k') | components/autofill/content/renderer/form_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698