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_STRING16_H_ | 5 #ifndef BASE_STRING16_H_ |
6 #define BASE_STRING16_H_ | 6 #define BASE_STRING16_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // WHAT: | 9 // WHAT: |
10 // A version of std::basic_string that provides 2-byte characters even when | 10 // A version of std::basic_string that provides 2-byte characters even when |
(...skipping 12 matching lines...) Expand all Loading... |
23 // entirely improper on those systems where the encoding of wchar_t is defined | 23 // entirely improper on those systems where the encoding of wchar_t is defined |
24 // as UTF-32. | 24 // as UTF-32. |
25 // | 25 // |
26 // Here, we define string16, which is similar to std::wstring but replaces all | 26 // Here, we define string16, which is similar to std::wstring but replaces all |
27 // libc functions with custom, 2-byte-char compatible routines. It is capable | 27 // libc functions with custom, 2-byte-char compatible routines. It is capable |
28 // of carrying UTF-16-encoded data. | 28 // of carrying UTF-16-encoded data. |
29 | 29 |
30 #include <stdio.h> | 30 #include <stdio.h> |
31 #include <string> | 31 #include <string> |
32 | 32 |
33 #include "base/base_api.h" | 33 #include "base/base_export.h" |
34 #include "base/basictypes.h" | 34 #include "base/basictypes.h" |
35 | 35 |
36 #if defined(WCHAR_T_IS_UTF16) | 36 #if defined(WCHAR_T_IS_UTF16) |
37 | 37 |
38 typedef wchar_t char16; | 38 typedef wchar_t char16; |
39 typedef std::wstring string16; | 39 typedef std::wstring string16; |
40 | 40 |
41 #elif defined(WCHAR_T_IS_UTF32) | 41 #elif defined(WCHAR_T_IS_UTF32) |
42 | 42 |
43 typedef uint16 char16; | 43 typedef uint16 char16; |
44 | 44 |
45 namespace base { | 45 namespace base { |
46 | 46 |
47 // char16 versions of the functions required by string16_char_traits; these | 47 // char16 versions of the functions required by string16_char_traits; these |
48 // are based on the wide character functions of similar names ("w" or "wcs" | 48 // are based on the wide character functions of similar names ("w" or "wcs" |
49 // instead of "c16"). | 49 // instead of "c16"). |
50 BASE_API int c16memcmp(const char16* s1, const char16* s2, size_t n); | 50 BASE_EXPORT int c16memcmp(const char16* s1, const char16* s2, size_t n); |
51 BASE_API size_t c16len(const char16* s); | 51 BASE_EXPORT size_t c16len(const char16* s); |
52 BASE_API const char16* c16memchr(const char16* s, char16 c, size_t n); | 52 BASE_EXPORT const char16* c16memchr(const char16* s, char16 c, size_t n); |
53 BASE_API char16* c16memmove(char16* s1, const char16* s2, size_t n); | 53 BASE_EXPORT char16* c16memmove(char16* s1, const char16* s2, size_t n); |
54 BASE_API char16* c16memcpy(char16* s1, const char16* s2, size_t n); | 54 BASE_EXPORT char16* c16memcpy(char16* s1, const char16* s2, size_t n); |
55 BASE_API char16* c16memset(char16* s, char16 c, size_t n); | 55 BASE_EXPORT char16* c16memset(char16* s, char16 c, size_t n); |
56 | 56 |
57 struct string16_char_traits { | 57 struct string16_char_traits { |
58 typedef char16 char_type; | 58 typedef char16 char_type; |
59 typedef int int_type; | 59 typedef int int_type; |
60 | 60 |
61 // int_type needs to be able to hold each possible value of char_type, and in | 61 // int_type needs to be able to hold each possible value of char_type, and in |
62 // addition, the distinct value of eof(). | 62 // addition, the distinct value of eof(). |
63 COMPILE_ASSERT(sizeof(int_type) > sizeof(char_type), unexpected_type_width); | 63 COMPILE_ASSERT(sizeof(int_type) > sizeof(char_type), unexpected_type_width); |
64 | 64 |
65 typedef std::streamoff off_type; | 65 typedef std::streamoff off_type; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // to occur even when a std::basic_string<> does not cross shared library | 162 // to occur even when a std::basic_string<> does not cross shared library |
163 // boundaries, such as in statically-linked executables. | 163 // boundaries, such as in statically-linked executables. |
164 // | 164 // |
165 // TODO(mark): File this bug with Apple and update this note with a bug number. | 165 // TODO(mark): File this bug with Apple and update this note with a bug number. |
166 | 166 |
167 extern template class std::basic_string<char16, base::string16_char_traits>; | 167 extern template class std::basic_string<char16, base::string16_char_traits>; |
168 | 168 |
169 typedef std::basic_string<char16, base::string16_char_traits> string16; | 169 typedef std::basic_string<char16, base::string16_char_traits> string16; |
170 | 170 |
171 namespace base { | 171 namespace base { |
172 BASE_API extern std::ostream& operator<<(std::ostream& out, | 172 BASE_EXPORT extern std::ostream& operator<<(std::ostream& out, |
173 const string16& str); | 173 const string16& str); |
174 } | 174 } |
175 | 175 |
176 #endif // WCHAR_T_IS_UTF32 | 176 #endif // WCHAR_T_IS_UTF32 |
177 | 177 |
178 #endif // BASE_STRING16_H_ | 178 #endif // BASE_STRING16_H_ |
OLD | NEW |