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 #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 STLDeleteContainerPairSecondPointers( | |
|
Evan Stade
2014/01/08 21:08:59
STLDeleteValues
please use gerrit instead
2014/01/09 00:38:11
Done.
| |
| 40 sub_regions_.begin(), sub_regions_.end()); | |
| 41 STLDeleteContainerPairSecondPointers( | |
| 42 language_codes_.begin(), language_codes_.end()); | |
| 43 } | |
| 44 | |
| 45 Ruleset* Ruleset::AddSubRegion(const std::string& sub_region, | |
| 46 scoped_ptr<Rule> rule) { | |
| 47 assert(sub_regions_.find(sub_region) == sub_regions_.end()); | |
| 48 Ruleset* sub_region_rules = new Ruleset(rule.Pass()); | |
| 49 sub_regions_.insert(std::make_pair(sub_region, sub_region_rules)); | |
|
Evan Stade
2014/01/08 21:08:59
Any reason you can't use the easier-to-read versio
please use gerrit instead
2014/01/09 00:38:11
No reason AFAIK. Done.
| |
| 50 return sub_region_rules; | |
| 51 } | |
| 52 | |
| 53 void Ruleset::AddLanguageCode(const std::string& language_code, | |
| 54 scoped_ptr<Rule> rule) { | |
| 55 assert(language_codes_.find(language_code) == language_codes_.end()); | |
| 56 language_codes_.insert(std::make_pair(language_code, rule.release())); | |
| 57 } | |
| 58 | |
| 59 Ruleset* Ruleset::GetSubRegion(const std::string& sub_region) const { | |
|
Evan Stade
2014/01/08 21:08:59
this is not used anywhere --- please add it when i
please use gerrit instead
2014/01/09 00:38:11
Done.
| |
| 60 std::map<std::string, Ruleset*>::const_iterator it = | |
| 61 sub_regions_.find(sub_region); | |
| 62 return it == sub_regions_.end() ? NULL : it->second; | |
| 63 } | |
| 64 | |
| 65 const Rule* Ruleset::GetLanguageCode(const std::string& language_code) const { | |
|
Evan Stade
2014/01/08 21:08:59
this is not used anywhere --- please add it when i
please use gerrit instead
2014/01/09 00:38:11
Done.
| |
| 66 std::map<std::string, const Rule*>::const_iterator it = | |
| 67 language_codes_.find(language_code); | |
| 68 return it == language_codes_.end() ? NULL : it->second; | |
| 69 } | |
| 70 | |
| 71 } // namespace addressinput | |
| 72 } // namespace i18n | |
| OLD | NEW |