| 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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 } | 750 } |
| 751 | 751 |
| 752 void ReplaceSubstringsAfterOffset(std::string* str, | 752 void ReplaceSubstringsAfterOffset(std::string* str, |
| 753 std::string::size_type start_offset, | 753 std::string::size_type start_offset, |
| 754 const std::string& find_this, | 754 const std::string& find_this, |
| 755 const std::string& replace_with) { | 755 const std::string& replace_with) { |
| 756 DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with, | 756 DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with, |
| 757 true); // replace all instances | 757 true); // replace all instances |
| 758 } | 758 } |
| 759 | 759 |
| 760 // TODO(tfarina): Remove this when finish moving SplitString functions to |
| 761 // string_split.[cc/h]. |
| 760 template<typename STR> | 762 template<typename STR> |
| 761 static void SplitStringT(const STR& str, | 763 static void SplitStringT(const STR& str, |
| 762 const typename STR::value_type s, | 764 const typename STR::value_type s, |
| 763 bool trim_whitespace, | 765 bool trim_whitespace, |
| 764 std::vector<STR>* r) { | 766 std::vector<STR>* r) { |
| 765 size_t last = 0; | 767 size_t last = 0; |
| 766 size_t i; | 768 size_t i; |
| 767 size_t c = str.size(); | 769 size_t c = str.size(); |
| 768 for (i = 0; i <= c; ++i) { | 770 for (i = 0; i <= c; ++i) { |
| 769 if (i == c || str[i] == s) { | 771 if (i == c || str[i] == s) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 794 SplitStringT(str, s, true, r); | 796 SplitStringT(str, s, true, r); |
| 795 } | 797 } |
| 796 #endif | 798 #endif |
| 797 | 799 |
| 798 void SplitString(const std::string& str, | 800 void SplitString(const std::string& str, |
| 799 char s, | 801 char s, |
| 800 std::vector<std::string>* r) { | 802 std::vector<std::string>* r) { |
| 801 SplitStringT(str, s, true, r); | 803 SplitStringT(str, s, true, r); |
| 802 } | 804 } |
| 803 | 805 |
| 804 void SplitStringDontTrim(const std::wstring& str, | |
| 805 wchar_t s, | |
| 806 std::vector<std::wstring>* r) { | |
| 807 SplitStringT(str, s, false, r); | |
| 808 } | |
| 809 | |
| 810 #if !defined(WCHAR_T_IS_UTF16) | |
| 811 void SplitStringDontTrim(const string16& str, | |
| 812 char16 s, | |
| 813 std::vector<string16>* r) { | |
| 814 SplitStringT(str, s, false, r); | |
| 815 } | |
| 816 #endif | |
| 817 | |
| 818 void SplitStringDontTrim(const std::string& str, | |
| 819 char s, | |
| 820 std::vector<std::string>* r) { | |
| 821 SplitStringT(str, s, false, r); | |
| 822 } | |
| 823 | |
| 824 template<typename STR> | 806 template<typename STR> |
| 825 static size_t TokenizeT(const STR& str, | 807 static size_t TokenizeT(const STR& str, |
| 826 const STR& delimiters, | 808 const STR& delimiters, |
| 827 std::vector<STR>* tokens) { | 809 std::vector<STR>* tokens) { |
| 828 tokens->clear(); | 810 tokens->clear(); |
| 829 | 811 |
| 830 typename STR::size_type start = str.find_first_not_of(delimiters); | 812 typename STR::size_type start = str.find_first_not_of(delimiters); |
| 831 while (start != STR::npos) { | 813 while (start != STR::npos) { |
| 832 typename STR::size_type end = str.find_first_of(delimiters, start + 1); | 814 typename STR::size_type end = str.find_first_of(delimiters, start + 1); |
| 833 if (end == STR::npos) { | 815 if (end == STR::npos) { |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 int rstr_len = (max_len - 3) / 2; | 1230 int rstr_len = (max_len - 3) / 2; |
| 1249 int lstr_len = rstr_len + ((max_len - 3) % 2); | 1231 int lstr_len = rstr_len + ((max_len - 3) % 2); |
| 1250 output->assign(input.substr(0, lstr_len) + L"..." + | 1232 output->assign(input.substr(0, lstr_len) + L"..." + |
| 1251 input.substr(input.length() - rstr_len)); | 1233 input.substr(input.length() - rstr_len)); |
| 1252 break; | 1234 break; |
| 1253 } | 1235 } |
| 1254 } | 1236 } |
| 1255 | 1237 |
| 1256 return true; | 1238 return true; |
| 1257 } | 1239 } |
| OLD | NEW |