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/strings/utf_string_conversion_utils.h" | 5 #include "base/strings/utf_string_conversion_utils.h" |
6 | 6 |
7 #include "base/third_party/icu/icu_utf.h" | 7 #include "base/third_party/icu/icu_utf.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Validate the value. | 64 // Validate the value. |
65 return IsValidCodepoint(*code_point); | 65 return IsValidCodepoint(*code_point); |
66 } | 66 } |
67 #endif // defined(WCHAR_T_IS_UTF32) | 67 #endif // defined(WCHAR_T_IS_UTF32) |
68 | 68 |
69 // WriteUnicodeCharacter ------------------------------------------------------- | 69 // WriteUnicodeCharacter ------------------------------------------------------- |
70 | 70 |
71 size_t WriteUnicodeCharacter(uint32 code_point, std::string* output) { | 71 size_t WriteUnicodeCharacter(uint32 code_point, std::string* output) { |
72 if (code_point <= 0x7f) { | 72 if (code_point <= 0x7f) { |
73 // Fast path the common case of one byte. | 73 // Fast path the common case of one byte. |
74 output->push_back(code_point); | 74 output->push_back(static_cast<char>(code_point)); |
75 return 1; | 75 return 1; |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 // CBU8_APPEND_UNSAFE can append up to 4 bytes. | 79 // CBU8_APPEND_UNSAFE can append up to 4 bytes. |
80 size_t char_offset = output->length(); | 80 size_t char_offset = output->length(); |
81 size_t original_char_offset = char_offset; | 81 size_t original_char_offset = char_offset; |
82 output->resize(char_offset + CBU8_MAX_LENGTH); | 82 output->resize(char_offset + CBU8_MAX_LENGTH); |
83 | 83 |
84 CBU8_APPEND_UNSAFE(&(*output)[0], char_offset, code_point); | 84 CBU8_APPEND_UNSAFE(&(*output)[0], char_offset, code_point); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // character. | 139 // character. |
140 output->reserve(src_len / 2); | 140 output->reserve(src_len / 2); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 // Instantiate versions we know callers will need. | 144 // Instantiate versions we know callers will need. |
145 template void PrepareForUTF16Or32Output(const char*, size_t, std::wstring*); | 145 template void PrepareForUTF16Or32Output(const char*, size_t, std::wstring*); |
146 template void PrepareForUTF16Or32Output(const char*, size_t, string16*); | 146 template void PrepareForUTF16Or32Output(const char*, size_t, string16*); |
147 | 147 |
148 } // namespace base | 148 } // namespace base |
OLD | NEW |