| OLD | NEW |
| 1 // Copyright (c) 2009 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 #ifndef BASE_UTF_STRING_CONVERSION_UTILS_H_ | 5 #ifndef BASE_UTF_STRING_CONVERSION_UTILS_H_ |
| 6 #define BASE_UTF_STRING_CONVERSION_UTILS_H_ | 6 #define BASE_UTF_STRING_CONVERSION_UTILS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // This should only be used by the various UTF string conversion files. | 9 // This should only be used by the various UTF string conversion files. |
| 10 | 10 |
| 11 #include "base/base_api.h" |
| 11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 inline bool IsValidCodepoint(uint32 code_point) { | 16 inline bool IsValidCodepoint(uint32 code_point) { |
| 16 // Excludes the surrogate code points ([0xD800, 0xDFFF]) and | 17 // Excludes the surrogate code points ([0xD800, 0xDFFF]) and |
| 17 // codepoints larger than 0x10FFFF (the highest codepoint allowed). | 18 // codepoints larger than 0x10FFFF (the highest codepoint allowed). |
| 18 // Non-characters and unassigned codepoints are allowed. | 19 // Non-characters and unassigned codepoints are allowed. |
| 19 return code_point < 0xD800u || | 20 return code_point < 0xD800u || |
| 20 (code_point >= 0xE000u && code_point <= 0x10FFFFu); | 21 (code_point >= 0xE000u && code_point <= 0x10FFFFu); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 bool ReadUnicodeCharacter(const wchar_t* src, | 54 bool ReadUnicodeCharacter(const wchar_t* src, |
| 54 int32 src_len, | 55 int32 src_len, |
| 55 int32* char_index, | 56 int32* char_index, |
| 56 uint32* code_point); | 57 uint32* code_point); |
| 57 #endif // defined(WCHAR_T_IS_UTF32) | 58 #endif // defined(WCHAR_T_IS_UTF32) |
| 58 | 59 |
| 59 // WriteUnicodeCharacter ------------------------------------------------------- | 60 // WriteUnicodeCharacter ------------------------------------------------------- |
| 60 | 61 |
| 61 // Appends a UTF-8 character to the given 8-bit string. Returns the number of | 62 // Appends a UTF-8 character to the given 8-bit string. Returns the number of |
| 62 // bytes written. | 63 // bytes written. |
| 63 size_t WriteUnicodeCharacter(uint32 code_point, std::string* output); | 64 // TODO(brettw) Bug 79631: This function should not be exposed. |
| 65 BASE_API size_t WriteUnicodeCharacter(uint32 code_point, std::string* output); |
| 64 | 66 |
| 65 // Appends the given code point as a UTF-16 character to the given 16-bit | 67 // Appends the given code point as a UTF-16 character to the given 16-bit |
| 66 // string. Returns the number of 16-bit values written. | 68 // string. Returns the number of 16-bit values written. |
| 67 size_t WriteUnicodeCharacter(uint32 code_point, string16* output); | 69 size_t WriteUnicodeCharacter(uint32 code_point, string16* output); |
| 68 | 70 |
| 69 #if defined(WCHAR_T_IS_UTF32) | 71 #if defined(WCHAR_T_IS_UTF32) |
| 70 // Appends the given UTF-32 character to the given 32-bit string. Returns the | 72 // Appends the given UTF-32 character to the given 32-bit string. Returns the |
| 71 // number of 32-bit values written. | 73 // number of 32-bit values written. |
| 72 inline size_t WriteUnicodeCharacter(uint32 code_point, std::wstring* output) { | 74 inline size_t WriteUnicodeCharacter(uint32 code_point, std::wstring* output) { |
| 73 // This is the easy case, just append the character. | 75 // This is the easy case, just append the character. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 void PrepareForUTF8Output(const CHAR* src, size_t src_len, std::string* output); | 88 void PrepareForUTF8Output(const CHAR* src, size_t src_len, std::string* output); |
| 87 | 89 |
| 88 // Prepares an output buffer (containing either UTF-16 or -32 data) given some | 90 // Prepares an output buffer (containing either UTF-16 or -32 data) given some |
| 89 // UTF-8 input that will be converted to it. See PrepareForUTF8Output(). | 91 // UTF-8 input that will be converted to it. See PrepareForUTF8Output(). |
| 90 template<typename STRING> | 92 template<typename STRING> |
| 91 void PrepareForUTF16Or32Output(const char* src, size_t src_len, STRING* output); | 93 void PrepareForUTF16Or32Output(const char* src, size_t src_len, STRING* output); |
| 92 | 94 |
| 93 } // namespace base | 95 } // namespace base |
| 94 | 96 |
| 95 #endif // BASE_UTF_STRING_CONVERSION_UTILS_H_ | 97 #endif // BASE_UTF_STRING_CONVERSION_UTILS_H_ |
| OLD | NEW |