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

Side by Side Diff: base/string_util.cc

Issue 10828217: string_util support for joining strings using strings not just chars. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: string_util support for joining strings on strings in addition to chars. Created 8 years, 4 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/string_util.h ('k') | base/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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 return TokenizeT(str, delimiters, tokens); 743 return TokenizeT(str, delimiters, tokens);
744 } 744 }
745 745
746 size_t Tokenize(const base::StringPiece& str, 746 size_t Tokenize(const base::StringPiece& str,
747 const base::StringPiece& delimiters, 747 const base::StringPiece& delimiters,
748 std::vector<base::StringPiece>* tokens) { 748 std::vector<base::StringPiece>* tokens) {
749 return TokenizeT(str, delimiters, tokens); 749 return TokenizeT(str, delimiters, tokens);
750 } 750 }
751 751
752 template<typename STR> 752 template<typename STR>
753 static STR JoinStringT(const std::vector<STR>& parts, 753 static STR JoinStringT(const std::vector<STR>& parts, const STR& sep) {
754 typename STR::value_type sep) {
755 if (parts.empty()) 754 if (parts.empty())
756 return STR(); 755 return STR();
757 756
758 STR result(parts[0]); 757 STR result(parts[0]);
759 typename std::vector<STR>::const_iterator iter = parts.begin(); 758 typename std::vector<STR>::const_iterator iter = parts.begin();
760 ++iter; 759 ++iter;
761 760
762 for (; iter != parts.end(); ++iter) { 761 for (; iter != parts.end(); ++iter) {
763 result += sep; 762 result += sep;
764 result += *iter; 763 result += *iter;
765 } 764 }
766 765
767 return result; 766 return result;
768 } 767 }
769 768
770 std::string JoinString(const std::vector<std::string>& parts, char sep) { 769 std::string JoinString(const std::vector<std::string>& parts, char sep) {
771 return JoinStringT(parts, sep); 770 return JoinStringT(parts, std::string(1, sep));
772 } 771 }
773 772
774 string16 JoinString(const std::vector<string16>& parts, char16 sep) { 773 string16 JoinString(const std::vector<string16>& parts, char16 sep) {
775 return JoinStringT(parts, sep); 774 return JoinStringT(parts, string16(1, sep));
775 }
776
777 std::string JoinString(const std::vector<std::string>& parts,
778 const std::string& separator) {
779 return JoinStringT(parts, separator);
780 }
781
782 string16 JoinString(const std::vector<string16>& parts,
783 const string16& separator) {
784 return JoinStringT(parts, separator);
776 } 785 }
777 786
778 template<class FormatStringType, class OutStringType> 787 template<class FormatStringType, class OutStringType>
779 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, 788 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string,
780 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { 789 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) {
781 size_t substitutions = subst.size(); 790 size_t substitutions = subst.size();
782 791
783 size_t sub_length = 0; 792 size_t sub_length = 0;
784 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); 793 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin();
785 iter != subst.end(); ++iter) { 794 iter != subst.end(); ++iter) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 } 1051 }
1043 1052
1044 } // namespace 1053 } // namespace
1045 1054
1046 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 1055 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
1047 return lcpyT<char>(dst, src, dst_size); 1056 return lcpyT<char>(dst, src, dst_size);
1048 } 1057 }
1049 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1058 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1050 return lcpyT<wchar_t>(dst, src, dst_size); 1059 return lcpyT<wchar_t>(dst, src, dst_size);
1051 } 1060 }
OLDNEW
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698