17ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// Copyright (C) 2014 Google Inc. 27ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// 37ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// Licensed under the Apache License, Version 2.0 (the "License"); 47ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// you may not use this file except in compliance with the License. 57ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// You may obtain a copy of the License at 67ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// 77ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// http://www.apache.org/licenses/LICENSE-2.0 87ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// 97ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// Unless required by applicable law or agreed to in writing, software 107ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// distributed under the License is distributed on an "AS IS" BASIS, 117ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// See the License for the specific language governing permissions and 137ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com// limitations under the License. 147ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 157ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com#include <libaddressinput/address_metadata.h> 167ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 177ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com#include <libaddressinput/address_field.h> 187ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 197ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com#include <algorithm> 201e3cc4b1d6f57ac44f3e954fbdc2e49e2228c397rouslan@chromium.org#include <string> 217ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 229f47fe3ed525accac995b095d408a825673a2ee1roubert@google.com#include "format_element.h" 237ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com#include "region_data_constants.h" 247ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com#include "rule.h" 257ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 267ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.comnamespace i18n { 277ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.comnamespace addressinput { 287ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 297ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.combool IsFieldRequired(AddressField field, const std::string& region_code) { 30b470ed6975ed95aba244369d74d758755d976738roubert@google.com if (field == COUNTRY) { 31b470ed6975ed95aba244369d74d758755d976738roubert@google.com return true; 32b470ed6975ed95aba244369d74d758755d976738roubert@google.com } 33b470ed6975ed95aba244369d74d758755d976738roubert@google.com 347ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com Rule rule; 357ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com rule.CopyFrom(Rule::GetDefault()); 367ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com if (!rule.ParseSerializedRule( 377ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com RegionDataConstants::GetRegionData(region_code))) { 387ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com return false; 397ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com } 407ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 417ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com return std::find(rule.GetRequired().begin(), 427ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com rule.GetRequired().end(), 437ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com field) != rule.GetRequired().end(); 447ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com} 457ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 467ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.combool IsFieldUsed(AddressField field, const std::string& region_code) { 47b470ed6975ed95aba244369d74d758755d976738roubert@google.com if (field == COUNTRY) { 48b470ed6975ed95aba244369d74d758755d976738roubert@google.com return true; 49b470ed6975ed95aba244369d74d758755d976738roubert@google.com } 50b470ed6975ed95aba244369d74d758755d976738roubert@google.com 517ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com Rule rule; 527ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com rule.CopyFrom(Rule::GetDefault()); 537ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com if (!rule.ParseSerializedRule( 547ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com RegionDataConstants::GetRegionData(region_code))) { 557ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com return false; 567ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com } 577ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 587ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com return std::find(rule.GetFormat().begin(), 597ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com rule.GetFormat().end(), 607ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com FormatElement(field)) != rule.GetFormat().end(); 617ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com} 627ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com 637ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com} // namespace addressinput 647ddb737724d535079cf6158d721fc094aa3d69dcroubert@google.com} // namespace i18n 65