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

Unified Diff: third_party/libaddressinput/chromium/cpp/src/address_data.cc

Issue 208243005: Determine language code and type of format for address. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ctime include. Created 6 years, 9 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
Index: third_party/libaddressinput/chromium/cpp/src/address_data.cc
diff --git a/third_party/libaddressinput/chromium/cpp/src/address_data.cc b/third_party/libaddressinput/chromium/cpp/src/address_data.cc
index 51d36c6d9d63153296da075856c3cfe536f09cce..08da6ca153507e543ff5af83d100f3008bc052ee 100644
--- a/third_party/libaddressinput/chromium/cpp/src/address_data.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/address_data.cc
@@ -24,6 +24,7 @@
#include "region_data_constants.h"
#include "rule.h"
+#include "util/string_util.h"
namespace i18n {
namespace addressinput {
@@ -65,7 +66,16 @@ void AddressData::FormatForDisplay(std::vector<std::string>* lines) const {
rule.CopyFrom(Rule::GetDefault());
rule.ParseSerializedRule(RegionDataConstants::GetRegionData(country_code));
- const std::vector<std::vector<FormatElement> >& format = rule.GetFormat();
+ // If latinized rules are available and the |language_code| of this address is
+ // not the primary language code for the region, then use the latinized
+ // formatting rules.
+ const std::vector<std::vector<FormatElement> >& format =
+ rule.GetLatinFormat().empty() ||
+ language_code.empty() ||
+ NormalizeLanguageCode(language_code) ==
+ NormalizeLanguageCode(rule.GetLanguage())
+ ? rule.GetFormat() : rule.GetLatinFormat();
+
for (size_t i = 0; i < format.size(); ++i) {
std::string line;
for (size_t j = 0; j < format[i].size(); ++j) {
@@ -107,28 +117,5 @@ void AddressData::SetFieldValue(AddressField field, const std::string& value) {
}
}
-const std::string& AddressData::GuessLanguageCode() const {
- Rule rule;
- rule.CopyFrom(Rule::GetDefault());
- if (!rule.ParseSerializedRule(
- RegionDataConstants::GetRegionData(country_code))) {
- return language_code;
- }
-
- std::vector<std::string>::const_iterator lang_it =
- std::find(rule.GetLanguages().begin(),
- rule.GetLanguages().end(),
- language_code);
- if (lang_it != rule.GetLanguages().end()) {
- return *lang_it;
- }
-
- if (!rule.GetLanguage().empty()) {
- return rule.GetLanguage();
- }
-
- return language_code;
-}
-
} // namespace addressinput
} // namespace i18n

Powered by Google App Engine
This is Rietveld 408576698