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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_EXPORT size_t WriteUnicodeCharacter(uint32 code_point, | 65 BASE_EXPORT size_t WriteUnicodeCharacter(uint32 code_point, |
66 std::string* output); | 66 std::string* output); |
67 | 67 |
68 // Appends the given code point as a UTF-16 character to the given 16-bit | 68 // Appends the given code point as a UTF-16 character to the given 16-bit |
69 // string. Returns the number of 16-bit values written. | 69 // string. Returns the number of 16-bit values written. |
70 size_t WriteUnicodeCharacter(uint32 code_point, string16* output); | 70 BASE_EXPORT size_t WriteUnicodeCharacter(uint32 code_point, string16* output); |
71 | 71 |
72 #if defined(WCHAR_T_IS_UTF32) | 72 #if defined(WCHAR_T_IS_UTF32) |
73 // Appends the given UTF-32 character to the given 32-bit string. Returns the | 73 // Appends the given UTF-32 character to the given 32-bit string. Returns the |
74 // number of 32-bit values written. | 74 // number of 32-bit values written. |
75 inline size_t WriteUnicodeCharacter(uint32 code_point, std::wstring* output) { | 75 inline size_t WriteUnicodeCharacter(uint32 code_point, std::wstring* output) { |
76 // This is the easy case, just append the character. | 76 // This is the easy case, just append the character. |
77 output->push_back(code_point); | 77 output->push_back(code_point); |
78 return 1; | 78 return 1; |
79 } | 79 } |
80 #endif // defined(WCHAR_T_IS_UTF32) | 80 #endif // defined(WCHAR_T_IS_UTF32) |
81 | 81 |
82 // Generalized Unicode converter ----------------------------------------------- | 82 // Generalized Unicode converter ----------------------------------------------- |
83 | 83 |
84 // Guesses the length of the output in UTF-8 in bytes, clears that output | 84 // Guesses the length of the output in UTF-8 in bytes, clears that output |
85 // string, and reserves that amount of space. We assume that the input | 85 // string, and reserves that amount of space. We assume that the input |
86 // character types are unsigned, which will be true for UTF-16 and -32 on our | 86 // character types are unsigned, which will be true for UTF-16 and -32 on our |
87 // systems. | 87 // systems. |
88 template<typename CHAR> | 88 template<typename CHAR> |
89 void PrepareForUTF8Output(const CHAR* src, size_t src_len, std::string* output); | 89 void PrepareForUTF8Output(const CHAR* src, size_t src_len, std::string* output); |
90 | 90 |
91 // Prepares an output buffer (containing either UTF-16 or -32 data) given some | 91 // Prepares an output buffer (containing either UTF-16 or -32 data) given some |
92 // UTF-8 input that will be converted to it. See PrepareForUTF8Output(). | 92 // UTF-8 input that will be converted to it. See PrepareForUTF8Output(). |
93 template<typename STRING> | 93 template<typename STRING> |
94 void PrepareForUTF16Or32Output(const char* src, size_t src_len, STRING* output); | 94 void PrepareForUTF16Or32Output(const char* src, size_t src_len, STRING* output); |
95 | 95 |
96 } // namespace base | 96 } // namespace base |
97 | 97 |
98 #endif // BASE_UTF_STRING_CONVERSION_UTILS_H_ | 98 #endif // BASE_UTF_STRING_CONVERSION_UTILS_H_ |
OLD | NEW |