RESTinio
Toggle main menu visibility
Loading...
Searching...
No Matches
restinio
router
boost_regex_engine.hpp
Go to the documentation of this file.
1
/*
2
restinio
3
*/
4
5
/*!
6
Regex engine for using std::regex.
7
*/
8
9
#
pragma
once
10
11
#
include
<
boost
/
regex
.
hpp
>
12
13
namespace
restinio
14
{
15
16
namespace
router
17
{
18
19
//
20
// boost_regex_engine_t
21
//
22
23
//! Regex engine implementation for using with standard regex implementation.
24
struct
boost_regex_engine_t
25
{
26
using
compiled_regex_t
= boost::regex;
27
using
match_results_t
=
std
::
vector
<
std
::
pair
<
std
::
size_t
,
size_t
> >;
28
using
matched_item_descriptor_t
=
match_results_t
::
value_type
;
29
30
static
constexpr
std::size_t
31
max_capture_groups
()
32
{
33
// The size of match results for standard regexes cannot be reserved
34
// and grows as needed, so no limits beforehand.
35
return
std::numeric_limits< std::size_t >::max();
36
}
37
38
//! Create compiled regex object for a given route.
39
static
auto
40
compile_regex
(
41
//! Regular expression (the pattern).
42
string_view_t r,
43
//! Option for case sensativity.
44
bool
is_case_sensative )
45
{
46
compiled_regex_t::flag_type regex_flags = boost::regex::ECMAScript;
47
48
if
( !is_case_sensative )
49
{
50
regex_flags |= boost::regex::icase;
51
}
52
53
return
compiled_regex_t
{ r.data(), r.size(), regex_flags };
54
}
55
56
//! Wrapper function for matching logic invokation.
57
static
auto
58
try_match
(
59
string_view_t target_path,
60
const
compiled_regex_t
& r,
61
match_results_t & match_results )
62
{
63
boost::cmatch matches;
64
if
(
65
boost::regex_search(
66
target_path.data(),
67
target_path.data() + target_path.size(),
68
matches,
69
r ) )
70
{
71
match_results.reserve( matches.size() );
72
73
std::transform(
74
matches.begin(),
75
matches.end(),
76
std::back_inserter( match_results ),
77
[ begin = target_path.data() ](
const
auto
& m ){
78
return
matched_item_descriptor_t{ m.first - begin, m.second - begin };
79
} );
80
81
return
true
;
82
}
83
return
false
;
84
}
85
86
//! Get the beginning of a submatch.
87
static
auto
88
submatch_begin_pos
(
const
matched_item_descriptor_t & m )
89
{
90
return
m.first;
91
}
92
93
//! Get the end of a submatch.
94
static
auto
95
submatch_end_pos
(
const
matched_item_descriptor_t & m )
96
{
97
return
m.second;
98
}
99
};
100
101
}
/* namespace router */
102
103
}
/* namespace restinio */
restinio::router
Definition
boost_regex_engine.hpp:17
restinio
Definition
sendfile_operation_default.ipp:12
restinio::router::boost_regex_engine_t
Regex engine implementation for using with standard regex implementation.
Definition
boost_regex_engine.hpp:25
restinio::router::boost_regex_engine_t::compile_regex
static auto compile_regex(string_view_t r, bool is_case_sensative)
Create compiled regex object for a given route.
Definition
boost_regex_engine.hpp:40
restinio::router::boost_regex_engine_t::compiled_regex_t
boost::regex compiled_regex_t
Definition
boost_regex_engine.hpp:26
restinio::router::boost_regex_engine_t::submatch_begin_pos
static auto submatch_begin_pos(const matched_item_descriptor_t &m)
Get the beginning of a submatch.
Definition
boost_regex_engine.hpp:88
restinio::router::boost_regex_engine_t::max_capture_groups
static constexpr std::size_t max_capture_groups()
Definition
boost_regex_engine.hpp:31
restinio::router::boost_regex_engine_t::submatch_end_pos
static auto submatch_end_pos(const matched_item_descriptor_t &m)
Get the end of a submatch.
Definition
boost_regex_engine.hpp:95
restinio::router::boost_regex_engine_t::try_match
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.
Definition
boost_regex_engine.hpp:58
Generated by
1.17.0