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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Portable, keep scanning the rest of the format string. | 133 // Portable, keep scanning the rest of the format string. |
134 in_specification = false; | 134 in_specification = false; |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
| 143 template<class StringType> |
| 144 int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a, |
| 145 BasicStringPiece<StringType> b) { |
| 146 // Find the first characters that aren't equal and compare them. If the end |
| 147 // of one of the strings is found before a nonequal character, the lengths |
| 148 // of the strings are compared. |
| 149 size_t i = 0; |
| 150 while (i < a.length() && i < b.length()) { |
| 151 typename StringType::value_type lower_a = ToLowerASCII(a[i]); |
| 152 typename StringType::value_type lower_b = ToLowerASCII(b[i]); |
| 153 if (lower_a < lower_b) |
| 154 return -1; |
| 155 if (lower_a > lower_b) |
| 156 return 1; |
| 157 i++; |
| 158 } |
| 159 |
| 160 // End of one string hit before finding a different character. Expect the |
| 161 // common case to be "strings equal" at this point so check that first. |
| 162 if (a.length() == b.length()) |
| 163 return 0; |
| 164 |
| 165 if (a.length() < b.length()) |
| 166 return -1; |
| 167 return 1; |
| 168 } |
| 169 |
| 170 int CompareCaseInsensitiveASCII(base::StringPiece a, base::StringPiece b) { |
| 171 return CompareCaseInsensitiveASCIIT<std::string>(a, b); |
| 172 } |
| 173 |
| 174 int CompareCaseInsensitiveASCII(base::StringPiece16 a, base::StringPiece16 b) { |
| 175 return CompareCaseInsensitiveASCIIT<base::string16>(a, b); |
| 176 } |
| 177 |
| 178 bool EqualsCaseInsensitiveASCII(base::StringPiece a, base::StringPiece b) { |
| 179 if (a.length() != b.length()) |
| 180 return false; |
| 181 return CompareCaseInsensitiveASCIIT<std::string>(a, b) == 0; |
| 182 } |
| 183 |
| 184 bool EqualsCaseInsensitiveASCII(base::StringPiece16 a, base::StringPiece16 b) { |
| 185 if (a.length() != b.length()) |
| 186 return false; |
| 187 return CompareCaseInsensitiveASCIIT<base::string16>(a, b) == 0; |
| 188 } |
| 189 |
143 const std::string& EmptyString() { | 190 const std::string& EmptyString() { |
144 return EmptyStrings::GetInstance()->s; | 191 return EmptyStrings::GetInstance()->s; |
145 } | 192 } |
146 | 193 |
147 const string16& EmptyString16() { | 194 const string16& EmptyString16() { |
148 return EmptyStrings::GetInstance()->s16; | 195 return EmptyStrings::GetInstance()->s16; |
149 } | 196 } |
150 | 197 |
151 template<typename STR> | 198 template<typename STR> |
152 bool ReplaceCharsT(const STR& input, | 199 bool ReplaceCharsT(const STR& input, |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 } | 1003 } |
957 | 1004 |
958 } // namespace | 1005 } // namespace |
959 | 1006 |
960 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 1007 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
961 return lcpyT<char>(dst, src, dst_size); | 1008 return lcpyT<char>(dst, src, dst_size); |
962 } | 1009 } |
963 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1010 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
964 return lcpyT<wchar_t>(dst, src, dst_size); | 1011 return lcpyT<wchar_t>(dst, src, dst_size); |
965 } | 1012 } |
OLD | NEW |