summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/l10n_util.cc4
-rw-r--r--base/string_util.cc18
-rw-r--r--base/string_util.h2
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.cc6
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc10
5 files changed, 20 insertions, 20 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index 854d0a0..c04d3d5 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -525,6 +525,10 @@ static string16 GetStringF(int message_id,
const string16& c,
const string16& d,
std::vector<size_t>* offsets) {
+ // TODO(tc): We could save a string copy if we got the raw string as
+ // a StringPiece and were able to call ReplaceStringPlaceholders with
+ // a StringPiece format string and string16 substitution strings. In
+ // practice, the strings should be relatively short.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const string16& format_string = rb.GetLocalizedString(message_id);
std::vector<string16> subst;
diff --git a/base/string_util.cc b/base/string_util.cc
index b0ab3a6..a62b905 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);
diff --git a/base/string_util.h b/base/string_util.h
index f128f99..1c58e91 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -550,7 +550,7 @@ string16 ReplaceStringPlaceholders(const string16& format_string,
const std::vector<string16>& subst,
std::vector<size_t>* 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);
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc
index f81193d..49e227f 100644
--- a/chrome/browser/dom_ui/dom_ui_theme_source.cc
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc
@@ -193,9 +193,8 @@ void DOMUIThemeSource::InitNewTabCSS() {
IDR_NEW_TAB_THEME_CSS));
// Create the string from our template and the replacements.
- std::string format_string = new_tab_theme_css.as_string();
const std::string css_string = ReplaceStringPlaceholders(
- format_string, subst, NULL);
+ new_tab_theme_css, subst, NULL);
new_tab_css_ = ReplaceStringPlaceholders(
css_string, subst2, NULL);
}
@@ -227,9 +226,8 @@ void DOMUIThemeSource::InitNewIncognitoTabCSS() {
IDR_NEW_INCOGNITO_TAB_THEME_CSS));
// Create the string from our template and the replacements.
- std::string format_string = new_tab_theme_css.as_string();
new_incognito_tab_css_ = ReplaceStringPlaceholders(
- format_string, subst, NULL);
+ new_tab_theme_css, subst, NULL);
}
void DOMUIThemeSource::SendNewTabCSS(int request_id,
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index 428281e..2a69afd 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -325,7 +325,7 @@ class ExtensionImpl : public ExtensionBase {
std::string message =
ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages);
- std::vector<string16> substitutions;
+ std::vector<std::string> substitutions;
if (args[1]->IsNull() || args[1]->IsUndefined()) {
// chrome.i18n.getMessage("message_name");
// chrome.i18n.getMessage("message_name", null);
@@ -333,7 +333,7 @@ class ExtensionImpl : public ExtensionBase {
} else if (args[1]->IsString()) {
// chrome.i18n.getMessage("message_name", "one param");
std::string substitute = *v8::String::Utf8Value(args[1]->ToString());
- substitutions.push_back(UTF8ToUTF16(substitute));
+ substitutions.push_back(substitute);
} else if (args[1]->IsArray()) {
// chrome.i18n.getMessage("message_name", ["more", "params"]);
v8::Array* placeholders = static_cast<v8::Array*>(*args[1]);
@@ -343,15 +343,15 @@ class ExtensionImpl : public ExtensionBase {
std::string substitute =
*v8::String::Utf8Value(
placeholders->Get(v8::Integer::New(i))->ToString());
- substitutions.push_back(UTF8ToUTF16(substitute));
+ substitutions.push_back(substitute);
}
} else {
NOTREACHED() << "Couldn't parse second parameter.";
return v8::Undefined();
}
- return v8::String::New(UTF16ToUTF8(ReplaceStringPlaceholders(
- UTF8ToUTF16(message), substitutions, NULL)).c_str());
+ return v8::String::New(ReplaceStringPlaceholders(
+ message, substitutions, NULL).c_str());
}
// Common code for starting an API request to the browser. |value_args|