summaryrefslogtreecommitdiffstats
path: root/base/string16.cc
diff options
context:
space:
mode:
authormmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-27 20:57:35 +0000
committermmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-27 20:57:35 +0000
commitd13701900a71240fe1b4074b778133ba9a3461e9 (patch)
tree3ca3fd78ec07a47dcc2cad83defb977b0ad61e81 /base/string16.cc
parentb8c87bb8ea9f514a8f09a0f2154f8469ba7faf00 (diff)
downloadchromium_src-d13701900a71240fe1b4074b778133ba9a3461e9.zip
chromium_src-d13701900a71240fe1b4074b778133ba9a3461e9.tar.gz
chromium_src-d13701900a71240fe1b4074b778133ba9a3461e9.tar.bz2
Move std::string16 to base::string16. Don't pollute the std namespace. Don't
assume that all string types can be represented as std::basic_string<CHAR>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string16.cc')
-rw-r--r--base/string16.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/base/string16.cc b/base/string16.cc
new file mode 100644
index 0000000..2a7ec9c
--- /dev/null
+++ b/base/string16.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/string16.h"
+
+#if defined(WCHAR_T_IS_UTF16)
+
+#error This file should not be used on 2-byte wchar_t systems
+// If this winds up being needed on 2-byte wchar_t systems, either the
+// definitions below can be used, or the host system's wide character
+// functions like wmemcmp can be wrapped.
+
+#elif defined(WCHAR_T_IS_UTF32)
+
+namespace base {
+
+int c16memcmp(const char16* s1, const char16* s2, size_t n) {
+ // We cannot call memcmp because that changes the semantics.
+ while (n-- > 0) {
+ if (*s1 != *s2) {
+ // We cannot use (*s1 - *s2) because char16 is unsigned.
+ return ((*s1 < *s2) ? -1 : 1);
+ }
+ ++s1;
+ ++s2;
+ }
+ return 0;
+}
+
+size_t c16len(const char16* s) {
+ const char16 *s_orig = s;
+ while (*s) {
+ ++s;
+ }
+ return s - s_orig;
+}
+
+const char16* c16memchr(const char16* s, char16 c, size_t n) {
+ while (n-- > 0) {
+ if (*s == c) {
+ return s;
+ }
+ ++s;
+ }
+ return 0;
+}
+
+char16* c16memmove(char16* s1, const char16* s2, size_t n) {
+ return reinterpret_cast<char16*>(memmove(s1, s2, n * sizeof(char16)));
+}
+
+char16* c16memcpy(char16* s1, const char16* s2, size_t n) {
+ return reinterpret_cast<char16*>(memcpy(s1, s2, n * sizeof(char16)));
+}
+
+char16* c16memset(char16* s, char16 c, size_t n) {
+ char16 *s_orig = s;
+ while (n-- > 0) {
+ *s = c;
+ ++s;
+ }
+ return s_orig;
+}
+
+} // namespace base
+
+#endif // WCHAR_T_IS_UTF32