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

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

Issue 1280473002: Update ToLower/UpperASCII API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 | « base/strings/string_util.h ('k') | base/strings/string_util_unittest.cc » ('j') | 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/string_util.h" 5 #include "base/strings/string_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <math.h> 9 #include <math.h>
10 #include <stdarg.h> 10 #include <stdarg.h>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Portable, keep scanning the rest of the format string. 141 // Portable, keep scanning the rest of the format string.
142 in_specification = false; 142 in_specification = false;
143 } 143 }
144 } 144 }
145 } 145 }
146 } 146 }
147 147
148 return true; 148 return true;
149 } 149 }
150 150
151 namespace {
152
153 template<typename StringType>
154 StringType ToLowerASCIIImpl(BasicStringPiece<StringType> str) {
155 StringType ret;
156 ret.reserve(str.size());
157 for (size_t i = 0; i < str.size(); i++)
158 ret.push_back(ToLowerASCII(str[i]));
159 return ret;
160 }
161
162 template<typename StringType>
163 StringType ToUpperASCIIImpl(BasicStringPiece<StringType> str) {
164 StringType ret;
165 ret.reserve(str.size());
166 for (size_t i = 0; i < str.size(); i++)
167 ret.push_back(ToUpperASCII(str[i]));
168 return ret;
169 }
170
171 } // namespace
172
173 std::string ToLowerASCII(StringPiece str) {
174 return ToLowerASCIIImpl<std::string>(str);
175 }
176
177 string16 ToLowerASCII(StringPiece16 str) {
178 return ToLowerASCIIImpl<string16>(str);
179 }
180
181 std::string ToUpperASCII(StringPiece str) {
182 return ToUpperASCIIImpl<std::string>(str);
183 }
184
185 string16 ToUpperASCII(StringPiece16 str) {
186 return ToUpperASCIIImpl<string16>(str);
187 }
188
151 template<class StringType> 189 template<class StringType>
152 int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a, 190 int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a,
153 BasicStringPiece<StringType> b) { 191 BasicStringPiece<StringType> b) {
154 // Find the first characters that aren't equal and compare them. If the end 192 // Find the first characters that aren't equal and compare them. If the end
155 // of one of the strings is found before a nonequal character, the lengths 193 // of one of the strings is found before a nonequal character, the lengths
156 // of the strings are compared. 194 // of the strings are compared.
157 size_t i = 0; 195 size_t i = 0;
158 while (i < a.length() && i < b.length()) { 196 while (i < a.length() && i < b.length()) {
159 typename StringType::value_type lower_a = ToLowerASCII(a[i]); 197 typename StringType::value_type lower_a = ToLowerASCII(a[i]);
160 typename StringType::value_type lower_b = ToLowerASCII(b[i]); 198 typename StringType::value_type lower_b = ToLowerASCII(b[i]);
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } // namespace 1035 } // namespace
998 1036
999 size_t strlcpy(char* dst, const char* src, size_t dst_size) { 1037 size_t strlcpy(char* dst, const char* src, size_t dst_size) {
1000 return lcpyT<char>(dst, src, dst_size); 1038 return lcpyT<char>(dst, src, dst_size);
1001 } 1039 }
1002 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1040 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1003 return lcpyT<wchar_t>(dst, src, dst_size); 1041 return lcpyT<wchar_t>(dst, src, dst_size);
1004 } 1042 }
1005 1043
1006 } // namespace base 1044 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698