michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/string16.h" michael@0: michael@0: #if defined(WCHAR_T_IS_UTF16) michael@0: michael@0: #error This file should not be used on 2-byte wchar_t systems michael@0: // If this winds up being needed on 2-byte wchar_t systems, either the michael@0: // definitions below can be used, or the host system's wide character michael@0: // functions like wmemcmp can be wrapped. michael@0: michael@0: #elif defined(WCHAR_T_IS_UTF32) michael@0: michael@0: #include "base/string_util.h" michael@0: michael@0: namespace base { michael@0: michael@0: int c16memcmp(const char16* s1, const char16* s2, size_t n) { michael@0: // We cannot call memcmp because that changes the semantics. michael@0: while (n-- > 0) { michael@0: if (*s1 != *s2) { michael@0: // We cannot use (*s1 - *s2) because char16 is unsigned. michael@0: return ((*s1 < *s2) ? -1 : 1); michael@0: } michael@0: ++s1; michael@0: ++s2; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: size_t c16len(const char16* s) { michael@0: const char16 *s_orig = s; michael@0: while (*s) { michael@0: ++s; michael@0: } michael@0: return s - s_orig; michael@0: } michael@0: michael@0: const char16* c16memchr(const char16* s, char16 c, size_t n) { michael@0: while (n-- > 0) { michael@0: if (*s == c) { michael@0: return s; michael@0: } michael@0: ++s; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: char16* c16memmove(char16* s1, const char16* s2, size_t n) { michael@0: return reinterpret_cast(memmove(s1, s2, n * sizeof(char16))); michael@0: } michael@0: michael@0: char16* c16memcpy(char16* s1, const char16* s2, size_t n) { michael@0: return reinterpret_cast(memcpy(s1, s2, n * sizeof(char16))); michael@0: } michael@0: michael@0: char16* c16memset(char16* s, char16 c, size_t n) { michael@0: char16 *s_orig = s; michael@0: while (n-- > 0) { michael@0: *s = c; michael@0: ++s; michael@0: } michael@0: return s_orig; michael@0: } michael@0: michael@0: } // namespace base michael@0: michael@0: template class std::basic_string; michael@0: michael@0: #endif // WCHAR_T_IS_UTF32