// 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 "rule.h" #include <algorithm> #include <cassert> #include <cstddef> #include <string> #include <utility> #include <re2/re2.h> #include "address_field_util.h" #include "format_element.h" #include "grit.h" #include "messages.h" #include "region_data_constants.h" #include "util/json.h" #include "util/re2ptr.h" #include "util/size.h" #include "util/string_split.h" namespace i18n { namespace addressinput { namespace { // Used as a separator in a list of items. For example, the list of supported // languages can be "de~fr~it". const char kSeparator = …; // NameIdMap is a convenience POD struct that implements a mapping from // names to message ids, with sorted arrays of NameIdInfo entries. struct NameIdInfo { … }; struct NameIdMap { … }; const NameIdInfo kAdminAreaInfoArray[] = …; const NameIdMap kAdminAreaMessageIds{ … }; const NameIdInfo kPostalCodeInfoArray[] = …; const NameIdMap kPostalCodeMessageIds{ … }; const NameIdInfo kLocalityInfoArray[] = …; const NameIdMap kLocalityMessageIds{ … }; const NameIdInfo kSublocalityInfoArray[] = …; const NameIdMap kSublocalityMessageIds{ … }; #ifndef _NDEBUG // Helper type used to check that all maps are sorted at runtime. // Should be used as a local static variable to ensure this is checked only // once per process. Usage is simply: // // ... someFunction(....) { // static StaticMapChecker map_checker; // ... anything else ... // } struct StaticMapChecker { … }; #endif // _NDEBUG // Determines whether a given string is a reg-exp or a string. We consider a // string to be anything that doesn't contain characters with special meanings // in regular expressions - (, [, \, {, ?. These special characters are all the // ones that appear in the postal code regular expressions. bool ContainsRegExSpecialCharacters(const std::string& input) { … } } // namespace Rule::Rule() : … { … } Rule::~Rule() = default; // static const Rule& Rule::GetDefault() { … } void Rule::CopyFrom(const Rule& rule) { … } bool Rule::ParseSerializedRule(const std::string& serialized_rule) { … } void Rule::ParseJsonRule(const Json& json) { … } } // namespace addressinput } // namespace i18n