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