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_util.h"
16
17#include <cassert>
18#include <string>
19
20namespace i18n {
21namespace addressinput {
22
23LookupKeyUtil::LookupKeyUtil(const std::string& validation_data_url)
24    : validation_data_url_(validation_data_url) {
25  assert(validation_data_url_.length() > 0);
26  assert(validation_data_url_[validation_data_url_.length() - 1] == '/');
27}
28
29LookupKeyUtil::~LookupKeyUtil() {}
30
31std::string LookupKeyUtil::GetUrlForKey(const std::string& key) const {
32  return validation_data_url_ + key;
33}
34
35std::string LookupKeyUtil::GetKeyForUrl(const std::string& url) const {
36  return IsValidationDataUrl(url) ? url.substr(validation_data_url_.length())
37                                  : std::string();
38}
39
40bool LookupKeyUtil::IsValidationDataUrl(const std::string& url) const {
41  return
42      url.compare(0, validation_data_url_.length(), validation_data_url_) == 0;
43}
44
45}  // namespace addressinput
46}  // namespace i18n
47