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

Side by Side Diff: base/utf_string_conversions.cc

Issue 522029: If we can't read a unicode character, write the standard "unknown" (0xFFFD) c... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « base/utf_offset_string_conversions_unittest.cc ('k') | base/utf_string_conversions_unittest.cc » ('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 (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
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
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
OLDNEW
« no previous file with comments | « base/utf_offset_string_conversions_unittest.cc ('k') | base/utf_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698