OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <math.h> | 9 #include <math.h> |
10 #include <stdarg.h> | 10 #include <stdarg.h> |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 } | 877 } |
878 | 878 |
879 char* WriteInto(std::string* str, size_t length_with_null) { | 879 char* WriteInto(std::string* str, size_t length_with_null) { |
880 return WriteIntoT(str, length_with_null); | 880 return WriteIntoT(str, length_with_null); |
881 } | 881 } |
882 | 882 |
883 char16* WriteInto(base::string16* str, size_t length_with_null) { | 883 char16* WriteInto(base::string16* str, size_t length_with_null) { |
884 return WriteIntoT(str, length_with_null); | 884 return WriteIntoT(str, length_with_null); |
885 } | 885 } |
886 | 886 |
| 887 } // namespace base |
| 888 |
887 template<typename STR> | 889 template<typename STR> |
888 static STR JoinStringT(const std::vector<STR>& parts, | 890 static STR JoinStringT(const std::vector<STR>& parts, const STR& sep) { |
889 BasicStringPiece<STR> sep) { | |
890 if (parts.empty()) | 891 if (parts.empty()) |
891 return STR(); | 892 return STR(); |
892 | 893 |
893 STR result(parts[0]); | 894 STR result(parts[0]); |
894 auto iter = parts.begin(); | 895 typename std::vector<STR>::const_iterator iter = parts.begin(); |
895 ++iter; | 896 ++iter; |
896 | 897 |
897 for (; iter != parts.end(); ++iter) { | 898 for (; iter != parts.end(); ++iter) { |
898 sep.AppendToString(&result); | 899 result += sep; |
899 result += *iter; | 900 result += *iter; |
900 } | 901 } |
901 | 902 |
902 return result; | 903 return result; |
903 } | 904 } |
904 | 905 |
| 906 std::string JoinString(const std::vector<std::string>& parts, char sep) { |
| 907 return JoinStringT(parts, std::string(1, sep)); |
| 908 } |
| 909 |
| 910 string16 JoinString(const std::vector<string16>& parts, char16 sep) { |
| 911 return JoinStringT(parts, string16(1, sep)); |
| 912 } |
| 913 |
905 std::string JoinString(const std::vector<std::string>& parts, | 914 std::string JoinString(const std::vector<std::string>& parts, |
906 StringPiece separator) { | 915 const std::string& separator) { |
907 return JoinStringT(parts, separator); | 916 return JoinStringT(parts, separator); |
908 } | 917 } |
909 | 918 |
910 string16 JoinString(const std::vector<string16>& parts, | 919 string16 JoinString(const std::vector<string16>& parts, |
911 StringPiece16 separator) { | 920 const string16& separator) { |
912 return JoinStringT(parts, separator); | 921 return JoinStringT(parts, separator); |
913 } | 922 } |
914 | 923 |
915 } // namespace base | |
916 | |
917 template<class FormatStringType, class OutStringType> | 924 template<class FormatStringType, class OutStringType> |
918 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, | 925 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, |
919 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { | 926 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { |
920 size_t substitutions = subst.size(); | 927 size_t substitutions = subst.size(); |
921 | 928 |
922 size_t sub_length = 0; | 929 size_t sub_length = 0; |
923 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); | 930 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); |
924 iter != subst.end(); ++iter) { | 931 iter != subst.end(); ++iter) { |
925 sub_length += iter->length(); | 932 sub_length += iter->length(); |
926 } | 933 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 } | 1032 } |
1026 | 1033 |
1027 } // namespace | 1034 } // namespace |
1028 | 1035 |
1029 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 1036 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
1030 return lcpyT<char>(dst, src, dst_size); | 1037 return lcpyT<char>(dst, src, dst_size); |
1031 } | 1038 } |
1032 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1039 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
1033 return lcpyT<wchar_t>(dst, src, dst_size); | 1040 return lcpyT<wchar_t>(dst, src, dst_size); |
1034 } | 1041 } |
OLD | NEW |