OLD | NEW |
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 #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 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // ReadUnicodeCharacter -------------------------------------------------------- | 32 // ReadUnicodeCharacter -------------------------------------------------------- |
33 | 33 |
34 // Reads a UTF-8 stream, placing the next code point into the given output | 34 // Reads a UTF-8 stream, placing the next code point into the given output |
35 // |*code_point|. |src| represents the entire string to read, and |*char_index| | 35 // |*code_point|. |src| represents the entire string to read, and |*char_index| |
36 // is the character offset within the string to start reading at. |*char_index| | 36 // is the character offset within the string to start reading at. |*char_index| |
37 // will be updated to index the last character read, such that incrementing it | 37 // will be updated to index the last character read, such that incrementing it |
38 // (as in a for loop) will take the reader to the next character. | 38 // (as in a for loop) will take the reader to the next character. |
39 // | 39 // |
40 // Returns true on success. On false, |*code_point| will be invalid. | 40 // Returns true on success. On false, |*code_point| will be invalid. |
41 bool ReadUnicodeCharacter(const char* src, | 41 BASE_API bool ReadUnicodeCharacter(const char* src, |
42 int32 src_len, | 42 int32 src_len, |
43 int32* char_index, | 43 int32* char_index, |
44 uint32* code_point_out); | 44 uint32* code_point_out); |
45 | 45 |
46 // Reads a UTF-16 character. The usage is the same as the 8-bit version above. | 46 // Reads a UTF-16 character. The usage is the same as the 8-bit version above. |
47 bool ReadUnicodeCharacter(const char16* src, | 47 BASE_API bool ReadUnicodeCharacter(const char16* src, |
48 int32 src_len, | 48 int32 src_len, |
49 int32* char_index, | 49 int32* char_index, |
50 uint32* code_point); | 50 uint32* code_point); |
51 | 51 |
52 #if defined(WCHAR_T_IS_UTF32) | 52 #if defined(WCHAR_T_IS_UTF32) |
53 // Reads UTF-32 character. The usage is the same as the 8-bit version above. | 53 // Reads UTF-32 character. The usage is the same as the 8-bit version above. |
54 bool ReadUnicodeCharacter(const wchar_t* src, | 54 BASE_API bool ReadUnicodeCharacter(const wchar_t* src, |
55 int32 src_len, | 55 int32 src_len, |
56 int32* char_index, | 56 int32* char_index, |
57 uint32* code_point); | 57 uint32* code_point); |
58 #endif // defined(WCHAR_T_IS_UTF32) | 58 #endif // defined(WCHAR_T_IS_UTF32) |
59 | 59 |
60 // WriteUnicodeCharacter ------------------------------------------------------- | 60 // WriteUnicodeCharacter ------------------------------------------------------- |
61 | 61 |
62 // 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 |
63 // bytes written. | 63 // bytes written. |
64 // TODO(brettw) Bug 79631: This function should not be exposed. | 64 // TODO(brettw) Bug 79631: This function should not be exposed. |
65 BASE_API size_t WriteUnicodeCharacter(uint32 code_point, std::string* output); | 65 BASE_API size_t WriteUnicodeCharacter(uint32 code_point, std::string* output); |
66 | 66 |
67 // 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 |
(...skipping 20 matching lines...) Expand all Loading... |
88 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); |
89 | 89 |
90 // 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 |
91 // UTF-8 input that will be converted to it. See PrepareForUTF8Output(). | 91 // UTF-8 input that will be converted to it. See PrepareForUTF8Output(). |
92 template<typename STRING> | 92 template<typename STRING> |
93 void PrepareForUTF16Or32Output(const char* src, size_t src_len, STRING* output); | 93 void PrepareForUTF16Or32Output(const char* src, size_t src_len, STRING* output); |
94 | 94 |
95 } // namespace base | 95 } // namespace base |
96 | 96 |
97 #endif // BASE_UTF_STRING_CONVERSION_UTILS_H_ | 97 #endif // BASE_UTF_STRING_CONVERSION_UTILS_H_ |
OLD | NEW |