Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: base/strings/string_util.cc

Issue 1237873004: Revert of Move JoinString to the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/string_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698