Ada 3.1.0
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 <string>
9#include <string_view>
10
11#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
12#include <regex>
13#endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
14
16
17template <typename T>
18concept regex_concept = requires(T t, std::string_view pattern,
19 bool ignore_case, std::string_view input) {
20 // Ensure the class has a type alias 'regex_type'
21 typename T::regex_type;
22
23 // Function to create a regex instance
24 {
25 T::create_instance(pattern, ignore_case)
26 } -> std::same_as<std::optional<typename T::regex_type>>;
27
28 // Function to perform regex search
29 {
30 T::regex_search(input, std::declval<typename T::regex_type&>())
31 } -> std::same_as<std::optional<std::vector<std::optional<std::string>>>>;
32
33 // Function to match regex pattern
34 {
35 T::regex_match(input, std::declval<typename T::regex_type&>())
36 } -> std::same_as<bool>;
37
38 // Copy constructor
39 { T(std::declval<const T&>()) } -> std::same_as<T>;
40
41 // Move constructor
42 { T(std::declval<T&&>()) } -> std::same_as<T>;
43};
44
45#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
46class std_regex_provider final {
47 public:
48 std_regex_provider() = default;
49 using regex_type = std::regex;
50 static std::optional<regex_type> create_instance(std::string_view pattern,
51 bool ignore_case);
52 static std::optional<std::vector<std::optional<std::string>>> regex_search(
53 std::string_view input, const regex_type& pattern);
54 static bool regex_match(std::string_view input, const regex_type& pattern);
55};
56#endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
57
58} // namespace ada::url_pattern_regex
59
60#endif // ADA_URL_PATTERN_REGEX_H