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 #include "ruleset.h" |
| 16 |
| 17 #include <libaddressinput/util/scoped_ptr.h> |
| 18 |
| 19 #include <cassert> |
| 20 #include <cstddef> |
| 21 #include <map> |
| 22 #include <string> |
| 23 #include <utility> |
| 24 |
| 25 #include "rule.h" |
| 26 #include "util/stl_util.h" |
| 27 |
| 28 namespace i18n { |
| 29 namespace addressinput { |
| 30 |
| 31 Ruleset::Ruleset(scoped_ptr<Rule> rule) |
| 32 : rule_(rule.Pass()), |
| 33 sub_regions_(), |
| 34 language_codes_() { |
| 35 assert(rule_ != NULL); |
| 36 } |
| 37 |
| 38 Ruleset::~Ruleset() { |
| 39 STLDeleteValues(&sub_regions_); |
| 40 STLDeleteValues(&language_codes_); |
| 41 } |
| 42 |
| 43 Ruleset* Ruleset::AddSubRegionRuleset(const std::string& sub_region, |
| 44 scoped_ptr<Rule> rule) { |
| 45 assert(sub_regions_.find(sub_region) == sub_regions_.end()); |
| 46 Ruleset* sub_region_ruleset = new Ruleset(rule.Pass()); |
| 47 sub_regions_[sub_region] = sub_region_ruleset; |
| 48 return sub_region_ruleset; |
| 49 } |
| 50 |
| 51 void Ruleset::AddLanguageCodeRule(const std::string& language_code, |
| 52 scoped_ptr<Rule> rule) { |
| 53 assert(language_codes_.find(language_code) == language_codes_.end()); |
| 54 language_codes_[language_code] = rule.release(); |
| 55 } |
| 56 |
| 57 } // namespace addressinput |
| 58 } // namespace i18n |
OLD | NEW |