// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_REGEXES_H_ #define COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_REGEXES_H_ #include <map> #include <memory> #include <string> #include <string_view> #include <vector> #include "base/no_destructor.h" #include "base/sequence_checker.h" #include "base/synchronization/lock.h" #include "base/types/strong_alias.h" #include "third_party/icu/source/i18n/unicode/regex.h" namespace autofill { ThreadSafe; // Compiles a case-insensitive regular expression. // // The return icu::RegexPattern is thread-safe (because it's const and icu // guarantees thread-safety of the const functions). In particularly this // includes icu::RegexPattern::matcher(). // // May also be used to initialize `static base::NoDestructor<icu::RegexPattern>` // function-scope variables. std::unique_ptr<const icu::RegexPattern> CompileRegex( std::u16string_view regex); // Returns true if `regex` is found in `input`. // If `groups` is non-null, it gets resized and the found capture groups // are written into it. // Thread-safe. bool MatchesRegex(std::u16string_view input, const icu::RegexPattern& regex_pattern, std::vector<std::u16string>* groups = nullptr); // Calls MatchesRegex() after compiling the `regex` on the first call and // retrieving it from a static variable in subsequent calls. // // This function is thread-safe. template <const char16_t regex[]> bool MatchesRegex(std::u16string_view input, std::vector<std::u16string>* groups = nullptr) { … } // A cache of compiled regex patterns. It can be configured to be thread-safe // (using a mutex) or not (in which case it uses a sequence checker). class AutofillRegexCache { … }; } // namespace autofill #endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_REGEXES_H_