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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/address_ui.cc

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge smaller patches. Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (C) 2013 Google Inc. 1 // Copyright (C) 2013 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 14 matching lines...) Expand all
25 #include "grit.h" 25 #include "grit.h"
26 #include "messages.h" 26 #include "messages.h"
27 #include "region_data_constants.h" 27 #include "region_data_constants.h"
28 #include "rule.h" 28 #include "rule.h"
29 29
30 namespace i18n { 30 namespace i18n {
31 namespace addressinput { 31 namespace addressinput {
32 32
33 namespace { 33 namespace {
34 34
35 // Parses the default region data into the static Rule object and returns a
36 // constant reference to this object. Cannot return a copy of the object,
37 // because Rule objects are not copyable.
38 const Rule& InitDefaultRule() {
39 static Rule rule;
40 rule.ParseSerializedRule(RegionDataConstants::GetDefaultRegionData());
41 return rule;
please use gerrit instead 2013/12/16 23:41:38 (This code is moved into Rule.cc.) You mentioned
42 }
43
44 // Returns the constant reference to the Rule object from InitDefaultRule(). The
45 // static object is in InitDefaultRule(), but this function maintains a constant
46 // static reference to it. The constant static reference avoids re-parsing the
47 // default region data.
48 const Rule& GetDefaultRule() {
49 static const Rule& kDefaultRule(InitDefaultRule());
50 return kDefaultRule;
51 }
52
53 int GetMessageIdForField(AddressField field, 35 int GetMessageIdForField(AddressField field,
54 int admin_area_name_message_id, 36 int admin_area_name_message_id,
55 int postal_code_name_message_id) { 37 int postal_code_name_message_id) {
56 switch (field) { 38 switch (field) {
57 case COUNTRY: 39 case COUNTRY:
58 return IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL; 40 return IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL;
59 case ADMIN_AREA: 41 case ADMIN_AREA:
60 return admin_area_name_message_id; 42 return admin_area_name_message_id;
61 case LOCALITY: 43 case LOCALITY:
62 return IDS_LIBADDRESSINPUT_I18N_LOCALITY_LABEL; 44 return IDS_LIBADDRESSINPUT_I18N_LOCALITY_LABEL;
(...skipping 24 matching lines...) Expand all
87 const std::vector<std::string>& GetRegionCodes() { 69 const std::vector<std::string>& GetRegionCodes() {
88 return RegionDataConstants::GetRegionCodes(); 70 return RegionDataConstants::GetRegionCodes();
89 } 71 }
90 72
91 std::vector<AddressUiComponent> BuildComponents( 73 std::vector<AddressUiComponent> BuildComponents(
92 const std::string& region_code, 74 const std::string& region_code,
93 const Localization& localization) { 75 const Localization& localization) {
94 std::vector<AddressUiComponent> result; 76 std::vector<AddressUiComponent> result;
95 77
96 Rule rule; 78 Rule rule;
97 rule.CopyFrom(GetDefaultRule()); 79 rule.CopyFrom(Rule::GetDefault());
98 if (!rule.ParseSerializedRule( 80 if (!rule.ParseSerializedRule(
99 RegionDataConstants::GetRegionData(region_code))) { 81 RegionDataConstants::GetRegionData(region_code))) {
100 return result; 82 return result;
101 } 83 }
102 84
103 bool previous_field_is_newline = true; 85 bool previous_field_is_newline = true;
104 bool next_field_is_newline = true; 86 bool next_field_is_newline = true;
105 for (std::vector<AddressField>::const_iterator field_it = 87 for (std::vector<AddressField>::const_iterator field_it =
106 rule.GetFormat().begin(); 88 rule.GetFormat().begin();
107 field_it != rule.GetFormat().end(); ++field_it) { 89 field_it != rule.GetFormat().end(); ++field_it) {
(...skipping 14 matching lines...) Expand all
122 GetMessageIdForField(*field_it, rule.GetAdminAreaNameMessageId(), 104 GetMessageIdForField(*field_it, rule.GetAdminAreaNameMessageId(),
123 rule.GetPostalCodeNameMessageId())); 105 rule.GetPostalCodeNameMessageId()));
124 result.push_back(component); 106 result.push_back(component);
125 } 107 }
126 108
127 return result; 109 return result;
128 } 110 }
129 111
130 } // namespace addressinput 112 } // namespace addressinput
131 } // namespace i18n 113 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698