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

Side by Side Diff: base/strings/utf_offset_string_conversions.cc

Issue 1548993002: Switch to standard integer types in base/strings/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/strings/utf_offset_string_conversions.h" 5 #include "base/strings/utf_offset_string_conversions.h"
6 6
7 #include <stdint.h>
8
7 #include <algorithm> 9 #include <algorithm>
8 10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
12 #include "base/strings/utf_string_conversion_utils.h" 14 #include "base/strings/utf_string_conversion_utils.h"
13 15
14 namespace base { 16 namespace base {
15 17
16 OffsetAdjuster::Adjustment::Adjustment(size_t original_offset, 18 OffsetAdjuster::Adjustment::Adjustment(size_t original_offset,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // It will always be sorted by increasing offset. 183 // It will always be sorted by increasing offset.
182 template<typename SrcChar, typename DestStdString> 184 template<typename SrcChar, typename DestStdString>
183 bool ConvertUnicode(const SrcChar* src, 185 bool ConvertUnicode(const SrcChar* src,
184 size_t src_len, 186 size_t src_len,
185 DestStdString* output, 187 DestStdString* output,
186 OffsetAdjuster::Adjustments* adjustments) { 188 OffsetAdjuster::Adjustments* adjustments) {
187 if (adjustments) 189 if (adjustments)
188 adjustments->clear(); 190 adjustments->clear();
189 // ICU requires 32-bit numbers. 191 // ICU requires 32-bit numbers.
190 bool success = true; 192 bool success = true;
191 int32 src_len32 = static_cast<int32>(src_len); 193 int32_t src_len32 = static_cast<int32_t>(src_len);
192 for (int32 i = 0; i < src_len32; i++) { 194 for (int32_t i = 0; i < src_len32; i++) {
193 uint32 code_point; 195 uint32_t code_point;
194 size_t original_i = i; 196 size_t original_i = i;
195 size_t chars_written = 0; 197 size_t chars_written = 0;
196 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) { 198 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) {
197 chars_written = WriteUnicodeCharacter(code_point, output); 199 chars_written = WriteUnicodeCharacter(code_point, output);
198 } else { 200 } else {
199 chars_written = WriteUnicodeCharacter(0xFFFD, output); 201 chars_written = WriteUnicodeCharacter(0xFFFD, output);
200 success = false; 202 success = false;
201 } 203 }
202 204
203 // Only bother writing an adjustment if this modification changed the 205 // Only bother writing an adjustment if this modification changed the
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 LimitOffset<base::StringPiece16>(utf16.length())); 253 LimitOffset<base::StringPiece16>(utf16.length()));
252 std::string result; 254 std::string result;
253 PrepareForUTF8Output(utf16.data(), utf16.length(), &result); 255 PrepareForUTF8Output(utf16.data(), utf16.length(), &result);
254 OffsetAdjuster::Adjustments adjustments; 256 OffsetAdjuster::Adjustments adjustments;
255 ConvertUnicode(utf16.data(), utf16.length(), &result, &adjustments); 257 ConvertUnicode(utf16.data(), utf16.length(), &result, &adjustments);
256 OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment); 258 OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment);
257 return result; 259 return result;
258 } 260 }
259 261
260 } // namespace base 262 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/utf_offset_string_conversions.h ('k') | base/strings/utf_offset_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698