Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (C) 2014 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (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 | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #ifndef I18N_ADDRESSINPUT_RULESET_H_ | |
| 16 #define I18N_ADDRESSINPUT_RULESET_H_ | |
| 17 | |
| 18 #include <libaddressinput/util/basictypes.h> | |
| 19 #include <libaddressinput/util/scoped_ptr.h> | |
| 20 | |
| 21 #include <map> | |
| 22 #include <string> | |
| 23 | |
| 24 namespace i18n { | |
| 25 namespace addressinput { | |
| 26 | |
| 27 class Rule; | |
| 28 | |
| 29 // A recursive data structure that stores a set of rules for a region. Can store | |
| 30 // the rules for a country, its administrative areas, localities, and dependent | |
| 31 // localities, in addition to the language-specific rules. | |
| 32 // | |
| 33 // Example for Canada and some of its provinces: | |
| 34 // CA-->fr | |
| 35 // | | |
| 36 // ------------------------------------- | |
| 37 // | | | | | | |
| 38 // v v v v v | |
| 39 // AB-->fr BC-->fr MB-->fr NB-->fr NL-->fr | |
| 40 // | |
| 41 // The rules in Canada are in English by default. Each rule also has a French | |
| 42 // language version. | |
| 43 class Ruleset { | |
| 44 public: | |
| 45 // Builds a ruleset with a region-wide |rule| in the default language of the | |
| 46 // country. The |rule| should not be NULL. | |
| 47 explicit Ruleset(scoped_ptr<Rule> rule); | |
| 48 | |
| 49 ~Ruleset(); | |
| 50 | |
| 51 // Returns the region-wide rule in the default language of the country. | |
| 52 const Rule& rule() const { return *rule_.get(); } | |
| 53 | |
| 54 // Adds and returns a ruleset for |sub_region| with the subregion-wide |rule| | |
| 55 // in the default language of the country. The caller does not own the result. | |
| 56 Ruleset* AddSubRegionRuleset(const std::string& sub_region, | |
| 57 scoped_ptr<Rule> rule); | |
|
Evan Stade
2014/01/09 01:01:39
hmm, I think the second param should be a Ruleset.
please use gerrit instead
2014/01/09 01:19:08
Done.
| |
| 58 | |
| 59 // Adds a language-specific |rule| for |language_code| for this region. | |
| 60 void AddLanguageCodeRule(const std::string& language_code, | |
| 61 scoped_ptr<Rule> rule); | |
| 62 | |
| 63 private: | |
| 64 // The region-wide rule in the default language of the country. | |
| 65 scoped_ptr<const Rule> rule_; | |
| 66 | |
| 67 // Owned rulesets for sub-regions. | |
| 68 std::map<std::string, Ruleset*> sub_regions_; | |
| 69 | |
| 70 // Owned language-specific rules for the region. | |
| 71 std::map<std::string, const Rule*> language_codes_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(Ruleset); | |
| 74 }; | |
| 75 | |
| 76 } // namespace addressinput | |
| 77 } // namespace i18n | |
| 78 | |
| 79 #endif // I18N_ADDRESSINPUT_RULESET_H_ | |
| OLD | NEW |