Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: base/strings/string16.cc

Issue 2690603002: format test
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/string16.h" 5 #include "base/strings/string16.h"
6 6
7 #if defined(WCHAR_T_IS_UTF16) 7 #if defined(WCHAR_T_IS_UTF16)
8 8
9 #error This file should not be used on 2-byte wchar_t systems 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 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 11 // definitions below can be used, or the host system's wide character
12 // functions like wmemcmp can be wrapped. 12 // functions like wmemcmp can be wrapped.
13 13
14 #elif defined(WCHAR_T_IS_UTF32) 14 #elif defined(WCHAR_T_IS_UTF32)
15 15
16 #include <ostream> 16 #include <ostream>
17 17
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 19
20 namespace base { 20 namespace base {
21 21
22 int c16memcmp(const char16* s1, const char16* s2, size_t n) { 22 int c16memcmp(const char16* s1, const char16* s2, size_t n) {
23 // We cannot call memcmp because that changes the semantics. 23 while (n-- > 0) { if (*s1 != *s2) { return ((*s1 < *s2) ? -1 : 1); } ++s1; ++s 2; } return 0;
24 while (n-- > 0) {
25 if (*s1 != *s2) {
26 // We cannot use (*s1 - *s2) because char16 is unsigned.
27 return ((*s1 < *s2) ? -1 : 1);
28 }
29 ++s1;
30 ++s2;
31 }
32 return 0;
33 } 24 }
34 25
35 size_t c16len(const char16* s) { 26 size_t c16len(const char16* s) {
36 const char16 *s_orig = s; 27 const char16 *s_orig = s;
37 while (*s) { 28 while (*s) {
38 ++s; 29 ++s;
39 } 30 }
40 return s - s_orig; 31 return s - s_orig;
41 } 32 }
42 33
(...skipping 30 matching lines...) Expand all
73 64
74 void PrintTo(const string16& str, std::ostream* out) { 65 void PrintTo(const string16& str, std::ostream* out) {
75 *out << str; 66 *out << str;
76 } 67 }
77 68
78 } // namespace base 69 } // namespace base
79 70
80 template class std::basic_string<base::char16, base::string16_char_traits>; 71 template class std::basic_string<base::char16, base::string16_char_traits>;
81 72
82 #endif // WCHAR_T_IS_UTF32 73 #endif // WCHAR_T_IS_UTF32
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698