// Copyright (C) 2014 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 "post_box_matchers.h" #include <algorithm> #include <cassert> #include <cstddef> #include <cstring> #include <string> #include <vector> #include <re2/re2.h> #include "language.h" #include "rule.h" #include "util/re2ptr.h" #include "util/size.h" namespace i18n { namespace addressinput { namespace { // kLanguageInfoMap is a constant table that associates language names // with the corresponding matching regexp. // // NOTE: This array must be sorted in increasing language name values. // this is checked at compile time through a static_assert() below. struct LanguageInfo { … }; constexpr const LanguageInfo kLanguageInfoMap[] = …; constexpr size_t kLanguageInfoMapSize = …; // Compile-time function that returns true iff the content of string |a| // is less or equal to string |b|. constexpr bool StrLessOrEqualConstexpr(const char* a, const char* b) { … } // Sanity checks. static_assert …; static_assert …; static_assert …; static_assert …; static_assert …; static_assert …; static_assert …; static_assert …; // Compile-time function to verify that LanguageInfoMap is properly sorted. // The |n| parameter is a starting position for the check. constexpr bool CheckLanguageInfoMapOrderConstexpr(size_t n = 0) { … } // Compile-time check for the order to kLanguageInfoMap entries. static_assert …; // Return a pointer to the LanguageInfo entry corresponding to |language| // or nullptr if this wasn't found. const LanguageInfo* FindLanguageInfoFor(const std::string& language) { … } // A convenience wrapper class for a fixed array of RE2PlainPtr that shall // only be instantiated as a static variable. class StaticRE2Array { … }; } // namespace // static std::vector<const RE2PlainPtr*> PostBoxMatchers::GetMatchers( const Rule& country_rule) { … } } // namespace addressinput } // namespace i18n