Index: third_party/libaddressinput/chromium/cpp/src/ruleset.cc |
diff --git a/third_party/libaddressinput/chromium/cpp/src/ruleset.cc b/third_party/libaddressinput/chromium/cpp/src/ruleset.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9090279ca27399f6b7ae892ee56525359b75ab2f |
--- /dev/null |
+++ b/third_party/libaddressinput/chromium/cpp/src/ruleset.cc |
@@ -0,0 +1,72 @@ |
+// Copyright (C) 2014 Google Inc. |
+// |
+// Licensed under the Apache License, Version 2.0 (the "License"); |
+// you may not use this file except in compliance with the License. |
+// You may obtain a copy of the License at |
+// |
+// http://www.apache.org/licenses/LICENSE-2.0 |
+// |
+// Unless required by applicable law or agreed to in writing, software |
+// distributed under the License is distributed on an "AS IS" BASIS, |
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+// See the License for the specific language governing permissions and |
+// limitations under the License. |
+ |
+#include "ruleset.h" |
+ |
+#include <libaddressinput/util/scoped_ptr.h> |
+ |
+#include <cassert> |
+#include <cstddef> |
+#include <map> |
+#include <string> |
+#include <utility> |
+ |
+#include "rule.h" |
+#include "util/stl_util.h" |
+ |
+namespace i18n { |
+namespace addressinput { |
+ |
+Ruleset::Ruleset(scoped_ptr<Rule> rule) |
+ : rule_(rule.Pass()), |
+ sub_regions_(), |
+ language_codes_() { |
+ assert(rule_ != NULL); |
+} |
+ |
+Ruleset::~Ruleset() { |
+ STLDeleteContainerPairSecondPointers( |
Evan Stade
2014/01/08 21:08:59
STLDeleteValues
please use gerrit instead
2014/01/09 00:38:11
Done.
|
+ sub_regions_.begin(), sub_regions_.end()); |
+ STLDeleteContainerPairSecondPointers( |
+ language_codes_.begin(), language_codes_.end()); |
+} |
+ |
+Ruleset* Ruleset::AddSubRegion(const std::string& sub_region, |
+ scoped_ptr<Rule> rule) { |
+ assert(sub_regions_.find(sub_region) == sub_regions_.end()); |
+ Ruleset* sub_region_rules = new Ruleset(rule.Pass()); |
+ 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.
|
+ return sub_region_rules; |
+} |
+ |
+void Ruleset::AddLanguageCode(const std::string& language_code, |
+ scoped_ptr<Rule> rule) { |
+ assert(language_codes_.find(language_code) == language_codes_.end()); |
+ language_codes_.insert(std::make_pair(language_code, rule.release())); |
+} |
+ |
+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.
|
+ std::map<std::string, Ruleset*>::const_iterator it = |
+ sub_regions_.find(sub_region); |
+ return it == sub_regions_.end() ? NULL : it->second; |
+} |
+ |
+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.
|
+ std::map<std::string, const Rule*>::const_iterator it = |
+ language_codes_.find(language_code); |
+ return it == language_codes_.end() ? NULL : it->second; |
+} |
+ |
+} // namespace addressinput |
+} // namespace i18n |