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

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
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 template<typename StringType>
152 StringType ToLowerASCIIT(BasicStringPiece<StringType> str) {
153 StringType ret;
154 ret.reserve(str.size());
155 for (size_t i = 0; i < str.size(); i++)
156 ret.push_back(ToLowerASCII(str[i]));
157 return ret;
158 }
159
160 std::string ToLowerASCII(StringPiece str) {
161 return ToLowerASCIIT<std::string>(str);
162 }
163
164 string16 ToLowerASCII(StringPiece16 str) {
165 return ToLowerASCIIT<string16>(str);
166 }
167
168 template<typename StringType>
169 StringType ToUpperASCIIT(BasicStringPiece<StringType> str) {
170 StringType ret;
171 ret.reserve(str.size());
172 for (size_t i = 0; i < str.size(); i++)
173 ret.push_back(ToUpperASCII(str[i]));
174 return ret;
175 }
176
177 std::string ToUpperASCII(StringPiece str) {
178 return ToUpperASCIIT<std::string>(str);
179 }
180
181 string16 ToUpperASCII(StringPiece16 str) {
182 return ToUpperASCIIT<string16>(str);
183 }
184
151 template<class StringType> 185 template<class StringType>
152 int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a, 186 int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a,
153 BasicStringPiece<StringType> b) { 187 BasicStringPiece<StringType> b) {
154 // Find the first characters that aren't equal and compare them. If the end 188 // 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 189 // of one of the strings is found before a nonequal character, the lengths
156 // of the strings are compared. 190 // of the strings are compared.
157 size_t i = 0; 191 size_t i = 0;
158 while (i < a.length() && i < b.length()) { 192 while (i < a.length() && i < b.length()) {
159 typename StringType::value_type lower_a = ToLowerASCII(a[i]); 193 typename StringType::value_type lower_a = ToLowerASCII(a[i]);
160 typename StringType::value_type lower_b = ToLowerASCII(b[i]); 194 typename StringType::value_type lower_b = ToLowerASCII(b[i]);
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } // namespace 1031 } // namespace
998 1032
999 size_t strlcpy(char* dst, const char* src, size_t dst_size) { 1033 size_t strlcpy(char* dst, const char* src, size_t dst_size) {
1000 return lcpyT<char>(dst, src, dst_size); 1034 return lcpyT<char>(dst, src, dst_size);
1001 } 1035 }
1002 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1036 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1003 return lcpyT<wchar_t>(dst, src, dst_size); 1037 return lcpyT<wchar_t>(dst, src, dst_size);
1004 } 1038 }
1005 1039
1006 } // namespace base 1040 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698