OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/i18n/icu_string_conversions.h" | 5 #include "base/i18n/icu_string_conversions.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 inline UConverterType utf32_platform_endian() { | 137 inline UConverterType utf32_platform_endian() { |
138 #if U_IS_BIG_ENDIAN | 138 #if U_IS_BIG_ENDIAN |
139 return UCNV_UTF32_BigEndian; | 139 return UCNV_UTF32_BigEndian; |
140 #else | 140 #else |
141 return UCNV_UTF32_LittleEndian; | 141 return UCNV_UTF32_LittleEndian; |
142 #endif | 142 #endif |
143 } | 143 } |
144 | 144 |
145 } // namespace | 145 } // namespace |
146 | 146 |
147 const char kCodepageLatin1[] = "ISO-8859-1"; | |
148 const char kCodepageUTF8[] = "UTF-8"; | |
149 const char kCodepageUTF16BE[] = "UTF-16BE"; | |
150 const char kCodepageUTF16LE[] = "UTF-16LE"; | |
151 | |
152 // Codepage <-> Wide/UTF-16 --------------------------------------------------- | 147 // Codepage <-> Wide/UTF-16 --------------------------------------------------- |
153 | 148 |
154 bool UTF16ToCodepage(const string16& utf16, | 149 bool UTF16ToCodepage(const string16& utf16, |
155 const char* codepage_name, | 150 const char* codepage_name, |
156 OnStringConversionError::Type on_error, | 151 OnStringConversionError::Type on_error, |
157 std::string* encoded) { | 152 std::string* encoded) { |
158 encoded->clear(); | 153 encoded->clear(); |
159 | 154 |
160 UErrorCode status = U_ZERO_ERROR; | 155 UErrorCode status = U_ZERO_ERROR; |
161 UConverter* converter = ucnv_open(codepage_name, &status); | 156 UConverter* converter = ucnv_open(codepage_name, &status); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 buffer.get(), static_cast<int>(max_length), &status); | 283 buffer.get(), static_cast<int>(max_length), &status); |
289 if (!U_SUCCESS(status)) | 284 if (!U_SUCCESS(status)) |
290 return false; | 285 return false; |
291 normalized_utf16.assign(buffer.get(), actual_length); | 286 normalized_utf16.assign(buffer.get(), actual_length); |
292 | 287 |
293 return UTF16ToUTF8(normalized_utf16.data(), | 288 return UTF16ToUTF8(normalized_utf16.data(), |
294 normalized_utf16.length(), result); | 289 normalized_utf16.length(), result); |
295 } | 290 } |
296 | 291 |
297 } // namespace base | 292 } // namespace base |
OLD | NEW |