Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: base/strings/string16.h

Issue 1548993002: Switch to standard integer types in base/strings/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/strings/safe_sprintf_unittest.cc ('k') | base/strings/string_number_conversions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_STRINGS_STRING16_H_ 5 #ifndef BASE_STRINGS_STRING16_H_
6 #define BASE_STRINGS_STRING16_H_ 6 #define BASE_STRINGS_STRING16_H_
7 7
8 // WHAT: 8 // WHAT:
9 // A version of std::basic_string that provides 2-byte characters even when 9 // A version of std::basic_string that provides 2-byte characters even when
10 // wchar_t is not implemented as a 2-byte type. You can access this class as 10 // wchar_t is not implemented as a 2-byte type. You can access this class as
11 // string16. We also define char16, which string16 is based upon. 11 // string16. We also define char16, which string16 is based upon.
12 // 12 //
13 // WHY: 13 // WHY:
14 // On Windows, wchar_t is 2 bytes, and it can conveniently handle UTF-16/UCS-2 14 // On Windows, wchar_t is 2 bytes, and it can conveniently handle UTF-16/UCS-2
15 // data. Plenty of existing code operates on strings encoded as UTF-16. 15 // data. Plenty of existing code operates on strings encoded as UTF-16.
16 // 16 //
17 // On many other platforms, sizeof(wchar_t) is 4 bytes by default. We can make 17 // On many other platforms, sizeof(wchar_t) is 4 bytes by default. We can make
18 // it 2 bytes by using the GCC flag -fshort-wchar. But then std::wstring fails 18 // it 2 bytes by using the GCC flag -fshort-wchar. But then std::wstring fails
19 // at run time, because it calls some functions (like wcslen) that come from 19 // at run time, because it calls some functions (like wcslen) that come from
20 // the system's native C library -- which was built with a 4-byte wchar_t! 20 // the system's native C library -- which was built with a 4-byte wchar_t!
21 // It's wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it's 21 // It's wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it's
22 // entirely improper on those systems where the encoding of wchar_t is defined 22 // entirely improper on those systems where the encoding of wchar_t is defined
23 // as UTF-32. 23 // as UTF-32.
24 // 24 //
25 // Here, we define string16, which is similar to std::wstring but replaces all 25 // Here, we define string16, which is similar to std::wstring but replaces all
26 // libc functions with custom, 2-byte-char compatible routines. It is capable 26 // libc functions with custom, 2-byte-char compatible routines. It is capable
27 // of carrying UTF-16-encoded data. 27 // of carrying UTF-16-encoded data.
28 28
29 #include <stddef.h>
30 #include <stdint.h>
29 #include <stdio.h> 31 #include <stdio.h>
30 #include <string> 32 #include <string>
31 33
32 #include "base/base_export.h" 34 #include "base/base_export.h"
33 #include "base/basictypes.h" 35 #include "build/build_config.h"
34 36
35 #if defined(WCHAR_T_IS_UTF16) 37 #if defined(WCHAR_T_IS_UTF16)
36 38
37 namespace base { 39 namespace base {
38 40
39 typedef wchar_t char16; 41 typedef wchar_t char16;
40 typedef std::wstring string16; 42 typedef std::wstring string16;
41 typedef std::char_traits<wchar_t> string16_char_traits; 43 typedef std::char_traits<wchar_t> string16_char_traits;
42 44
43 } // namespace base 45 } // namespace base
44 46
45 #elif defined(WCHAR_T_IS_UTF32) 47 #elif defined(WCHAR_T_IS_UTF32)
46 48
47 namespace base { 49 namespace base {
48 50
49 typedef uint16 char16; 51 typedef uint16_t char16;
50 52
51 // char16 versions of the functions required by string16_char_traits; these 53 // char16 versions of the functions required by string16_char_traits; these
52 // are based on the wide character functions of similar names ("w" or "wcs" 54 // are based on the wide character functions of similar names ("w" or "wcs"
53 // instead of "c16"). 55 // instead of "c16").
54 BASE_EXPORT int c16memcmp(const char16* s1, const char16* s2, size_t n); 56 BASE_EXPORT int c16memcmp(const char16* s1, const char16* s2, size_t n);
55 BASE_EXPORT size_t c16len(const char16* s); 57 BASE_EXPORT size_t c16len(const char16* s);
56 BASE_EXPORT const char16* c16memchr(const char16* s, char16 c, size_t n); 58 BASE_EXPORT const char16* c16memchr(const char16* s, char16 c, size_t n);
57 BASE_EXPORT char16* c16memmove(char16* s1, const char16* s2, size_t n); 59 BASE_EXPORT char16* c16memmove(char16* s1, const char16* s2, size_t n);
58 BASE_EXPORT char16* c16memcpy(char16* s1, const char16* s2, size_t n); 60 BASE_EXPORT char16* c16memcpy(char16* s1, const char16* s2, size_t n);
59 BASE_EXPORT char16* c16memset(char16* s, char16 c, size_t n); 61 BASE_EXPORT char16* c16memset(char16* s, char16 c, size_t n);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // boundaries, such as in statically-linked executables. 178 // boundaries, such as in statically-linked executables.
177 // 179 //
178 // TODO(mark): File this bug with Apple and update this note with a bug number. 180 // TODO(mark): File this bug with Apple and update this note with a bug number.
179 181
180 extern template 182 extern template
181 class BASE_EXPORT std::basic_string<base::char16, base::string16_char_traits>; 183 class BASE_EXPORT std::basic_string<base::char16, base::string16_char_traits>;
182 184
183 #endif // WCHAR_T_IS_UTF32 185 #endif // WCHAR_T_IS_UTF32
184 186
185 #endif // BASE_STRINGS_STRING16_H_ 187 #endif // BASE_STRINGS_STRING16_H_
OLDNEW
« no previous file with comments | « base/strings/safe_sprintf_unittest.cc ('k') | base/strings/string_number_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698