15 #include <restinio/impl/include_fmtlib.hpp> 17 #include <restinio/exception.hpp> 33 template <
typename Traits >
52 struct matched_item_descriptor_t
final 65 matched_item_descriptor_t
92 compile( r, options );
95 regex_t(
const regex_t & ) =
delete;
96 regex_t &
operator = (
const regex_t & ) =
delete;
101 rw.m_route_regex =
nullptr;
108 m_route_regex = rw.m_route_regex;
109 rw.m_route_regex =
nullptr;
117 if(
nullptr != m_route_regex )
119 pcre2_code_free( m_route_regex );
126 return m_route_regex;
135 PCRE2_SIZE erroroffset;
138 m_route_regex = pcre2_compile(
139 reinterpret_cast<
const unsigned char*>( r.data() ),
141 static_cast<
unsigned int>(options),
146 if(
nullptr == m_route_regex )
148 std::array<
unsigned char, 256 > buffer;
149 (
void)pcre2_get_error_message( errorcode, buffer.data(), buffer.size() );
152 "unable to compile regex \"{}\": {}",
154 reinterpret_cast<
const char * >( buffer.data() ) ) };
166 template < std::size_t Max_Capture_Groups = 20,
int Compile_Options = 0,
int Match_Options = 0 >
184 using matched_item_descriptor_t =
typename match_results_t::matched_item_descriptor_t;
190 return Traits::max_capture_groups;
199 bool is_case_sensative )
201 int options = Traits::compile_options;
203 if( !is_case_sensative )
205 options |= PCRE2_CASELESS;
208 return compiled_regex_t{ r, options };
214 string_view_t target_path,
215 const compiled_regex_t & r,
216 match_results_t & match_results )
221 reinterpret_cast<
const unsigned char* >( target_path.data() ),
224 Traits::match_options,
225 match_results.m_match_data,
230 match_results.m_size =
static_cast<std::size_t>(rc);
237 throw exception_t{
"unexpected: not enough submatch vector size" };
239 if( PCRE2_ERROR_NOMATCH != rc )
241 throw exception_t{ fmt::format(
"pcre2 error: {}", rc ) };
252 return static_cast< std::size_t >( m.m_begin );
259 return static_cast< std::size_t >( m.m_end );
static constexpr std::size_t max_capture_groups()
regex_t & operator=(const regex_t &)=delete
match_results_t(const match_results_t &)=delete
void compile(string_view_t r, int options)
pcre2_code * m_route_regex
static constexpr int match_options
matched_item_descriptor_t(PCRE2_SIZE begin, PCRE2_SIZE end)
regex_t(const regex_t &)=delete
match_results_t & operator=(match_results_t &&)=delete
match_results_t & operator=(const match_results_t &)=delete
match_results_t(match_results_t &&)=delete
static auto submatch_begin_pos(const matched_item_descriptor_t &m)
Get the beginning of a submatch.
static constexpr int compile_options
static auto try_match(string_view_t target_path, const compiled_regex_t &r, match_results_t &match_results)
Wrapper function for matching logic invokation.
matched_item_descriptor_t operator[](std::size_t i) const
pcre2_match_data * m_match_data
static constexpr std::size_t max_capture_groups
regex_t & operator=(regex_t &&rw) noexcept
static auto compile_regex(string_view_t r, bool is_case_sensative)
Create compiled regex object for a given route.
A wrapper class for working with pcre match results.
regex_t(string_view_t r, int options)
regex_t(regex_t &&rw) noexcept
Regex engine implementation for PCRE2.
static auto submatch_end_pos(const matched_item_descriptor_t &m)
Get the end of a submatch.
const pcre2_code * pcre2_regex() const
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...