2
3
6
7
15#include <restinio/impl/include_fmtlib.hpp>
17#include <restinio/exception.hpp>
33template <
typename Traits >
38 m_match_data = pcre2_match_data_create( Traits::max_capture_groups,
nullptr );
43 if(
nullptr != m_match_data )
44 pcre2_match_data_free( m_match_data );
52 struct matched_item_descriptor_t
final
65 matched_item_descriptor_t
68 PCRE2_SIZE * submatches = pcre2_get_ovector_pointer( m_match_data );
70 return matched_item_descriptor_t{
72 submatches[ 1 + 2 * i ] };
92 compile( r, options );
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 );
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() );
153 "unable to compile regex \"{}\": {}" ),
155 reinterpret_cast<
const char * >( buffer.data() ) ) };
167template < std::size_t Max_Capture_Groups = 20,
int Compile_Options = 0,
int Match_Options = 0 >
188 static constexpr std::size_t
191 return Traits::max_capture_groups;
200 bool is_case_sensative )
202 int options = Traits::compile_options;
204 if( !is_case_sensative )
206 options |= PCRE2_CASELESS;
215 string_view_t target_path,
222 reinterpret_cast<
const unsigned char* >( target_path.data() ),
225 Traits::match_options,
226 match_results.m_match_data,
231 match_results.m_size =
static_cast<std::size_t>(rc);
238 throw exception_t{ "unexpected: not enough submatch vector size" };
240 if( PCRE2_ERROR_NOMATCH != rc )
254 return static_cast< std::size_t >( m.m_begin );
261 return static_cast< std::size_t >( m.m_end );
Exception class for all exceptions thrown by RESTinio.
exception_t(const char *err)
regex_t(regex_t &&rw) noexcept
regex_t(const regex_t &)=delete
regex_t & operator=(regex_t &&rw) noexcept
regex_t & operator=(const regex_t &)=delete
void compile(string_view_t r, int options)
regex_t(string_view_t r, int options)
pcre2_code * m_route_regex
#define RESTINIO_FMT_FORMAT_STRING(s)
matched_item_descriptor_t(PCRE2_SIZE begin, PCRE2_SIZE end)
match_results_t & operator=(const match_results_t &)=delete
match_results_t & operator=(match_results_t &&)=delete
pcre2_match_data * m_match_data
match_results_t(const match_results_t &)=delete
matched_item_descriptor_t operator[](std::size_t i) const
match_results_t(match_results_t &&)=delete
Regex engine implementation for PCRE2.
pcre2_details::match_results_t< Traits > match_results_t
static auto submatch_end_pos(const matched_item_descriptor_t &m)
Get the end of a submatch.
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.
typename match_results_t::matched_item_descriptor_t matched_item_descriptor_t
static auto compile_regex(string_view_t r, bool is_case_sensative)
Create compiled regex object for a given route.
pcre2_details::regex_t compiled_regex_t
static auto submatch_begin_pos(const matched_item_descriptor_t &m)
Get the beginning of a submatch.
static constexpr std::size_t max_capture_groups()
static constexpr int match_options
static constexpr std::size_t max_capture_groups
static constexpr int compile_options