Ada 3.0.1
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_pattern_regex.h
Go to the documentation of this file.
1
5#ifndef ADA_URL_PATTERN_REGEX_H
6#define ADA_URL_PATTERN_REGEX_H
7
8#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
9#include <regex>
10#endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
11
13
14template <typename T>
15concept regex_concept = requires(T t, std::string_view pattern,
16 bool ignore_case, std::string_view input) {
17 // Ensure the class has a type alias 'regex_type'
18 typename T::regex_type;
19
20 // Function to create a regex instance
21 {
22 T::create_instance(pattern, ignore_case)
23 } -> std::same_as<std::optional<typename T::regex_type>>;
24
25 // Function to perform regex search
26 {
27 T::regex_search(input, std::declval<typename T::regex_type&>())
28 } -> std::same_as<std::optional<std::vector<std::optional<std::string>>>>;
29
30 // Function to match regex pattern
31 {
32 T::regex_match(input, std::declval<typename T::regex_type&>())
33 } -> std::same_as<bool>;
34
35 // Copy constructor
36 { T(std::declval<const T&>()) } -> std::same_as<T>;
37
38 // Move constructor
39 { T(std::declval<T&&>()) } -> std::same_as<T>;
40};
41
42#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
43class std_regex_provider {
44 public:
45 std_regex_provider() = default;
46 using regex_type = std::regex;
47 static std::optional<regex_type> create_instance(std::string_view pattern,
48 bool ignore_case);
49 static std::optional<std::vector<std::optional<std::string>>> regex_search(
50 std::string_view input, const regex_type& pattern);
51 static bool regex_match(std::string_view input, const regex_type& pattern);
52};
53#endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
54
55} // namespace ada::url_pattern_regex
56
57#endif // ADA_URL_PATTERN_REGEX_H