Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/lookup_key.cc

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge smaller patches. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "lookup_key.h"
16
17 #include <libaddressinput/address_field.h>
18 #include <libaddressinput/util/basictypes.h>
19 #include <libaddressinput/util/scoped_ptr.h>
20
21 #include <cassert>
22 #include <cstddef>
23 #include <string>
24 #include <utility>
25
26 #include "rule.h"
27
28 namespace i18n {
29 namespace addressinput {
30
31 LookupKey::LookupKey(const std::string& country_code)
32 : value_("data/" + country_code),
33 level_(COUNTRY),
34 rule_(),
35 sub_keys_(),
36 language_code_keys_() {}
37
38 LookupKey::~LookupKey() {
39 for (LookupKeys::const_iterator subkey_it = sub_keys_.begin();
40 subkey_it != sub_keys_.end(); ++subkey_it) {
41 delete subkey_it->second;
42 }
43 for (LookupKeys::const_iterator rule_it = language_code_keys_.begin();
44 rule_it != language_code_keys_.end(); ++rule_it) {
45 delete rule_it->second;
46 }
47 }
48
49 const std::string& LookupKey::GetKeyValue() const {
50 return value_;
51 }
52
53 AddressField LookupKey::GetLevel() const {
54 return level_;
55 }
56
57 void LookupKey::SetRule(const Rule* rule) {
58 assert(rule != NULL);
59 assert(rule_ == NULL);
60 rule_.reset(rule);
61 }
62
63 const Rule* LookupKey::GetRule() const {
64 return rule_.get();
65 }
66
67 LookupKey* LookupKey::AddSubKey(const std::string& sub_key) {
68 assert(sub_keys_.find(sub_key) == sub_keys_.end());
69 AddressField sub_level = static_cast<AddressField>(level_ + 1);
70 assert(sub_level <= DEPENDENT_LOCALITY);
71 LookupKey* sub_lookup_key = new LookupKey(value_ + "/" + sub_key, sub_level);
72 sub_keys_.insert(std::make_pair(sub_key, sub_lookup_key));
73 return sub_lookup_key;
74 }
75
76 LookupKey* LookupKey::AddLanguageCodeKey(const std::string& language_code) {
77 assert(language_code_keys_.find(language_code) == language_code_keys_.end());
78 LookupKey* language_code_key =
79 new LookupKey(value_ + "--" + language_code, level_);
80 language_code_keys_.insert(std::make_pair(language_code, language_code_key));
81 return language_code_key;
82 }
83
84 LookupKey::LookupKey(const std::string& key_value, AddressField level)
85 : value_(key_value),
86 level_(level),
87 rule_(),
88 sub_keys_(),
89 language_code_keys_() {}
90
91 } // namespace addressinput
92 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698