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]. | |
762 template<typename STR> | |
763 static void SplitStringT(const STR& str, | |
764 const typename STR::value_type s, | |
765 bool trim_whitespace, | |
766 std::vector<STR>* r) { | |
767 size_t last = 0; | |
768 size_t i; | |
769 size_t c = str.size(); | |
770 for (i = 0; i <= c; ++i) { | |
771 if (i == c || str[i] == s) { | |
772 size_t len = i - last; | |
773 STR tmp = str.substr(last, len); | |
774 if (trim_whitespace) { | |
775 STR t_tmp; | |
776 TrimWhitespace(tmp, TRIM_ALL, &t_tmp); | |
777 r->push_back(t_tmp); | |
778 } else { | |
779 r->push_back(tmp); | |
780 } | |
781 last = i + 1; | |
782 } | |
783 } | |
784 } | |
785 | |
786 void SplitString(const std::wstring& str, | |
787 wchar_t s, | |
788 std::vector<std::wstring>* r) { | |
789 SplitStringT(str, s, true, r); | |
790 } | |
791 | |
792 #if !defined(WCHAR_T_IS_UTF16) | |
793 void SplitString(const string16& str, | |
794 char16 s, | |
795 std::vector<string16>* r) { | |
796 SplitStringT(str, s, true, r); | |
797 } | |
798 #endif | |
799 | |
800 void SplitString(const std::string& str, | |
801 char s, | |
802 std::vector<std::string>* r) { | |
803 SplitStringT(str, s, true, r); | |
804 } | |
805 | 760 |
806 template<typename STR> | 761 template<typename STR> |
807 static size_t TokenizeT(const STR& str, | 762 static size_t TokenizeT(const STR& str, |
808 const STR& delimiters, | 763 const STR& delimiters, |
809 std::vector<STR>* tokens) { | 764 std::vector<STR>* tokens) { |
810 tokens->clear(); | 765 tokens->clear(); |
811 | 766 |
812 typename STR::size_type start = str.find_first_not_of(delimiters); | 767 typename STR::size_type start = str.find_first_not_of(delimiters); |
813 while (start != STR::npos) { | 768 while (start != STR::npos) { |
814 typename STR::size_type end = str.find_first_of(delimiters, start + 1); | 769 typename STR::size_type end = str.find_first_of(delimiters, start + 1); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 int rstr_len = (max_len - 3) / 2; | 1185 int rstr_len = (max_len - 3) / 2; |
1231 int lstr_len = rstr_len + ((max_len - 3) % 2); | 1186 int lstr_len = rstr_len + ((max_len - 3) % 2); |
1232 output->assign(input.substr(0, lstr_len) + L"..." + | 1187 output->assign(input.substr(0, lstr_len) + L"..." + |
1233 input.substr(input.length() - rstr_len)); | 1188 input.substr(input.length() - rstr_len)); |
1234 break; | 1189 break; |
1235 } | 1190 } |
1236 } | 1191 } |
1237 | 1192 |
1238 return true; | 1193 return true; |
1239 } | 1194 } |
OLD | NEW |