OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 5 #include "base/string_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <ctype.h> | 9 #include <ctype.h> |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 } | 561 } |
562 | 562 |
563 template <typename STR> | 563 template <typename STR> |
564 bool StartsWithT(const STR& str, const STR& search, bool case_sensitive) { | 564 bool StartsWithT(const STR& str, const STR& search, bool case_sensitive) { |
565 if (case_sensitive) { | 565 if (case_sensitive) { |
566 return str.compare(0, search.length(), search) == 0; | 566 return str.compare(0, search.length(), search) == 0; |
567 } else { | 567 } else { |
568 if (search.size() > str.size()) | 568 if (search.size() > str.size()) |
569 return false; | 569 return false; |
570 return std::equal(search.begin(), search.end(), str.begin(), | 570 return std::equal(search.begin(), search.end(), str.begin(), |
571 CaseInsensitiveCompare<typename STR::value_type>()); | 571 base::CaseInsensitiveCompare<typename STR::value_type>()); |
572 } | 572 } |
573 } | 573 } |
574 | 574 |
575 bool StartsWith(const std::wstring& str, const std::wstring& search, | 575 bool StartsWith(const std::wstring& str, const std::wstring& search, |
576 bool case_sensitive) { | 576 bool case_sensitive) { |
577 return StartsWithT(str, search, case_sensitive); | 577 return StartsWithT(str, search, case_sensitive); |
578 } | 578 } |
579 | 579 |
580 #if !defined(WCHAR_T_IS_UTF16) | 580 #if !defined(WCHAR_T_IS_UTF16) |
581 bool StartsWith(const string16& str, const string16& search, | 581 bool StartsWith(const string16& str, const string16& search, |
582 bool case_sensitive) { | 582 bool case_sensitive) { |
583 return StartsWithT(str, search, case_sensitive); | 583 return StartsWithT(str, search, case_sensitive); |
584 } | 584 } |
585 #endif | 585 #endif |
586 | 586 |
587 template <typename STR> | 587 template <typename STR> |
588 bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) { | 588 bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) { |
589 typename STR::size_type str_length = str.length(); | 589 typename STR::size_type str_length = str.length(); |
590 typename STR::size_type search_length = search.length(); | 590 typename STR::size_type search_length = search.length(); |
591 if (search_length > str_length) | 591 if (search_length > str_length) |
592 return false; | 592 return false; |
593 if (case_sensitive) { | 593 if (case_sensitive) { |
594 return str.compare(str_length - search_length, search_length, search) == 0; | 594 return str.compare(str_length - search_length, search_length, search) == 0; |
595 } else { | 595 } else { |
596 return std::equal(search.begin(), search.end(), | 596 return std::equal(search.begin(), search.end(), |
597 str.begin() + (str_length - search_length), | 597 str.begin() + (str_length - search_length), |
598 CaseInsensitiveCompare<typename STR::value_type>()); | 598 base::CaseInsensitiveCompare<typename STR::value_type>()); |
599 } | 599 } |
600 } | 600 } |
601 | 601 |
602 bool EndsWith(const std::string& str, const std::string& search, | 602 bool EndsWith(const std::string& str, const std::string& search, |
603 bool case_sensitive) { | 603 bool case_sensitive) { |
604 return EndsWithT(str, search, case_sensitive); | 604 return EndsWithT(str, search, case_sensitive); |
605 } | 605 } |
606 | 606 |
607 bool EndsWith(const std::wstring& str, const std::wstring& search, | 607 bool EndsWith(const std::wstring& str, const std::wstring& search, |
608 bool case_sensitive) { | 608 bool case_sensitive) { |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 int rstr_len = (max_len - 3) / 2; | 1177 int rstr_len = (max_len - 3) / 2; |
1178 int lstr_len = rstr_len + ((max_len - 3) % 2); | 1178 int lstr_len = rstr_len + ((max_len - 3) % 2); |
1179 output->assign(input.substr(0, lstr_len) + L"..." + | 1179 output->assign(input.substr(0, lstr_len) + L"..." + |
1180 input.substr(input.length() - rstr_len)); | 1180 input.substr(input.length() - rstr_len)); |
1181 break; | 1181 break; |
1182 } | 1182 } |
1183 } | 1183 } |
1184 | 1184 |
1185 return true; | 1185 return true; |
1186 } | 1186 } |
OLD | NEW |