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

Side by Side Diff: base/utf_offset_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 | « no previous file | base/utf_offset_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_offset_string_conversions.h" 5 #include "base/utf_offset_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::PrepareForUTF16Or32Output; 10 using base::PrepareForUTF16Or32Output;
(...skipping 18 matching lines...) Expand all
29 // ICU requires 32-bit numbers. 29 // ICU requires 32-bit numbers.
30 bool success = true; 30 bool success = true;
31 int32 src_len32 = static_cast<int32>(src_len); 31 int32 src_len32 = static_cast<int32>(src_len);
32 for (int32 i = 0; i < src_len32; i++) { 32 for (int32 i = 0; i < src_len32; i++) {
33 uint32 code_point; 33 uint32 code_point;
34 size_t original_i = i; 34 size_t original_i = i;
35 size_t chars_written = 0; 35 size_t chars_written = 0;
36 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) { 36 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) {
37 chars_written = WriteUnicodeCharacter(code_point, output); 37 chars_written = WriteUnicodeCharacter(code_point, output);
38 } else { 38 } else {
39 // TODO(jungshik): consider adding 'Replacement character' (U+FFFD) 39 chars_written = WriteUnicodeCharacter(0xFFFD, output);
40 // in place of an invalid codepoint.
41 success = false; 40 success = false;
42 } 41 }
43 if ((output_offset != std::wstring::npos) && 42 if ((output_offset != std::wstring::npos) &&
44 (*offset_for_adjustment > original_i)) { 43 (*offset_for_adjustment > original_i)) {
45 // NOTE: ReadUnicodeCharacter() adjusts |i| to point _at_ the last 44 // NOTE: ReadUnicodeCharacter() adjusts |i| to point _at_ the last
46 // character read, not after it (so that incrementing it in the loop 45 // character read, not after it (so that incrementing it in the loop
47 // increment will place it at the right location), so we need to account 46 // increment will place it at the right location), so we need to account
48 // for that in determining the amount that was read. 47 // for that in determining the amount that was read.
49 if (*offset_for_adjustment <= static_cast<size_t>(i)) 48 if (*offset_for_adjustment <= static_cast<size_t>(i))
50 output_offset = std::wstring::npos; 49 output_offset = std::wstring::npos;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 112
114 std::wstring UTF16ToWideAndAdjustOffset(const string16& utf16, 113 std::wstring UTF16ToWideAndAdjustOffset(const string16& utf16,
115 size_t* offset_for_adjustment) { 114 size_t* offset_for_adjustment) {
116 std::wstring ret; 115 std::wstring ret;
117 UTF16ToWideAndAdjustOffset(utf16.data(), utf16.length(), &ret, 116 UTF16ToWideAndAdjustOffset(utf16.data(), utf16.length(), &ret,
118 offset_for_adjustment); 117 offset_for_adjustment);
119 return ret; 118 return ret;
120 } 119 }
121 120
122 #endif // defined(WCHAR_T_IS_UTF32) 121 #endif // defined(WCHAR_T_IS_UTF32)
OLDNEW
« no previous file with comments | « no previous file | base/utf_offset_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698