| OLD | NEW |
| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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> | 29 #include <stddef.h> |
| 30 #include <stdint.h> | 30 #include <stdint.h> |
| 31 #include <stdio.h> | 31 #include <stdio.h> |
| 32 |
| 33 #include <functional> |
| 32 #include <string> | 34 #include <string> |
| 33 | 35 |
| 34 #include "base/base_export.h" | 36 #include "base/base_export.h" |
| 35 #include "build/build_config.h" | 37 #include "build/build_config.h" |
| 36 | 38 |
| 37 #if defined(WCHAR_T_IS_UTF16) | 39 #if defined(WCHAR_T_IS_UTF16) |
| 38 | 40 |
| 39 namespace base { | 41 namespace base { |
| 40 | 42 |
| 41 typedef wchar_t char16; | 43 typedef wchar_t char16; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // in which the linker does not fully coalesce symbols when dead code | 177 // in which the linker does not fully coalesce symbols when dead code |
| 176 // stripping is enabled. This bug causes the memory errors described above | 178 // stripping is enabled. This bug causes the memory errors described above |
| 177 // to occur even when a std::basic_string<> does not cross shared library | 179 // to occur even when a std::basic_string<> does not cross shared library |
| 178 // boundaries, such as in statically-linked executables. | 180 // boundaries, such as in statically-linked executables. |
| 179 // | 181 // |
| 180 // TODO(mark): File this bug with Apple and update this note with a bug number. | 182 // TODO(mark): File this bug with Apple and update this note with a bug number. |
| 181 | 183 |
| 182 extern template | 184 extern template |
| 183 class BASE_EXPORT std::basic_string<base::char16, base::string16_char_traits>; | 185 class BASE_EXPORT std::basic_string<base::char16, base::string16_char_traits>; |
| 184 | 186 |
| 187 // Specialize std::hash for base::string16. Although the style guide forbids |
| 188 // this in general, it is necessary for consistency with WCHAR_T_IS_UTF16 |
| 189 // platforms, where base::string16 is a type alias for std::wstring. |
| 190 namespace std { |
| 191 template<> |
| 192 struct hash<base::string16> { |
| 193 std::size_t operator()(const base::string16& s) const { |
| 194 std::size_t result = 0; |
| 195 for (base::char16 c : s) |
| 196 result = (result * 131) + c; |
| 197 return result; |
| 198 } |
| 199 }; |
| 200 } // namespace std |
| 201 |
| 185 #endif // WCHAR_T_IS_UTF32 | 202 #endif // WCHAR_T_IS_UTF32 |
| 186 | 203 |
| 187 #endif // BASE_STRINGS_STRING16_H_ | 204 #endif // BASE_STRINGS_STRING16_H_ |
| OLD | NEW |