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

Side by Side Diff: base/strings/utf_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
« no previous file with comments | « base/strings/utf_string_conversions.h ('k') | base/strings/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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 6
7 #include <stdint.h>
8
7 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
8 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversion_utils.h" 11 #include "base/strings/utf_string_conversion_utils.h"
12 #include "build/build_config.h"
10 13
11 namespace base { 14 namespace base {
12 15
13 namespace { 16 namespace {
14 17
15 // Generalized Unicode converter ----------------------------------------------- 18 // Generalized Unicode converter -----------------------------------------------
16 19
17 // Converts the given source Unicode character type to the given destination 20 // Converts the given source Unicode character type to the given destination
18 // Unicode character type as a STL string. The given input buffer and size 21 // Unicode character type as a STL string. The given input buffer and size
19 // determine the source, and the given output STL string will be replaced by 22 // determine the source, and the given output STL string will be replaced by
20 // the result. 23 // the result.
21 template<typename SRC_CHAR, typename DEST_STRING> 24 template<typename SRC_CHAR, typename DEST_STRING>
22 bool ConvertUnicode(const SRC_CHAR* src, 25 bool ConvertUnicode(const SRC_CHAR* src,
23 size_t src_len, 26 size_t src_len,
24 DEST_STRING* output) { 27 DEST_STRING* output) {
25 // ICU requires 32-bit numbers. 28 // ICU requires 32-bit numbers.
26 bool success = true; 29 bool success = true;
27 int32 src_len32 = static_cast<int32>(src_len); 30 int32_t src_len32 = static_cast<int32_t>(src_len);
28 for (int32 i = 0; i < src_len32; i++) { 31 for (int32_t i = 0; i < src_len32; i++) {
29 uint32 code_point; 32 uint32_t code_point;
30 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) { 33 if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) {
31 WriteUnicodeCharacter(code_point, output); 34 WriteUnicodeCharacter(code_point, output);
32 } else { 35 } else {
33 WriteUnicodeCharacter(0xFFFD, output); 36 WriteUnicodeCharacter(0xFFFD, output);
34 success = false; 37 success = false;
35 } 38 }
36 } 39 }
37 40
38 return success; 41 return success;
39 } 42 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 DCHECK(IsStringASCII(ascii)) << ascii; 222 DCHECK(IsStringASCII(ascii)) << ascii;
220 return string16(ascii.begin(), ascii.end()); 223 return string16(ascii.begin(), ascii.end());
221 } 224 }
222 225
223 std::string UTF16ToASCII(StringPiece16 utf16) { 226 std::string UTF16ToASCII(StringPiece16 utf16) {
224 DCHECK(IsStringASCII(utf16)) << UTF16ToUTF8(utf16); 227 DCHECK(IsStringASCII(utf16)) << UTF16ToUTF8(utf16);
225 return std::string(utf16.begin(), utf16.end()); 228 return std::string(utf16.begin(), utf16.end());
226 } 229 }
227 230
228 } // namespace base 231 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/utf_string_conversions.h ('k') | base/strings/utf_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698