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 RESTINIO_FMT_FORMAT_STRING(
153 "unable to compile regex \"{}\": {}" ),
154 fmtlib_tools::streamed( r ),
155 reinterpret_cast<
const char * >( buffer.data() ) ) };
167 template < std::size_t Max_Capture_Groups = 20,
int Compile_Options = 0,
int Match_Options = 0 >
185 using matched_item_descriptor_t =
typename match_results_t::matched_item_descriptor_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;
209 return compiled_regex_t{ r, options };
215 string_view_t target_path,
216 const compiled_regex_t & r,
217 match_results_t & match_results )
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 )
243 fmt::format( RESTINIO_FMT_FORMAT_STRING(
"pcre2 error: {}" ), rc ) };
254 return static_cast< std::size_t >( m.m_begin );
261 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
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
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