| Index: third_party/libaddressinput/chromium/cpp/src/lookup_key.h
|
| diff --git a/third_party/libaddressinput/chromium/cpp/src/lookup_key.h b/third_party/libaddressinput/chromium/cpp/src/lookup_key.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..26a612825a096360b18eea832563b64eead40129
|
| --- /dev/null
|
| +++ b/third_party/libaddressinput/chromium/cpp/src/lookup_key.h
|
| @@ -0,0 +1,97 @@
|
| +// 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.
|
| +
|
| +#ifndef I18N_ADDRESSINPUT_LOOKUP_KEY_H_
|
| +#define I18N_ADDRESSINPUT_LOOKUP_KEY_H_
|
| +
|
| +#include <libaddressinput/address_field.h>
|
| +#include <libaddressinput/util/basictypes.h>
|
| +#include <libaddressinput/util/scoped_ptr.h>
|
| +
|
| +#include <map>
|
| +#include <string>
|
| +
|
| +namespace i18n {
|
| +namespace addressinput {
|
| +
|
| +class Rule;
|
| +
|
| +// Sample usage:
|
| +// LookupKey country_key("CA");
|
| +// Rule country_rule = RetrieveRule(country_key.GetKeyValue());
|
| +// country_key.SetRule(country_rule);
|
| +//
|
| +// LookupKey* administrative_area_key = country_key.AddSubKey("AB");
|
| +// administrative_area_key->SetRule(
|
| +// RetrieveRule(administrative_area_key.GetKeyValue()));
|
| +//
|
| +// Process(administrative_area_key->GetLevel(),
|
| +// administrative_area_key->GetRule());
|
| +//
|
| +// LookupKey* language_code_key = country_key.AddLanguageCodeKey("fr");
|
| +// language_code_key->SetRule(
|
| +// RetrieveRule(language_code_key.GetKeyValue()));
|
| +//
|
| +// Process(language_code_key->GetLevel(),
|
| +// language_code_key->GetRule());
|
| +class LookupKey {
|
| + public:
|
| + explicit LookupKey(const std::string& country_code);
|
| + ~LookupKey();
|
| +
|
| + // Returns the string representation of this key, for example "data/US/CA".
|
| + const std::string& GetKeyValue() const;
|
| +
|
| + // Returns the level of this key, for example ADMIN_AREA.
|
| + AddressField GetLevel() const;
|
| +
|
| + // Takes ownership of |rule|.
|
| + void SetRule(const Rule* rule);
|
| +
|
| + // The caller does not own the result.
|
| + const Rule* GetRule() const;
|
| +
|
| + // Adds a sub-key and returns it. The caller does not own the result.
|
| + LookupKey* AddSubKey(const std::string& sub_key);
|
| +
|
| + // Adds a language code key and returns it. The caller does not own the
|
| + // result.
|
| + LookupKey* AddLanguageCodeKey(const std::string& language_code);
|
| +
|
| + // Returns the lookup key for |sub_key| or NULL. The caller does not own the
|
| + // result.
|
| + LookupKey* GetSubKey(const std::string& sub_key) const;
|
| +
|
| + // Returns the lookup key for |language_code| or NULL. The caller does not own
|
| + // the result.
|
| + LookupKey* GetLanguageCodeKey(const std::string& language_code) const;
|
| +
|
| + private:
|
| + typedef std::map<std::string, LookupKey*> LookupKeys;
|
| +
|
| + LookupKey(const std::string& key_value, AddressField level);
|
| +
|
| + const std::string value_;
|
| + const AddressField level_;
|
| + scoped_ptr<const Rule> rule_;
|
| + LookupKeys sub_keys_;
|
| + LookupKeys language_code_keys_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(LookupKey);
|
| +};
|
| +
|
| +} // namespace addressinput
|
| +} // namespace i18n
|
| +
|
| +#endif // I18N_ADDRESSINPUT_LOOKUP_KEY_H_
|
|
|