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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 815 } |
816 | 816 |
817 std::string JoinString(const std::vector<std::string>& parts, char sep) { | 817 std::string JoinString(const std::vector<std::string>& parts, char sep) { |
818 return JoinStringT(parts, sep); | 818 return JoinStringT(parts, sep); |
819 } | 819 } |
820 | 820 |
821 string16 JoinString(const std::vector<string16>& parts, char16 sep) { | 821 string16 JoinString(const std::vector<string16>& parts, char16 sep) { |
822 return JoinStringT(parts, sep); | 822 return JoinStringT(parts, sep); |
823 } | 823 } |
824 | 824 |
825 template<typename STR> | |
826 void SplitStringAlongWhitespaceT(const STR& str, std::vector<STR>* result) { | |
827 const size_t length = str.length(); | |
828 if (!length) | |
829 return; | |
830 | |
831 bool last_was_ws = false; | |
832 size_t last_non_ws_start = 0; | |
833 for (size_t i = 0; i < length; ++i) { | |
834 switch (str[i]) { | |
835 // HTML 5 defines whitespace as: space, tab, LF, line tab, FF, or CR. | |
836 case L' ': | |
837 case L'\t': | |
838 case L'\xA': | |
839 case L'\xB': | |
840 case L'\xC': | |
841 case L'\xD': | |
842 if (!last_was_ws) { | |
843 if (i > 0) { | |
844 result->push_back( | |
845 str.substr(last_non_ws_start, i - last_non_ws_start)); | |
846 } | |
847 last_was_ws = true; | |
848 } | |
849 break; | |
850 | |
851 default: // Not a space character. | |
852 if (last_was_ws) { | |
853 last_was_ws = false; | |
854 last_non_ws_start = i; | |
855 } | |
856 break; | |
857 } | |
858 } | |
859 if (!last_was_ws) { | |
860 result->push_back( | |
861 str.substr(last_non_ws_start, length - last_non_ws_start)); | |
862 } | |
863 } | |
864 | |
865 void SplitStringAlongWhitespace(const std::wstring& str, | |
866 std::vector<std::wstring>* result) { | |
867 SplitStringAlongWhitespaceT(str, result); | |
868 } | |
869 | |
870 #if !defined(WCHAR_T_IS_UTF16) | |
871 void SplitStringAlongWhitespace(const string16& str, | |
872 std::vector<string16>* result) { | |
873 SplitStringAlongWhitespaceT(str, result); | |
874 } | |
875 #endif | |
876 | |
877 void SplitStringAlongWhitespace(const std::string& str, | |
878 std::vector<std::string>* result) { | |
879 SplitStringAlongWhitespaceT(str, result); | |
880 } | |
881 | |
882 template<class FormatStringType, class OutStringType> | 825 template<class FormatStringType, class OutStringType> |
883 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, | 826 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, |
884 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { | 827 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { |
885 size_t substitutions = subst.size(); | 828 size_t substitutions = subst.size(); |
886 DCHECK(substitutions < 10); | 829 DCHECK(substitutions < 10); |
887 | 830 |
888 size_t sub_length = 0; | 831 size_t sub_length = 0; |
889 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); | 832 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); |
890 iter != subst.end(); ++iter) { | 833 iter != subst.end(); ++iter) { |
891 sub_length += iter->length(); | 834 sub_length += iter->length(); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 int rstr_len = (max_len - 3) / 2; | 1120 int rstr_len = (max_len - 3) / 2; |
1178 int lstr_len = rstr_len + ((max_len - 3) % 2); | 1121 int lstr_len = rstr_len + ((max_len - 3) % 2); |
1179 output->assign(input.substr(0, lstr_len) + L"..." + | 1122 output->assign(input.substr(0, lstr_len) + L"..." + |
1180 input.substr(input.length() - rstr_len)); | 1123 input.substr(input.length() - rstr_len)); |
1181 break; | 1124 break; |
1182 } | 1125 } |
1183 } | 1126 } |
1184 | 1127 |
1185 return true; | 1128 return true; |
1186 } | 1129 } |
OLD | NEW |