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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 while (char_index < src_len) { | 348 while (char_index < src_len) { |
349 int32 code_point; | 349 int32 code_point; |
350 CBU8_NEXT(src, char_index, src_len, code_point); | 350 CBU8_NEXT(src, char_index, src_len, code_point); |
351 if (!IsValidCharacter(code_point)) | 351 if (!IsValidCharacter(code_point)) |
352 return false; | 352 return false; |
353 } | 353 } |
354 return true; | 354 return true; |
355 } | 355 } |
356 | 356 |
357 } // namespace base | 357 template<typename StringType> |
358 | 358 static inline bool DoLowerCaseEqualsASCII(BasicStringPiece<StringType> str, |
359 template<typename Iter> | 359 const char* lower_cased_cmp) { |
360 static inline bool DoLowerCaseEqualsASCII(Iter a_begin, | 360 for (typename BasicStringPiece<StringType>::const_iterator it = str.begin(); |
361 Iter a_end, | 361 it != str.end(); ++it, ++lower_cased_cmp) { |
362 const char* b) { | 362 if (!*lower_cased_cmp || base::ToLowerASCII(*it) != *lower_cased_cmp) |
363 for (Iter it = a_begin; it != a_end; ++it, ++b) { | |
364 if (!*b || base::ToLowerASCII(*it) != *b) | |
365 return false; | 363 return false; |
366 } | 364 } |
367 return *b == 0; | 365 return *lower_cased_cmp == 0; |
368 } | 366 } |
369 | 367 |
370 // Front-ends for LowerCaseEqualsASCII. | 368 // Front-ends for LowerCaseEqualsASCII. |
371 bool LowerCaseEqualsASCII(const std::string& a, const char* b) { | 369 bool LowerCaseEqualsASCII(StringPiece str, const char* lower_cased_cmp) { |
372 return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); | 370 return DoLowerCaseEqualsASCII(str, lower_cased_cmp); |
373 } | 371 } |
374 | 372 |
375 bool LowerCaseEqualsASCII(const string16& a, const char* b) { | 373 bool LowerCaseEqualsASCII(StringPiece16 str, const char* lower_cased_cmp) { |
376 return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); | 374 return DoLowerCaseEqualsASCII(str, lower_cased_cmp); |
377 } | 375 } |
378 | 376 |
379 bool LowerCaseEqualsASCII(std::string::const_iterator a_begin, | 377 bool LowerCaseEqualsASCII(std::string::const_iterator a_begin, |
380 std::string::const_iterator a_end, | 378 std::string::const_iterator a_end, |
381 const char* b) { | 379 const char* b) { |
382 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 380 const char* a = &*a_begin; |
| 381 return LowerCaseEqualsASCII(StringPiece(a, a_end - a_begin), b); |
383 } | 382 } |
384 | 383 |
385 bool LowerCaseEqualsASCII(string16::const_iterator a_begin, | 384 bool LowerCaseEqualsASCII(string16::const_iterator a_begin, |
386 string16::const_iterator a_end, | 385 string16::const_iterator a_end, |
387 const char* b) { | 386 const char* b) { |
388 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 387 const char16* a = &*a_begin; |
| 388 return LowerCaseEqualsASCII(StringPiece16(a, a_end - a_begin), b); |
389 } | 389 } |
390 | 390 |
391 // TODO(port): Resolve wchar_t/iterator issues that require OS_ANDROID here. | 391 // TODO(port): Resolve wchar_t/iterator issues that require OS_ANDROID here. |
392 #if !defined(OS_ANDROID) | 392 #if !defined(OS_ANDROID) |
393 bool LowerCaseEqualsASCII(const char* a_begin, | 393 bool LowerCaseEqualsASCII(const char* a_begin, |
394 const char* a_end, | 394 const char* a_end, |
395 const char* b) { | 395 const char* b) { |
396 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 396 return DoLowerCaseEqualsASCII(StringPiece(a_begin, a_end - a_begin), b); |
397 } | 397 } |
398 | 398 |
399 bool LowerCaseEqualsASCII(const char16* a_begin, | 399 bool LowerCaseEqualsASCII(const char16* a_begin, |
400 const char16* a_end, | 400 const char16* a_end, |
401 const char* b) { | 401 const char* b) { |
402 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 402 return DoLowerCaseEqualsASCII(StringPiece16(a_begin, a_end - a_begin), b); |
403 } | 403 } |
| 404 #endif // !defined(OS_ANDROID) |
404 | 405 |
405 #endif // !defined(OS_ANDROID) | 406 } // namespace base |
406 | 407 |
407 bool EqualsASCII(const string16& a, const base::StringPiece& b) { | 408 bool EqualsASCII(const string16& a, const base::StringPiece& b) { |
408 if (a.length() != b.length()) | 409 if (a.length() != b.length()) |
409 return false; | 410 return false; |
410 return std::equal(b.begin(), b.end(), a.begin()); | 411 return std::equal(b.begin(), b.end(), a.begin()); |
411 } | 412 } |
412 | 413 |
413 bool StartsWithASCII(const std::string& str, | 414 bool StartsWithASCII(const std::string& str, |
414 const std::string& search, | 415 const std::string& search, |
415 bool case_sensitive) { | 416 bool case_sensitive) { |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 } | 884 } |
884 | 885 |
885 } // namespace | 886 } // namespace |
886 | 887 |
887 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 888 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
888 return lcpyT<char>(dst, src, dst_size); | 889 return lcpyT<char>(dst, src, dst_size); |
889 } | 890 } |
890 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 891 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
891 return lcpyT<wchar_t>(dst, src, dst_size); | 892 return lcpyT<wchar_t>(dst, src, dst_size); |
892 } | 893 } |
OLD | NEW |