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

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

Issue 1278973004: Remove outdated versions of StartsWith and EndsWith from string_util.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | no next file » | 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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 CompareCase case_sensitivity) { 580 CompareCase case_sensitivity) {
581 return StartsWithT<std::string>(str, search_for, case_sensitivity); 581 return StartsWithT<std::string>(str, search_for, case_sensitivity);
582 } 582 }
583 583
584 bool StartsWith(StringPiece16 str, 584 bool StartsWith(StringPiece16 str,
585 StringPiece16 search_for, 585 StringPiece16 search_for,
586 CompareCase case_sensitivity) { 586 CompareCase case_sensitivity) {
587 return StartsWithT<string16>(str, search_for, case_sensitivity); 587 return StartsWithT<string16>(str, search_for, case_sensitivity);
588 } 588 }
589 589
590 bool StartsWith(const string16& str,
591 const string16& search,
592 bool case_sensitive) {
593 if (!case_sensitive) {
594 // This function was originally written using the current locale functions
595 // for case-insensitive comparisons. Emulate this behavior until callers
596 // can be converted either to use the case-insensitive ASCII one (most
597 // callers) or ICU functions in base_i18n.
598 if (search.size() > str.size())
599 return false;
600 return std::equal(search.begin(), search.end(), str.begin(),
601 CaseInsensitiveCompareDeprecated());
602 }
603 return StartsWith(StringPiece16(str), StringPiece16(search),
604 CompareCase::SENSITIVE);
605 }
606
607 template <typename Str> 590 template <typename Str>
608 bool EndsWithT(BasicStringPiece<Str> str, 591 bool EndsWithT(BasicStringPiece<Str> str,
609 BasicStringPiece<Str> search_for, 592 BasicStringPiece<Str> search_for,
610 CompareCase case_sensitivity) { 593 CompareCase case_sensitivity) {
611 if (search_for.size() > str.size()) 594 if (search_for.size() > str.size())
612 return false; 595 return false;
613 596
614 BasicStringPiece<Str> source = str.substr(str.size() - search_for.size(), 597 BasicStringPiece<Str> source = str.substr(str.size() - search_for.size(),
615 search_for.size()); 598 search_for.size());
616 599
(...skipping 14 matching lines...) Expand all
631 } 614 }
632 615
633 bool EndsWith(StringPiece str, 616 bool EndsWith(StringPiece str,
634 StringPiece search_for, 617 StringPiece search_for,
635 CompareCase case_sensitivity) { 618 CompareCase case_sensitivity) {
636 return EndsWithT<std::string>(str, search_for, case_sensitivity); 619 return EndsWithT<std::string>(str, search_for, case_sensitivity);
637 } 620 }
638 621
639 bool EndsWith(StringPiece16 str, 622 bool EndsWith(StringPiece16 str,
640 StringPiece16 search_for, 623 StringPiece16 search_for,
641 CompareCase case_sensitivity) { 624 CompareCase case_sensitivity) {
642 return EndsWithT<string16>(str, search_for, case_sensitivity); 625 return EndsWithT<string16>(str, search_for, case_sensitivity);
643 } 626 }
644 627
645 bool EndsWith(const string16& str,
646 const string16& search,
647 bool case_sensitive) {
648 if (!case_sensitive) {
649 // This function was originally written using the current locale functions
650 // for case-insensitive comparisons. Emulate this behavior until callers
651 // can be converted either to use the case-insensitive ASCII one (most
652 // callers) or ICU functions in base_i18n.
653 if (search.size() > str.size())
654 return false;
655 return std::equal(search.begin(), search.end(),
656 str.begin() + (str.size() - search.size()),
657 CaseInsensitiveCompareDeprecated());
658 }
659 return EndsWith(StringPiece16(str), StringPiece16(search),
660 CompareCase::SENSITIVE);
661 }
662
663 char HexDigitToInt(wchar_t c) { 628 char HexDigitToInt(wchar_t c) {
664 DCHECK(IsHexDigit(c)); 629 DCHECK(IsHexDigit(c));
665 if (c >= '0' && c <= '9') 630 if (c >= '0' && c <= '9')
666 return static_cast<char>(c - '0'); 631 return static_cast<char>(c - '0');
667 if (c >= 'A' && c <= 'F') 632 if (c >= 'A' && c <= 'F')
668 return static_cast<char>(c - 'A' + 10); 633 return static_cast<char>(c - 'A' + 10);
669 if (c >= 'a' && c <= 'f') 634 if (c >= 'a' && c <= 'f')
670 return static_cast<char>(c - 'a' + 10); 635 return static_cast<char>(c - 'a' + 10);
671 return 0; 636 return 0;
672 } 637 }
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } // namespace 962 } // namespace
998 963
999 size_t strlcpy(char* dst, const char* src, size_t dst_size) { 964 size_t strlcpy(char* dst, const char* src, size_t dst_size) {
1000 return lcpyT<char>(dst, src, dst_size); 965 return lcpyT<char>(dst, src, dst_size);
1001 } 966 }
1002 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 967 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1003 return lcpyT<wchar_t>(dst, src, dst_size); 968 return lcpyT<wchar_t>(dst, src, dst_size);
1004 } 969 }
1005 970
1006 } // namespace base 971 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698