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

Unified Diff: base/string_util.cc

Issue 347019: Convert ReplaceStringPlaceholders(std::string...) to take a (Closed)
Patch Set: a Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/string_util.h ('k') | chrome/browser/dom_ui/dom_ui_theme_source.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util.cc
diff --git a/base/string_util.cc b/base/string_util.cc
index b0ab3a6b7400026f49b24f299ea5fff5dcfc3db1..a62b905227ec58c7474629243bb9744309958074 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -1423,25 +1423,23 @@ void SplitStringAlongWhitespace(const std::string& str,
SplitStringAlongWhitespaceT(str, result);
}
-template<class StringType>
-StringType DoReplaceStringPlaceholders(const StringType& format_string,
- const std::vector<StringType>& subst,
- std::vector<size_t>* offsets) {
+template<class FormatStringType, class OutStringType>
+OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string,
+ const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) {
int substitutions = subst.size();
DCHECK(substitutions < 10);
int sub_length = 0;
- for (typename std::vector<StringType>::const_iterator iter = subst.begin();
- iter != subst.end();
- ++iter) {
+ for (typename std::vector<OutStringType>::const_iterator iter = subst.begin();
+ iter != subst.end(); ++iter) {
sub_length += (*iter).length();
}
- StringType formatted;
+ OutStringType formatted;
formatted.reserve(format_string.length() + sub_length);
std::vector<ReplacementOffset> r_offsets;
- for (typename StringType::const_iterator i = format_string.begin();
+ for (typename FormatStringType::const_iterator i = format_string.begin();
i != format_string.end(); ++i) {
if ('$' == *i) {
if (i + 1 != format_string.end()) {
@@ -1482,7 +1480,7 @@ string16 ReplaceStringPlaceholders(const string16& format_string,
return DoReplaceStringPlaceholders(format_string, subst, offsets);
}
-std::string ReplaceStringPlaceholders(const std::string& format_string,
+std::string ReplaceStringPlaceholders(const base::StringPiece& format_string,
const std::vector<std::string>& subst,
std::vector<size_t>* offsets) {
return DoReplaceStringPlaceholders(format_string, subst, offsets);
« no previous file with comments | « base/string_util.h ('k') | chrome/browser/dom_ui/dom_ui_theme_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698