Address outstanding comments from codereview.appspot.com/100630043.
diff --git a/cpp/include/libaddressinput/localization.h b/cpp/include/libaddressinput/localization.h
index c25ad4a..08b5964 100644
--- a/cpp/include/libaddressinput/localization.h
+++ b/cpp/include/libaddressinput/localization.h
@@ -61,7 +61,7 @@
AddressField field,
AddressProblem problem,
bool enable_examples,
- bool enable_links);
+ bool enable_links) const;
// Sets the language for the strings. The only supported language is "en"
// until we have translations.
@@ -86,11 +86,7 @@
AddressProblem problem,
bool uses_postal_code_as_label,
std::string postal_code_example,
- std::string post_service_url);
-
- // Calls |parameters.push_back| with 2 strings: the opening and closing tags
- // of the given URL's HTML link.
- void PushBackUrl(std::vector<std::string>& parameters, const std::string url);
+ std::string post_service_url) const;
// The string getter.
std::string (*get_string_)(int);
diff --git a/cpp/src/localization.cc b/cpp/src/localization.cc
index 6b16e35..951f1a7 100644
--- a/cpp/src/localization.cc
+++ b/cpp/src/localization.cc
@@ -27,6 +27,16 @@
#include "rule.h"
#include "util/string_util.h"
+namespace {
+
+void PushBackUrl(std::vector<std::string>& parameters, const std::string url) {
+ // TODO: HTML-escape the "url".
+ parameters.push_back("<a href=\"" + url + "\">");
+ parameters.push_back("</a>");
+}
+
+} // namespace
+
namespace i18n {
namespace addressinput {
@@ -65,7 +75,7 @@
AddressField field,
AddressProblem problem,
bool enable_examples,
- bool enable_links) {
+ bool enable_links) const {
if (field == POSTAL_CODE) {
Rule rule;
rule.CopyFrom(Rule::GetDefault());
@@ -78,6 +88,8 @@
if (enable_links) {
post_service_url = rule.GetPostServiceUrl();
}
+ } else {
+ assert(false);
}
// If we can't parse the serialized rule |uses_postal_code_as_label| will be
// determined from the default rule.
@@ -133,7 +145,7 @@
AddressProblem problem,
bool uses_postal_code_as_label,
std::string postal_code_example,
- std::string post_service_url) {
+ std::string post_service_url) const {
int message_id;
std::vector<std::string> parameters;
if (problem == MISSING_REQUIRED_FIELD) {
@@ -142,7 +154,7 @@
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE_AND_URL :
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE_AND_URL;
parameters.push_back(postal_code_example);
- Localization::PushBackUrl(parameters, post_service_url);
+ PushBackUrl(parameters, post_service_url);
} else if (!postal_code_example.empty()) {
message_id = uses_postal_code_as_label ?
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE :
@@ -158,7 +170,7 @@
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE_AND_URL :
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE_AND_URL;
parameters.push_back(postal_code_example);
- Localization::PushBackUrl(parameters, post_service_url);
+ PushBackUrl(parameters, post_service_url);
} else if (!postal_code_example.empty()) {
message_id = uses_postal_code_as_label ?
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE :
@@ -175,7 +187,7 @@
message_id = uses_postal_code_as_label ?
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE_URL :
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP_URL;
- Localization::PushBackUrl(parameters, post_service_url);
+ PushBackUrl(parameters, post_service_url);
} else {
message_id = uses_postal_code_as_label ?
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE :
@@ -190,12 +202,5 @@
}
}
-void Localization::PushBackUrl(std::vector<std::string>& parameters,
- const std::string url) {
- // TODO: HTML-escape the "url".
- parameters.push_back("<a href=\"" + url + "\">");
- parameters.push_back("</a>");
-}
-
} // namespace addressinput
} // namespace i18n