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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 413 |
414 while (char_index < src_len) { | 414 while (char_index < src_len) { |
415 int32 code_point; | 415 int32 code_point; |
416 CBU8_NEXT(src, char_index, src_len, code_point); | 416 CBU8_NEXT(src, char_index, src_len, code_point); |
417 if (!IsValidCharacter(code_point)) | 417 if (!IsValidCharacter(code_point)) |
418 return false; | 418 return false; |
419 } | 419 } |
420 return true; | 420 return true; |
421 } | 421 } |
422 | 422 |
423 } // namespace base | |
424 | |
425 template<typename Iter> | 423 template<typename Iter> |
426 static inline bool DoLowerCaseEqualsASCII(Iter a_begin, | 424 static inline bool DoLowerCaseEqualsASCII(Iter a_begin, |
427 Iter a_end, | 425 Iter a_end, |
428 const char* b) { | 426 const char* b) { |
429 for (Iter it = a_begin; it != a_end; ++it, ++b) { | 427 for (Iter it = a_begin; it != a_end; ++it, ++b) { |
430 if (!*b || base::ToLowerASCII(*it) != *b) | 428 if (!*b || ToLowerASCII(*it) != *b) |
431 return false; | 429 return false; |
432 } | 430 } |
433 return *b == 0; | 431 return *b == 0; |
434 } | 432 } |
435 | 433 |
436 // Front-ends for LowerCaseEqualsASCII. | 434 // Front-ends for LowerCaseEqualsASCII. |
437 bool LowerCaseEqualsASCII(const std::string& a, const char* b) { | 435 bool LowerCaseEqualsASCII(const std::string& a, const char* b) { |
438 return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); | 436 return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); |
439 } | 437 } |
440 | 438 |
(...skipping 12 matching lines...) Expand all Loading... |
453 const char* b) { | 451 const char* b) { |
454 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 452 return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
455 } | 453 } |
456 | 454 |
457 bool LowerCaseEqualsASCII(const char* a_begin, | 455 bool LowerCaseEqualsASCII(const char* a_begin, |
458 const char* a_end, | 456 const char* a_end, |
459 const char* b) { | 457 const char* b) { |
460 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 458 return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
461 } | 459 } |
462 | 460 |
| 461 bool LowerCaseEqualsASCII(const char* a_begin, |
| 462 const char* a_end, |
| 463 const char* b_begin, |
| 464 const char* b_end) { |
| 465 while (a_begin != a_end && b_begin != b_end && |
| 466 ToLowerASCII(*a_begin) == *b_begin) { |
| 467 a_begin++; |
| 468 b_begin++; |
| 469 } |
| 470 return a_begin == a_end && b_begin == b_end; |
| 471 } |
| 472 |
463 bool LowerCaseEqualsASCII(const char16* a_begin, | 473 bool LowerCaseEqualsASCII(const char16* a_begin, |
464 const char16* a_end, | 474 const char16* a_end, |
465 const char* b) { | 475 const char* b) { |
466 return DoLowerCaseEqualsASCII(a_begin, a_end, b); | 476 return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
467 } | 477 } |
468 | 478 |
| 479 } // namespace base |
| 480 |
469 bool EqualsASCII(const string16& a, const base::StringPiece& b) { | 481 bool EqualsASCII(const string16& a, const base::StringPiece& b) { |
470 if (a.length() != b.length()) | 482 if (a.length() != b.length()) |
471 return false; | 483 return false; |
472 return std::equal(b.begin(), b.end(), a.begin()); | 484 return std::equal(b.begin(), b.end(), a.begin()); |
473 } | 485 } |
474 | 486 |
475 bool StartsWithASCII(const std::string& str, | 487 bool StartsWithASCII(const std::string& str, |
476 const std::string& search, | 488 const std::string& search, |
477 bool case_sensitive) { | 489 bool case_sensitive) { |
478 if (case_sensitive) | 490 if (case_sensitive) |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 } | 1037 } |
1026 | 1038 |
1027 } // namespace | 1039 } // namespace |
1028 | 1040 |
1029 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 1041 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
1030 return lcpyT<char>(dst, src, dst_size); | 1042 return lcpyT<char>(dst, src, dst_size); |
1031 } | 1043 } |
1032 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1044 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
1033 return lcpyT<wchar_t>(dst, src, dst_size); | 1045 return lcpyT<wchar_t>(dst, src, dst_size); |
1034 } | 1046 } |
OLD | NEW |