| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/utf_string_conversion_utils.h" | 8 #include "base/utf_string_conversion_utils.h" |
| 9 | 9 |
| 10 using base::PrepareForUTF8Output; | 10 using base::PrepareForUTF8Output; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 size_t src_len, | 25 size_t src_len, |
| 26 DEST_STRING* output) { | 26 DEST_STRING* output) { |
| 27 // ICU requires 32-bit numbers. | 27 // ICU requires 32-bit numbers. |
| 28 bool success = true; | 28 bool success = true; |
| 29 int32 src_len32 = static_cast<int32>(src_len); | 29 int32 src_len32 = static_cast<int32>(src_len); |
| 30 for (int32 i = 0; i < src_len32; i++) { | 30 for (int32 i = 0; i < src_len32; i++) { |
| 31 uint32 code_point; | 31 uint32 code_point; |
| 32 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) { | 32 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) { |
| 33 WriteUnicodeCharacter(code_point, output); | 33 WriteUnicodeCharacter(code_point, output); |
| 34 } else { | 34 } else { |
| 35 // TODO(jungshik): consider adding 'Replacement character' (U+FFFD) | 35 WriteUnicodeCharacter(0xFFFD, output); |
| 36 // in place of an invalid codepoint. | |
| 37 success = false; | 36 success = false; |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 return success; | 40 return success; |
| 42 } | 41 } |
| 43 | 42 |
| 44 } // namespace | 43 } // namespace |
| 45 | 44 |
| 46 // UTF-8 <-> Wide -------------------------------------------------------------- | 45 // UTF-8 <-> Wide -------------------------------------------------------------- |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 166 |
| 168 bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) { | 167 bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output) { |
| 169 return WideToUTF8(src, src_len, output); | 168 return WideToUTF8(src, src_len, output); |
| 170 } | 169 } |
| 171 | 170 |
| 172 std::string UTF16ToUTF8(const string16& utf16) { | 171 std::string UTF16ToUTF8(const string16& utf16) { |
| 173 return WideToUTF8(utf16); | 172 return WideToUTF8(utf16); |
| 174 } | 173 } |
| 175 | 174 |
| 176 #endif | 175 #endif |
| OLD | NEW |