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

Side by Side Diff: net/base/net_string_util_icu.cc

Issue 266053002: Implement alternative string conversion functions in net/ on Android, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove GN changes Created 6 years, 7 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
« no previous file with comments | « net/base/net_string_util.h ('k') | net/base/net_string_util_icu_alternatives_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/base/net_string_util.h" 5 #include "net/base/net_string_util.h"
6 6
7 #include "base/i18n/i18n_constants.h" 7 #include "base/i18n/i18n_constants.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "third_party/icu/source/common/unicode/ucnv.h" 10 #include "third_party/icu/source/common/unicode/ucnv.h"
11 11
12 namespace net { 12 namespace net {
13 13
14 const char* const kCharsetLatin1 = base::kCodepageLatin1;
15
14 bool ConvertToUtf8(const std::string& text, const char* charset, 16 bool ConvertToUtf8(const std::string& text, const char* charset,
15 std::string* output) { 17 std::string* output) {
16 output->clear(); 18 output->clear();
17 19
18 UErrorCode err = U_ZERO_ERROR; 20 UErrorCode err = U_ZERO_ERROR;
19 UConverter* converter(ucnv_open(charset, &err)); 21 UConverter* converter(ucnv_open(charset, &err));
20 if (U_FAILURE(err)) 22 if (U_FAILURE(err))
21 return false; 23 return false;
22 24
23 // A single byte in a legacy encoding can be expanded to 3 bytes in UTF-8. 25 // A single byte in a legacy encoding can be expanded to 3 bytes in UTF-8.
(...skipping 12 matching lines...) Expand all
36 38
37 output->resize(output_length); 39 output->resize(output_length);
38 return true; 40 return true;
39 } 41 }
40 42
41 bool ConvertToUtf8AndNormalize(const std::string& text, const char* charset, 43 bool ConvertToUtf8AndNormalize(const std::string& text, const char* charset,
42 std::string* output) { 44 std::string* output) {
43 return base::ConvertToUtf8AndNormalize(text, charset, output); 45 return base::ConvertToUtf8AndNormalize(text, charset, output);
44 } 46 }
45 47
46 bool ConvertLatin1ToUtf8AndNormalize(const std::string& text,
47 std::string* output) {
48 return net::ConvertToUtf8AndNormalize(text, base::kCodepageLatin1, output);
49 }
50
51 bool ConvertToUTF16(const std::string& text, const char* charset, 48 bool ConvertToUTF16(const std::string& text, const char* charset,
52 base::string16* output) { 49 base::string16* output) {
53 return base::CodepageToUTF16(text, charset, 50 return base::CodepageToUTF16(text, charset,
54 base::OnStringConversionError::FAIL, output); 51 base::OnStringConversionError::FAIL, output);
55 } 52 }
56 53
57 bool ConvertLatin1ToUTF16(const std::string& text, base::string16* output) { 54 bool ConvertToUTF16WithSubstitutions(const std::string& text,
58 return base::CodepageToUTF16(text, base::kCodepageLatin1, 55 const char* charset,
59 base::OnStringConversionError::FAIL, output); 56 base::string16* output) {
57 return base::CodepageToUTF16(text, charset,
58 base::OnStringConversionError::SUBSTITUTE,
59 output);
60 } 60 }
61 61
62 } // namespace net 62 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_string_util.h ('k') | net/base/net_string_util_icu_alternatives_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698