Ada 4.1.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#include <concepts>
9#include <optional>
10#include <string>
11#include <string_view>
12#include <vector>
13
14#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
15#include <regex>
16#endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
17
18#if ADA_INCLUDE_URL_PATTERN
19namespace ada::url_pattern_regex {
20
46template <typename T>
47concept regex_concept = requires(T t, std::string_view pattern,
48 bool ignore_case, std::string_view input) {
49 // Ensure the class has a type alias 'regex_type'
50 typename T::regex_type;
51
52 // Function to create a regex instance
53 {
54 T::create_instance(pattern, ignore_case)
55 } -> std::same_as<std::optional<typename T::regex_type>>;
56
57 // Function to perform regex search
58 {
59 T::regex_search(input, std::declval<typename T::regex_type&>())
60 } -> std::same_as<std::optional<std::vector<std::optional<std::string>>>>;
61
62 // Function to match regex pattern
63 {
64 T::regex_match(input, std::declval<typename T::regex_type&>())
65 } -> std::same_as<bool>;
66
67 // Copy constructor
68 { T(std::declval<const T&>()) } -> std::same_as<T>;
69
70 // Move constructor
71 { T(std::declval<T&&>()) } -> std::same_as<T>;
72};
73
74#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
75class std_regex_provider final {
76 public:
77 std_regex_provider() = default;
78 using regex_type = std::regex;
79 static std::optional<regex_type> create_instance(std::string_view pattern,
80 bool ignore_case);
81 static std::optional<std::vector<std::optional<std::string>>> regex_search(
82 std::string_view input, const regex_type& pattern);
83 static bool regex_match(std::string_view input, const regex_type& pattern);
84};
85#endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
86
87} // namespace ada::url_pattern_regex
88#endif // ADA_INCLUDE_URL_PATTERN
89#endif // ADA_URL_PATTERN_REGEX_H