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 131223004: [rac] Format an address for display. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 11 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 9b86cc8585f79e18577f814e6a1bd185710c3d2e..15f615375e1c5e8649f14a89899bff4ee0453d46 100644
--- a/third_party/libaddressinput/chromium/cpp/src/address_data.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/address_data.cc
@@ -17,11 +17,69 @@
#include <libaddressinput/address_field.h>
#include <cassert>
+#include <cstddef>
#include <string>
+#include <vector>
+
+#include "region_data_constants.h"
+#include "rule.h"
namespace i18n {
namespace addressinput {
+void AddressData::BuildDisplayLines(std::vector<std::string>* lines) const {
+ assert(lines != NULL);
+ lines->clear();
+
+ Rule rule;
+ rule.CopyFrom(Rule::GetDefault());
+ rule.ParseSerializedRule(RegionDataConstants::GetRegionData(country_code));
+
+ for (size_t i = 0; i < rule.GetFormat().size(); ++i) {
+ std::string line;
+ for (size_t j = 0; j < rule.GetFormat()[i].size(); ++j) {
+ const FormatElement& element = rule.GetFormat()[i][j];
Evan Stade 2014/01/14 18:05:22 rule.GetFormat()[i] is used enough to get a local
please use gerrit instead 2014/01/14 23:21:12 Done.
+ switch (element.type) {
+ case FormatElement::LITERAL:
+ line += element.literal;
+ break;
+
+ case FormatElement::FIELD:
+ if (element.field == STREET_ADDRESS) {
+ // A street address is always surrounded by either newlines or
+ // spaces.
+ if (rule.GetFormat()[i].size() == 1) {
+ lines->insert(lines->end(),
+ address_lines.begin(),
+ address_lines.end());
+ } else {
+ for (size_t k = 0; k < address_lines.size(); ++k) {
Evan Stade 2014/01/14 18:05:22 I don't understand why street address line 2 might
please use gerrit instead 2014/01/14 23:21:12 Take the https://i18napis.appspot.com/ssl-address/
Evan Stade 2014/01/14 23:45:36 I think that would imply there's only one street a
please use gerrit instead 2014/01/15 00:05:47 Combined the cases and simplified the code. If Chr
+ line += address_lines[k];
+ if (k < address_lines.size() - 1) {
+ line += " ";
+ }
+ }
+ }
+ } else {
+ const std::string& field = GetField(element.field);
+ if (!field.empty()) {
+ line += field;
+ }
+ }
+ break;
+
+ default:
+ assert(false);
+ break;
+ }
+ }
+
+ if (!line.empty()) {
+ lines->push_back(line);
+ }
+ }
+}
+
const std::string& AddressData::GetField(AddressField field) const {
Evan Stade 2014/01/14 18:05:22 nit: should be called GetFieldValue
please use gerrit instead 2014/01/14 23:21:12 Done.
switch (field) {
case COUNTRY:

Powered by Google App Engine
This is Rietveld 408576698