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

Unified Diff: third_party/libaddressinput/chromium/cpp/src/rule.h

Issue 131223004: [rac] Format an address for display. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge. 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/rule.h
diff --git a/third_party/libaddressinput/chromium/cpp/src/rule.h b/third_party/libaddressinput/chromium/cpp/src/rule.h
index 9e6fa098405f8971d5c3dcec6842ae86cd7f8b97..6a7410d82503a4a834d53b789459fd91a04c95a7 100644
--- a/third_party/libaddressinput/chromium/cpp/src/rule.h
+++ b/third_party/libaddressinput/chromium/cpp/src/rule.h
@@ -26,7 +26,34 @@
namespace i18n {
namespace addressinput {
-// Stores the validation rules. Sample usage:
+// Stores an element in the format of an address as it should be displayed on an
+// envelope. The element can be either a literal string, like " ", or a field,
+// like ADMIN_AREA.
+struct FormatElement {
+ // Builds an element of address format for |field|.
+ explicit FormatElement(AddressField field);
+
+ // Builds an element of address format for |literal|. The literal should not
+ // be empty.
+ explicit FormatElement(const std::string& literal);
+
+ ~FormatElement();
+
+ // Returns true if this is a field element.
+ bool IsField() const { return literal.empty(); }
+
+ bool operator==(const FormatElement& other) const;
+
+ // The field for this element in address format. Should be used only if
+ // |literal| is an empty string.
+ AddressField field;
+
+ // The literal string for this element in address format. If empty, then this
+ // is a field element.
+ std::string literal;
+};
+
+// Stores the validation, input, and display rules for an address. Sample usage:
// Rule rule;
// if (rule.ParseSerializedRule("{\"fmt\": \"%A%n%C%S %Z\"}")) {
// Process(rule.GetFormat());
@@ -48,8 +75,8 @@ class Rule {
// format (JSON dictionary).
bool ParseSerializedRule(const std::string& serialized_rule);
- // Returns the address format for this rule.
- const std::vector<std::vector<AddressField> >& GetFormat() const {
+ // Returns the format of the address as it should appear on an envelope.
+ const std::vector<std::vector<FormatElement> >& GetFormat() const {
return format_;
}
@@ -98,7 +125,7 @@ class Rule {
int GetInvalidFieldMessageId(AddressField field) const;
private:
- std::vector<std::vector<AddressField> > format_;
+ std::vector<std::vector<FormatElement> > format_;
std::vector<AddressField> required_;
std::vector<std::string> sub_keys_;
std::vector<std::string> languages_;

Powered by Google App Engine
This is Rietveld 408576698