Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (C) 2013 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. | |
| 47 explicit Ruleset(scoped_ptr<Rule> rule); | |
| 48 | |
| 49 ~Ruleset(); | |
| 50 | |
| 51 // Returns the region-wide rule in the default language of the country. The | |
| 52 // caller does not own the result. | |
| 53 const Rule* GetRule() const; | |
|
Evan Stade
2014/01/06 22:54:19
return a const ref
also, why not rule() (i.e. c h
please use gerrit instead
2014/01/06 23:44:35
Done.
| |
| 54 | |
| 55 // Adds and returns a ruleset for |sub_region| with the subregion-wide |rule| | |
| 56 // in the default language of the country. The caller does not own the result. | |
| 57 Ruleset* AddSubRegion(const std::string& sub_region, scoped_ptr<Rule> rule); | |
| 58 | |
| 59 // Adds a language-specific |rule| for |language_code| for this region. | |
| 60 void AddLanguageCode(const std::string& language_code, scoped_ptr<Rule> rule); | |
| 61 | |
| 62 // Returns the set of rules for |sub_region|. The result can be NULL. The | |
| 63 // caller does not own the result. | |
| 64 Ruleset* GetSubRegion(const std::string& sub_region) const; | |
| 65 | |
| 66 // Returns the language-specific rule for |language_code|. The result can be | |
| 67 // NULL. The caller does not own the result. | |
| 68 const Rule* GetLanguageCode(const std::string& language_code) const; | |
| 69 | |
| 70 private: | |
| 71 // The region-wide rule in the default language of the country. | |
| 72 scoped_ptr<const Rule> rule_; | |
| 73 | |
| 74 // Owned rulesets for sub-regions. | |
| 75 std::map<std::string, Ruleset*> sub_regions_; | |
| 76 | |
| 77 // Owned language-specific rules for the region. | |
| 78 std::map<std::string, const Rule*> language_codes_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(Ruleset); | |
| 81 }; | |
| 82 | |
| 83 } // namespace addressinput | |
| 84 } // namespace i18n | |
| 85 | |
| 86 #endif // I18N_ADDRESSINPUT_RULESET_H_ | |
| OLD | NEW |