13 #include <restinio/impl/include_fmtlib.hpp> 15 #include <restinio/exception.hpp> 32 template <
typename Traits >
35 struct matched_item_descriptor_t
final 48 matched_item_descriptor_t
80 compile( r, options );
83 regex_t(
const regex_t & ) =
delete;
84 regex_t &
operator = (
const regex_t & ) =
delete;
89 rw.m_route_regex =
nullptr;
92 regex_t &
operator = ( regex_t && rw )
noexcept 96 m_route_regex = rw.m_route_regex;
97 rw.m_route_regex =
nullptr;
105 if(
nullptr != m_route_regex )
107 pcre_free( m_route_regex );
114 return m_route_regex;
123 const char* compile_error;
127 const std::string route{ r.data(), r.size() };
129 m_route_regex = pcre_compile( route.c_str(), options, &compile_error, &eoffset,
nullptr );
131 if(
nullptr == m_route_regex )
135 RESTINIO_FMT_FORMAT_STRING(
136 "unable to compile regex \"{}\": {}" ),
150 template < std::size_t Max_Capture_Groups = 20,
int Compile_Options = 0,
int Match_Options = 0 >
168 using matched_item_descriptor_t =
typename match_results_t::matched_item_descriptor_t;
174 return Traits::max_capture_groups;
183 bool is_case_sensative )
185 int options = Traits::compile_options;
187 if( !is_case_sensative )
189 options |= PCRE_CASELESS;
192 return compiled_regex_t{ r, options };
198 string_view_t target_path,
199 const compiled_regex_t & r,
200 match_results_t & match_results )
207 static_cast<
int >( target_path.size() ),
209 Traits::match_options,
210 match_results.m_submatches.data(),
211 static_cast<
int >( match_results.m_submatches.size() ) );
215 match_results.m_size =
static_cast<std::size_t>(rc);
222 throw exception_t{
"unexpected: not enough submatch vector size" };
224 if( PCRE_ERROR_NOMATCH != rc )
227 fmt::format( RESTINIO_FMT_FORMAT_STRING(
"pcre error: {}" ), rc ) };
238 return static_cast< std::size_t >( m.m_begin );
245 return static_cast< std::size_t >( m.m_end );
matched_item_descriptor_t operator[](std::size_t i) const
regex_t & operator=(regex_t &&rw) noexcept
regex_t(regex_t &&rw) noexcept
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.
static constexpr int compile_options
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...
std::array< int, 3 *Traits::max_capture_groups > m_submatches
A wrapper class for working with pcre match results.
static auto compile_regex(string_view_t r, bool is_case_sensative)
Create compiled regex object for a given route.
Regex engine implementation for PCRE.
regex_t(string_view_t r, int options)
static auto submatch_end_pos(const matched_item_descriptor_t &m)
Get the end of a submatch.
void compile(string_view_t r, int options)
const pcre * pcre_regex() const
regex_t(const regex_t &)=delete
matched_item_descriptor_t(int begin, int end)
static constexpr std::size_t max_capture_groups()
regex_t & operator=(const regex_t &)=delete
static constexpr int match_options
static constexpr std::size_t max_capture_groups
static auto submatch_begin_pos(const matched_item_descriptor_t &m)
Get the beginning of a submatch.