ipc/chromium/src/base/string16.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/string16.h"
michael@0 6
michael@0 7 #if defined(WCHAR_T_IS_UTF16)
michael@0 8
michael@0 9 #error This file should not be used on 2-byte wchar_t systems
michael@0 10 // If this winds up being needed on 2-byte wchar_t systems, either the
michael@0 11 // definitions below can be used, or the host system's wide character
michael@0 12 // functions like wmemcmp can be wrapped.
michael@0 13
michael@0 14 #elif defined(WCHAR_T_IS_UTF32)
michael@0 15
michael@0 16 #include "base/string_util.h"
michael@0 17
michael@0 18 namespace base {
michael@0 19
michael@0 20 int c16memcmp(const char16* s1, const char16* s2, size_t n) {
michael@0 21 // We cannot call memcmp because that changes the semantics.
michael@0 22 while (n-- > 0) {
michael@0 23 if (*s1 != *s2) {
michael@0 24 // We cannot use (*s1 - *s2) because char16 is unsigned.
michael@0 25 return ((*s1 < *s2) ? -1 : 1);
michael@0 26 }
michael@0 27 ++s1;
michael@0 28 ++s2;
michael@0 29 }
michael@0 30 return 0;
michael@0 31 }
michael@0 32
michael@0 33 size_t c16len(const char16* s) {
michael@0 34 const char16 *s_orig = s;
michael@0 35 while (*s) {
michael@0 36 ++s;
michael@0 37 }
michael@0 38 return s - s_orig;
michael@0 39 }
michael@0 40
michael@0 41 const char16* c16memchr(const char16* s, char16 c, size_t n) {
michael@0 42 while (n-- > 0) {
michael@0 43 if (*s == c) {
michael@0 44 return s;
michael@0 45 }
michael@0 46 ++s;
michael@0 47 }
michael@0 48 return 0;
michael@0 49 }
michael@0 50
michael@0 51 char16* c16memmove(char16* s1, const char16* s2, size_t n) {
michael@0 52 return reinterpret_cast<char16*>(memmove(s1, s2, n * sizeof(char16)));
michael@0 53 }
michael@0 54
michael@0 55 char16* c16memcpy(char16* s1, const char16* s2, size_t n) {
michael@0 56 return reinterpret_cast<char16*>(memcpy(s1, s2, n * sizeof(char16)));
michael@0 57 }
michael@0 58
michael@0 59 char16* c16memset(char16* s, char16 c, size_t n) {
michael@0 60 char16 *s_orig = s;
michael@0 61 while (n-- > 0) {
michael@0 62 *s = c;
michael@0 63 ++s;
michael@0 64 }
michael@0 65 return s_orig;
michael@0 66 }
michael@0 67
michael@0 68 } // namespace base
michael@0 69
michael@0 70 template class std::basic_string<char16, base::string16_char_traits>;
michael@0 71
michael@0 72 #endif // WCHAR_T_IS_UTF32

mercurial