aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkeghani@google.com <keghani@google.com@38ededc0-08b8-5190-f2ac-b31f878777ad>2014-05-27 12:47:39 +0000
committerkeghani@google.com <keghani@google.com@38ededc0-08b8-5190-f2ac-b31f878777ad>2014-05-27 12:47:39 +0000
commit99f34084b65e13adc4553d93409318384c4906ae (patch)
tree8b6b9e90d551bd217a24fefa220fc78606892028
parent9f5d76277e616e8fe924e8f4e2b0e0cd1f31f1cf (diff)
downloadsrc-99f34084b65e13adc4553d93409318384c4906ae.tar.gz
Address outstanding comments from codereview.appspot.com/100630043.
git-svn-id: http://libaddressinput.googlecode.com/svn/trunk@252 38ededc0-08b8-5190-f2ac-b31f878777ad
-rw-r--r--cpp/include/libaddressinput/localization.h8
-rw-r--r--cpp/src/localization.cc29
2 files changed, 19 insertions, 18 deletions
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 @@ class Localization {
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 @@ class Localization {
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 @@ std::string Localization::GetErrorMessage(const AddressData& address,
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 @@ std::string Localization::GetErrorMessage(const AddressData& address,
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 @@ std::string Localization::GetErrorMessageForPostalCode(
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 @@ std::string Localization::GetErrorMessageForPostalCode(
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 @@ std::string Localization::GetErrorMessageForPostalCode(
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 @@ std::string Localization::GetErrorMessageForPostalCode(
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 @@ std::string Localization::GetErrorMessageForPostalCode(
}
}
-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