#pragma once
#include <cstddef>
#include <memory>
#include <re2/re2.h>
#include <string>
#include <string_view>
#include <utility>
#include "dynamic_string.hpp"
#include "matcher/base.hpp"
#include "object_type.hpp"
namespace ddwaf::matcher {
class regex_match : public base_impl<regex_match> {
public:
static constexpr std::string_view matcher_name = "match_regex";
static constexpr std::string_view negated_matcher_name = "!match_regex";
regex_match(const std::string ®ex_str, std::size_t minLength, bool case_sensitive);
~regex_match() override = default;
regex_match(const regex_match &) = delete;
regex_match(regex_match &&) noexcept = default;
regex_match &operator=(const regex_match &) = delete;
regex_match &operator=(regex_match &&) noexcept = default;
protected:
[[nodiscard]] std::string_view to_string_impl() const { return regex->pattern(); }
static constexpr bool is_supported_type_impl(object_type type)
{
return (type & object_type::string) != 0;
}
[[nodiscard]] std::pair<bool, dynamic_string> match_impl(std::string_view pattern) const;
std::unique_ptr<re2::RE2> regex{nullptr};
std::size_t min_length;
friend class base_impl<regex_match>;
};
}