| Index: third_party/libaddressinput/chromium/cpp/src/lookup_key.cc
|
| diff --git a/third_party/libaddressinput/chromium/cpp/src/lookup_key.cc b/third_party/libaddressinput/chromium/cpp/src/lookup_key.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7acdc57eef33ff3c9321ffe739bce66e1ebe78bc
|
| --- /dev/null
|
| +++ b/third_party/libaddressinput/chromium/cpp/src/lookup_key.cc
|
| @@ -0,0 +1,92 @@
|
| +// Copyright (C) 2013 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 "lookup_key.h"
|
| +
|
| +#include <libaddressinput/address_field.h>
|
| +#include <libaddressinput/util/basictypes.h>
|
| +#include <libaddressinput/util/scoped_ptr.h>
|
| +
|
| +#include <cassert>
|
| +#include <cstddef>
|
| +#include <string>
|
| +#include <utility>
|
| +
|
| +#include "rule.h"
|
| +
|
| +namespace i18n {
|
| +namespace addressinput {
|
| +
|
| +LookupKey::LookupKey(const std::string& country_code)
|
| + : value_("data/" + country_code),
|
| + level_(COUNTRY),
|
| + rule_(),
|
| + sub_keys_(),
|
| + language_code_keys_() {}
|
| +
|
| +LookupKey::~LookupKey() {
|
| + for (LookupKeys::const_iterator subkey_it = sub_keys_.begin();
|
| + subkey_it != sub_keys_.end(); ++subkey_it) {
|
| + delete subkey_it->second;
|
| + }
|
| + for (LookupKeys::const_iterator rule_it = language_code_keys_.begin();
|
| + rule_it != language_code_keys_.end(); ++rule_it) {
|
| + delete rule_it->second;
|
| + }
|
| +}
|
| +
|
| +const std::string& LookupKey::GetKeyValue() const {
|
| + return value_;
|
| +}
|
| +
|
| +AddressField LookupKey::GetLevel() const {
|
| + return level_;
|
| +}
|
| +
|
| +void LookupKey::SetRule(const Rule* rule) {
|
| + assert(rule != NULL);
|
| + assert(rule_ == NULL);
|
| + rule_.reset(rule);
|
| +}
|
| +
|
| +const Rule* LookupKey::GetRule() const {
|
| + return rule_.get();
|
| +}
|
| +
|
| +LookupKey* LookupKey::AddSubKey(const std::string& sub_key) {
|
| + assert(sub_keys_.find(sub_key) == sub_keys_.end());
|
| + AddressField sub_level = static_cast<AddressField>(level_ + 1);
|
| + assert(sub_level <= DEPENDENT_LOCALITY);
|
| + LookupKey* sub_lookup_key = new LookupKey(value_ + "/" + sub_key, sub_level);
|
| + sub_keys_.insert(std::make_pair(sub_key, sub_lookup_key));
|
| + return sub_lookup_key;
|
| +}
|
| +
|
| +LookupKey* LookupKey::AddLanguageCodeKey(const std::string& language_code) {
|
| + assert(language_code_keys_.find(language_code) == language_code_keys_.end());
|
| + LookupKey* language_code_key =
|
| + new LookupKey(value_ + "--" + language_code, level_);
|
| + language_code_keys_.insert(std::make_pair(language_code, language_code_key));
|
| + return language_code_key;
|
| +}
|
| +
|
| +LookupKey::LookupKey(const std::string& key_value, AddressField level)
|
| + : value_(key_value),
|
| + level_(level),
|
| + rule_(),
|
| + sub_keys_(),
|
| + language_code_keys_() {}
|
| +
|
| +} // namespace addressinput
|
| +} // namespace i18n
|
|
|