| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/string16.h" | 5 #include "base/string16.h" |
| 6 | 6 |
| 7 #if defined(WCHAR_T_IS_UTF16) | 7 #if defined(WCHAR_T_IS_UTF16) |
| 8 | 8 |
| 9 #error This file should not be used on 2-byte wchar_t systems | 9 #error This file should not be used on 2-byte wchar_t systems |
| 10 // If this winds up being needed on 2-byte wchar_t systems, either the | 10 // If this winds up being needed on 2-byte wchar_t systems, either the |
| 11 // definitions below can be used, or the host system's wide character | 11 // definitions below can be used, or the host system's wide character |
| 12 // functions like wmemcmp can be wrapped. | 12 // functions like wmemcmp can be wrapped. |
| 13 | 13 |
| 14 #elif defined(WCHAR_T_IS_UTF32) | 14 #elif defined(WCHAR_T_IS_UTF32) |
| 15 | 15 |
| 16 #include "base/string_util.h" |
| 17 |
| 16 namespace base { | 18 namespace base { |
| 17 | 19 |
| 18 int c16memcmp(const char16* s1, const char16* s2, size_t n) { | 20 int c16memcmp(const char16* s1, const char16* s2, size_t n) { |
| 19 // We cannot call memcmp because that changes the semantics. | 21 // We cannot call memcmp because that changes the semantics. |
| 20 while (n-- > 0) { | 22 while (n-- > 0) { |
| 21 if (*s1 != *s2) { | 23 if (*s1 != *s2) { |
| 22 // We cannot use (*s1 - *s2) because char16 is unsigned. | 24 // We cannot use (*s1 - *s2) because char16 is unsigned. |
| 23 return ((*s1 < *s2) ? -1 : 1); | 25 return ((*s1 < *s2) ? -1 : 1); |
| 24 } | 26 } |
| 25 ++s1; | 27 ++s1; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 char16 *s_orig = s; | 60 char16 *s_orig = s; |
| 59 while (n-- > 0) { | 61 while (n-- > 0) { |
| 60 *s = c; | 62 *s = c; |
| 61 ++s; | 63 ++s; |
| 62 } | 64 } |
| 63 return s_orig; | 65 return s_orig; |
| 64 } | 66 } |
| 65 | 67 |
| 66 } // namespace base | 68 } // namespace base |
| 67 | 69 |
| 70 std::ostream& operator<<(std::ostream& out, const string16& str) { |
| 71 return out << UTF16ToUTF8(str); |
| 72 } |
| 73 |
| 68 #endif // WCHAR_T_IS_UTF32 | 74 #endif // WCHAR_T_IS_UTF32 |
| OLD | NEW |