1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/string16.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/string16.h" 1.9 + 1.10 +#if defined(WCHAR_T_IS_UTF16) 1.11 + 1.12 +#error This file should not be used on 2-byte wchar_t systems 1.13 +// If this winds up being needed on 2-byte wchar_t systems, either the 1.14 +// definitions below can be used, or the host system's wide character 1.15 +// functions like wmemcmp can be wrapped. 1.16 + 1.17 +#elif defined(WCHAR_T_IS_UTF32) 1.18 + 1.19 +#include "base/string_util.h" 1.20 + 1.21 +namespace base { 1.22 + 1.23 +int c16memcmp(const char16* s1, const char16* s2, size_t n) { 1.24 + // We cannot call memcmp because that changes the semantics. 1.25 + while (n-- > 0) { 1.26 + if (*s1 != *s2) { 1.27 + // We cannot use (*s1 - *s2) because char16 is unsigned. 1.28 + return ((*s1 < *s2) ? -1 : 1); 1.29 + } 1.30 + ++s1; 1.31 + ++s2; 1.32 + } 1.33 + return 0; 1.34 +} 1.35 + 1.36 +size_t c16len(const char16* s) { 1.37 + const char16 *s_orig = s; 1.38 + while (*s) { 1.39 + ++s; 1.40 + } 1.41 + return s - s_orig; 1.42 +} 1.43 + 1.44 +const char16* c16memchr(const char16* s, char16 c, size_t n) { 1.45 + while (n-- > 0) { 1.46 + if (*s == c) { 1.47 + return s; 1.48 + } 1.49 + ++s; 1.50 + } 1.51 + return 0; 1.52 +} 1.53 + 1.54 +char16* c16memmove(char16* s1, const char16* s2, size_t n) { 1.55 + return reinterpret_cast<char16*>(memmove(s1, s2, n * sizeof(char16))); 1.56 +} 1.57 + 1.58 +char16* c16memcpy(char16* s1, const char16* s2, size_t n) { 1.59 + return reinterpret_cast<char16*>(memcpy(s1, s2, n * sizeof(char16))); 1.60 +} 1.61 + 1.62 +char16* c16memset(char16* s, char16 c, size_t n) { 1.63 + char16 *s_orig = s; 1.64 + while (n-- > 0) { 1.65 + *s = c; 1.66 + ++s; 1.67 + } 1.68 + return s_orig; 1.69 +} 1.70 + 1.71 +} // namespace base 1.72 + 1.73 +template class std::basic_string<char16, base::string16_char_traits>; 1.74 + 1.75 +#endif // WCHAR_T_IS_UTF32