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

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

Issue 1182183003: Move EndsWith to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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') | chrome/app/delay_load_hook_win.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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 bool case_sensitive) { 496 bool case_sensitive) {
497 if (case_sensitive) { 497 if (case_sensitive) {
498 return str.compare(0, search.length(), search) == 0; 498 return str.compare(0, search.length(), search) == 0;
499 } 499 }
500 if (search.size() > str.size()) 500 if (search.size() > str.size())
501 return false; 501 return false;
502 return std::equal(search.begin(), search.end(), str.begin(), 502 return std::equal(search.begin(), search.end(), str.begin(),
503 CaseInsensitiveCompare<char16>()); 503 CaseInsensitiveCompare<char16>());
504 } 504 }
505 505
506 } // namespace base
507
508 template <typename STR> 506 template <typename STR>
509 bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) { 507 bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) {
510 size_t str_length = str.length(); 508 size_t str_length = str.length();
511 size_t search_length = search.length(); 509 size_t search_length = search.length();
512 if (search_length > str_length) 510 if (search_length > str_length)
513 return false; 511 return false;
514 if (case_sensitive) 512 if (case_sensitive)
515 return str.compare(str_length - search_length, search_length, search) == 0; 513 return str.compare(str_length - search_length, search_length, search) == 0;
516 return std::equal(search.begin(), search.end(), 514 return std::equal(search.begin(), search.end(),
517 str.begin() + (str_length - search_length), 515 str.begin() + (str_length - search_length),
518 base::CaseInsensitiveCompare<typename STR::value_type>()); 516 base::CaseInsensitiveCompare<typename STR::value_type>());
519 } 517 }
520 518
521 bool EndsWith(const std::string& str, const std::string& search, 519 bool EndsWith(const std::string& str, const std::string& search,
522 bool case_sensitive) { 520 bool case_sensitive) {
523 return EndsWithT(str, search, case_sensitive); 521 return EndsWithT(str, search, case_sensitive);
524 } 522 }
525 523
526 bool EndsWith(const string16& str, const string16& search, 524 bool EndsWith(const string16& str, const string16& search,
527 bool case_sensitive) { 525 bool case_sensitive) {
528 return EndsWithT(str, search, case_sensitive); 526 return EndsWithT(str, search, case_sensitive);
529 } 527 }
530 528
529 } // namespace base
530
531 static const char* const kByteStringsUnlocalized[] = { 531 static const char* const kByteStringsUnlocalized[] = {
532 " B", 532 " B",
533 " kB", 533 " kB",
534 " MB", 534 " MB",
535 " GB", 535 " GB",
536 " TB", 536 " TB",
537 " PB" 537 " PB"
538 }; 538 };
539 539
540 string16 FormatBytesUnlocalized(int64 bytes) { 540 string16 FormatBytesUnlocalized(int64 bytes) {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 } 1032 }
1033 1033
1034 } // namespace 1034 } // namespace
1035 1035
1036 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) {
1037 return lcpyT<char>(dst, src, dst_size); 1037 return lcpyT<char>(dst, src, dst_size);
1038 } 1038 }
1039 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) {
1040 return lcpyT<wchar_t>(dst, src, dst_size); 1040 return lcpyT<wchar_t>(dst, src, dst_size);
1041 } 1041 }
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | chrome/app/delay_load_hook_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698