OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 if (case_sensitive) | 766 if (case_sensitive) |
767 return str.compare(0, search.length(), search) == 0; | 767 return str.compare(0, search.length(), search) == 0; |
768 else { | 768 else { |
769 if (search.size() > str.size()) | 769 if (search.size() > str.size()) |
770 return false; | 770 return false; |
771 return std::equal(search.begin(), search.end(), str.begin(), | 771 return std::equal(search.begin(), search.end(), str.begin(), |
772 CaseInsensitiveCompare<wchar_t>()); | 772 CaseInsensitiveCompare<wchar_t>()); |
773 } | 773 } |
774 } | 774 } |
775 | 775 |
| 776 bool EndsWith(const std::wstring& str, |
| 777 const std::wstring& search, |
| 778 bool case_sensitive) { |
| 779 std::wstring::size_type str_length = str.length(); |
| 780 std::wstring::size_type search_length = search.length(); |
| 781 if (search_length > str_length) |
| 782 return false; |
| 783 if (case_sensitive) { |
| 784 return str.compare(str_length - search_length, search_length, search) == 0; |
| 785 } else { |
| 786 return std::equal(search.begin(), search.end(), |
| 787 str.begin() + (str_length - search_length), |
| 788 CaseInsensitiveCompare<wchar_t>()); |
| 789 } |
| 790 } |
| 791 |
776 DataUnits GetByteDisplayUnits(int64 bytes) { | 792 DataUnits GetByteDisplayUnits(int64 bytes) { |
777 // The byte thresholds at which we display amounts. A byte count is displayed | 793 // The byte thresholds at which we display amounts. A byte count is displayed |
778 // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. | 794 // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. |
779 // This must match the DataUnits enum. | 795 // This must match the DataUnits enum. |
780 static const int64 kUnitThresholds[] = { | 796 static const int64 kUnitThresholds[] = { |
781 0, // DATA_UNITS_BYTE, | 797 0, // DATA_UNITS_BYTE, |
782 3*1024, // DATA_UNITS_KILOBYTE, | 798 3*1024, // DATA_UNITS_KILOBYTE, |
783 2*1024*1024, // DATA_UNITS_MEGABYTE, | 799 2*1024*1024, // DATA_UNITS_MEGABYTE, |
784 1024*1024*1024 // DATA_UNITS_GIGABYTE, | 800 1024*1024*1024 // DATA_UNITS_GIGABYTE, |
785 }; | 801 }; |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 // Each input byte creates two output hex characters. | 1681 // Each input byte creates two output hex characters. |
1666 std::string ret(size * 2, '\0'); | 1682 std::string ret(size * 2, '\0'); |
1667 | 1683 |
1668 for (size_t i = 0; i < size; ++i) { | 1684 for (size_t i = 0; i < size; ++i) { |
1669 char b = reinterpret_cast<const char*>(bytes)[i]; | 1685 char b = reinterpret_cast<const char*>(bytes)[i]; |
1670 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; | 1686 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
1671 ret[(i * 2) + 1] = kHexChars[b & 0xf]; | 1687 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
1672 } | 1688 } |
1673 return ret; | 1689 return ret; |
1674 } | 1690 } |
OLD | NEW |