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

Side by Side Diff: base/strings/string_util.cc

Issue 1172183002: Move StartsWith[ASCII] to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util3
Patch Set: merger Created 5 years, 6 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
« no previous file with comments | « base/strings/string_util.h ('k') | base/test/test_pending_task_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 const char* b) { 475 const char* b) {
476 return DoLowerCaseEqualsASCII(a_begin, a_end, b); 476 return DoLowerCaseEqualsASCII(a_begin, a_end, b);
477 } 477 }
478 478
479 bool EqualsASCII(const string16& a, const StringPiece& b) { 479 bool EqualsASCII(const string16& a, const StringPiece& b) {
480 if (a.length() != b.length()) 480 if (a.length() != b.length())
481 return false; 481 return false;
482 return std::equal(b.begin(), b.end(), a.begin()); 482 return std::equal(b.begin(), b.end(), a.begin());
483 } 483 }
484 484
485 } // namespace base
486
487 bool StartsWithASCII(const std::string& str, 485 bool StartsWithASCII(const std::string& str,
488 const std::string& search, 486 const std::string& search,
489 bool case_sensitive) { 487 bool case_sensitive) {
490 if (case_sensitive) 488 if (case_sensitive)
491 return str.compare(0, search.length(), search) == 0; 489 return str.compare(0, search.length(), search) == 0;
492 else 490 else
493 return base::strncasecmp(str.c_str(), search.c_str(), search.length()) == 0; 491 return base::strncasecmp(str.c_str(), search.c_str(), search.length()) == 0;
494 } 492 }
495 493
496 template <typename STR> 494 bool StartsWith(const string16& str,
497 bool StartsWithT(const STR& str, const STR& search, bool case_sensitive) { 495 const string16& search,
496 bool case_sensitive) {
498 if (case_sensitive) { 497 if (case_sensitive) {
499 return str.compare(0, search.length(), search) == 0; 498 return str.compare(0, search.length(), search) == 0;
500 } else {
501 if (search.size() > str.size())
502 return false;
503 return std::equal(search.begin(), search.end(), str.begin(),
504 base::CaseInsensitiveCompare<typename STR::value_type>());
505 } 499 }
500 if (search.size() > str.size())
501 return false;
502 return std::equal(search.begin(), search.end(), str.begin(),
503 CaseInsensitiveCompare<char16>());
506 } 504 }
507 505
508 bool StartsWith(const string16& str, const string16& search, 506 } // namespace base
509 bool case_sensitive) {
510 return StartsWithT(str, search, case_sensitive);
511 }
512 507
513 template <typename STR> 508 template <typename STR>
514 bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) { 509 bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) {
515 size_t str_length = str.length(); 510 size_t str_length = str.length();
516 size_t search_length = search.length(); 511 size_t search_length = search.length();
517 if (search_length > str_length) 512 if (search_length > str_length)
518 return false; 513 return false;
519 if (case_sensitive) 514 if (case_sensitive)
520 return str.compare(str_length - search_length, search_length, search) == 0; 515 return str.compare(str_length - search_length, search_length, search) == 0;
521 return std::equal(search.begin(), search.end(), 516 return std::equal(search.begin(), search.end(),
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 } 1032 }
1038 1033
1039 } // namespace 1034 } // namespace
1040 1035
1041 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 1036 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
1042 return lcpyT<char>(dst, src, dst_size); 1037 return lcpyT<char>(dst, src, dst_size);
1043 } 1038 }
1044 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1039 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1045 return lcpyT<wchar_t>(dst, src, dst_size); 1040 return lcpyT<wchar_t>(dst, src, dst_size);
1046 } 1041 }
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | base/test/test_pending_task_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698