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 | |
889 template<typename STR> | 887 template<typename STR> |
890 static STR JoinStringT(const std::vector<STR>& parts, const STR& sep) { | 888 static STR JoinStringT(const std::vector<STR>& parts, |
| 889 BasicStringPiece<STR> sep) { |
891 if (parts.empty()) | 890 if (parts.empty()) |
892 return STR(); | 891 return STR(); |
893 | 892 |
894 STR result(parts[0]); | 893 STR result(parts[0]); |
895 typename std::vector<STR>::const_iterator iter = parts.begin(); | 894 auto iter = parts.begin(); |
896 ++iter; | 895 ++iter; |
897 | 896 |
898 for (; iter != parts.end(); ++iter) { | 897 for (; iter != parts.end(); ++iter) { |
899 result += sep; | 898 sep.AppendToString(&result); |
900 result += *iter; | 899 result += *iter; |
901 } | 900 } |
902 | 901 |
903 return result; | 902 return result; |
904 } | 903 } |
905 | 904 |
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 | |
914 std::string JoinString(const std::vector<std::string>& parts, | 905 std::string JoinString(const std::vector<std::string>& parts, |
915 const std::string& separator) { | 906 StringPiece separator) { |
916 return JoinStringT(parts, separator); | 907 return JoinStringT(parts, separator); |
917 } | 908 } |
918 | 909 |
919 string16 JoinString(const std::vector<string16>& parts, | 910 string16 JoinString(const std::vector<string16>& parts, |
920 const string16& separator) { | 911 StringPiece16 separator) { |
921 return JoinStringT(parts, separator); | 912 return JoinStringT(parts, separator); |
922 } | 913 } |
923 | 914 |
| 915 } // namespace base |
| 916 |
924 template<class FormatStringType, class OutStringType> | 917 template<class FormatStringType, class OutStringType> |
925 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, | 918 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, |
926 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { | 919 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { |
927 size_t substitutions = subst.size(); | 920 size_t substitutions = subst.size(); |
928 | 921 |
929 size_t sub_length = 0; | 922 size_t sub_length = 0; |
930 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); | 923 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); |
931 iter != subst.end(); ++iter) { | 924 iter != subst.end(); ++iter) { |
932 sub_length += iter->length(); | 925 sub_length += iter->length(); |
933 } | 926 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 } | 1025 } |
1033 | 1026 |
1034 } // namespace | 1027 } // namespace |
1035 | 1028 |
1036 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 1029 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
1037 return lcpyT<char>(dst, src, dst_size); | 1030 return lcpyT<char>(dst, src, dst_size); |
1038 } | 1031 } |
1039 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1032 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
1040 return lcpyT<wchar_t>(dst, src, dst_size); | 1033 return lcpyT<wchar_t>(dst, src, dst_size); |
1041 } | 1034 } |
OLD | NEW |