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
3 // found in the LICENSE file.
5 #include "base/strings/string16.h"
7 #if defined(WCHAR_T_IS_UTF16)
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
11 // definitions below can be used, or the host system's wide character
12 // functions like wmemcmp can be wrapped.
14 #elif defined(WCHAR_T_IS_UTF32)
18 #include "base/strings/utf_string_conversions.h"
22 int c16memcmp(const char16
* s1
, const char16
* s2
, size_t n
) {
23 // We cannot call memcmp because that changes the semantics.
26 // We cannot use (*s1 - *s2) because char16 is unsigned.
27 return ((*s1
< *s2
) ? -1 : 1);
35 size_t c16len(const char16
* s
) {
36 const char16
*s_orig
= s
;
43 const char16
* c16memchr(const char16
* s
, char16 c
, size_t n
) {
53 char16
* c16memmove(char16
* s1
, const char16
* s2
, size_t n
) {
54 return static_cast<char16
*>(memmove(s1
, s2
, n
* sizeof(char16
)));
57 char16
* c16memcpy(char16
* s1
, const char16
* s2
, size_t n
) {
58 return static_cast<char16
*>(memcpy(s1
, s2
, n
* sizeof(char16
)));
61 char16
* c16memset(char16
* s
, char16 c
, size_t n
) {
70 std::ostream
& operator<<(std::ostream
& out
, const string16
& str
) {
71 return out
<< UTF16ToUTF8(str
);
74 void PrintTo(const string16
& str
, std::ostream
* out
) {
80 template class std::basic_string
<base::char16
, base::string16_char_traits
>;
82 #endif // WCHAR_T_IS_UTF32