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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 SplitStringT(str, s, false, r); | 814 SplitStringT(str, s, false, r); |
815 } | 815 } |
816 #endif | 816 #endif |
817 | 817 |
818 void SplitStringDontTrim(const std::string& str, | 818 void SplitStringDontTrim(const std::string& str, |
819 char s, | 819 char s, |
820 std::vector<std::string>* r) { | 820 std::vector<std::string>* r) { |
821 SplitStringT(str, s, false, r); | 821 SplitStringT(str, s, false, r); |
822 } | 822 } |
823 | 823 |
824 template <typename STR> | |
825 static void SplitStringUsingSubstrT(const STR& str, | |
826 const STR& s, | |
827 std::vector<STR>* r) { | |
828 typename STR::size_type begin_index = 0; | |
829 while (true) { | |
830 const typename STR::size_type end_index = str.find(s, begin_index); | |
831 if (end_index == STR::npos) { | |
832 const STR term = str.substr(begin_index); | |
833 STR tmp; | |
834 TrimWhitespace(term, TRIM_ALL, &tmp); | |
835 r->push_back(tmp); | |
836 return; | |
837 } | |
838 const STR term = str.substr(begin_index, end_index - begin_index); | |
839 STR tmp; | |
840 TrimWhitespace(term, TRIM_ALL, &tmp); | |
841 r->push_back(tmp); | |
842 begin_index = end_index + s.size(); | |
843 } | |
844 } | |
845 | |
846 void SplitStringUsingSubstr(const string16& str, | |
847 const string16& s, | |
848 std::vector<string16>* r) { | |
849 SplitStringUsingSubstrT(str, s, r); | |
850 } | |
851 | |
852 void SplitStringUsingSubstr(const std::string& str, | |
853 const std::string& s, | |
854 std::vector<std::string>* r) { | |
855 SplitStringUsingSubstrT(str, s, r); | |
856 } | |
857 | |
858 template<typename STR> | 824 template<typename STR> |
859 static size_t TokenizeT(const STR& str, | 825 static size_t TokenizeT(const STR& str, |
860 const STR& delimiters, | 826 const STR& delimiters, |
861 std::vector<STR>* tokens) { | 827 std::vector<STR>* tokens) { |
862 tokens->clear(); | 828 tokens->clear(); |
863 | 829 |
864 typename STR::size_type start = str.find_first_not_of(delimiters); | 830 typename STR::size_type start = str.find_first_not_of(delimiters); |
865 while (start != STR::npos) { | 831 while (start != STR::npos) { |
866 typename STR::size_type end = str.find_first_of(delimiters, start + 1); | 832 typename STR::size_type end = str.find_first_of(delimiters, start + 1); |
867 if (end == STR::npos) { | 833 if (end == STR::npos) { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 int rstr_len = (max_len - 3) / 2; | 1211 int rstr_len = (max_len - 3) / 2; |
1246 int lstr_len = rstr_len + ((max_len - 3) % 2); | 1212 int lstr_len = rstr_len + ((max_len - 3) % 2); |
1247 output->assign(input.substr(0, lstr_len) + L"..." + | 1213 output->assign(input.substr(0, lstr_len) + L"..." + |
1248 input.substr(input.length() - rstr_len)); | 1214 input.substr(input.length() - rstr_len)); |
1249 break; | 1215 break; |
1250 } | 1216 } |
1251 } | 1217 } |
1252 | 1218 |
1253 return true; | 1219 return true; |
1254 } | 1220 } |
OLD | NEW |