OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |