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

Side by Side Diff: base/utf_string_conversions.cc

Issue 6317016: Change UTF8ToUTF16 to accept const StringPiece&. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 6
7 #include "base/string_piece.h" 7 #include "base/string_piece.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversion_utils.h" 9 #include "base/utf_string_conversion_utils.h"
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 // UTF16 <-> UTF8 -------------------------------------------------------------- 127 // UTF16 <-> UTF8 --------------------------------------------------------------
128 128
129 #if defined(WCHAR_T_IS_UTF32) 129 #if defined(WCHAR_T_IS_UTF32)
130 130
131 bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) { 131 bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) {
132 PrepareForUTF16Or32Output(src, src_len, output); 132 PrepareForUTF16Or32Output(src, src_len, output);
133 return ConvertUnicode(src, src_len, output); 133 return ConvertUnicode(src, src_len, output);
134 } 134 }
135 135
136 string16 UTF8ToUTF16(const std::string& utf8) { 136 string16 UTF8ToUTF16(const base::StringPiece& utf8) {
137 string16 ret; 137 string16 ret;
138 // Ignore the success flag of this call, it will do the best it can for 138 // Ignore the success flag of this call, it will do the best it can for
139 // invalid input, which is what we want here. 139 // invalid input, which is what we want here.
140 UTF8ToUTF16(utf8.data(), utf8.length(), &ret); 140 UTF8ToUTF16(utf8.data(), utf8.length(), &ret);
141 return ret; 141 return ret;
142 } 142 }
143 143
144 bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) { 144 bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) {
145 PrepareForUTF8Output(src, src_len, output); 145 PrepareForUTF8Output(src, src_len, output);
146 return ConvertUnicode(src, src_len, output); 146 return ConvertUnicode(src, src_len, output);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 string16 ASCIIToUTF16(const char* ascii) { 188 string16 ASCIIToUTF16(const char* ascii) {
189 DCHECK(IsStringASCII(ascii)) << ascii; 189 DCHECK(IsStringASCII(ascii)) << ascii;
190 return string16(ascii, &ascii[strlen(ascii)]); 190 return string16(ascii, &ascii[strlen(ascii)]);
191 } 191 }
192 192
193 string16 ASCIIToUTF16(const std::string& ascii) { 193 string16 ASCIIToUTF16(const std::string& ascii) {
194 DCHECK(IsStringASCII(ascii)) << ascii; 194 DCHECK(IsStringASCII(ascii)) << ascii;
195 return string16(ascii.begin(), ascii.end()); 195 return string16(ascii.begin(), ascii.end());
196 } 196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698