FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
expresscpp/src/path_to_regexp.cpp at master · deimi/expresscpp · GitHub
deimi
/
expresscpp
Public
forked from
expresscpp/expresscpp
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
expresscpp
/
src
/
path_to_regexp.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (52 loc) · 1.9 KB
Breadcrumbs
expresscpp
/
src
/
path_to_regexp.cpp
Copy path
File metadata and controls
59 lines (52 loc) · 1.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
include
"
expresscpp/path_to_regexp.hpp
"
#
include
<
algorithm
>
#
include
<
stdexcept
>
#
define
EXPRESSCPP_CONFIG_DEBUG_PATH_TO_REGEX
0
#
if
defined(EXPRESSCPP_CONFIG_DEBUG_PATH_TO_REGEX)
#
include
<
iostream
>
#
endif
namespace
expresscpp
{
using
namespace
std
::string_literals
;
std::string
pathToRegExpString
(std::string_view registered_path, std::vector<Key>& keys, PathToRegExpOptions op,
std::string_view parent_path) {
std::string regex =
std::string
(
"
^
"
) + parent_path.
data
() + registered_path.
data
();
size_t
key_index =
0
;
std::string::size_type start_pos =
0
;
while
(start_pos != std::string::npos) {
start_pos = regex.
find
(
'
:
'
, start_pos);
if
(start_pos != std::string::npos) {
const
auto
dash_end_pos = regex.
find
(
'
-
'
, start_pos);
const
auto
next_end_pos = regex.
find
(
'
:
'
, start_pos +
1
);
const
auto
slash_end_pos = regex.
find
(
'
/
'
, start_pos);
const
auto
end_pos =
std::min
(
std::min
(dash_end_pos, slash_end_pos), next_end_pos);
Key tmp_key;
const
auto
key_name = regex.
substr
(start_pos +
1
, end_pos - start_pos -
1
);
if
(key_name.
empty
()) {
throw
std::runtime_error
(
std::string
(
"
Empty parameter name found in path:
"
) + registered_path.
data
());
}
tmp_key.
index_
= key_index++;
tmp_key.
name_
= key_name;
regex.
replace
(start_pos, end_pos - start_pos,
"
(
\\
S+)
"
);
keys.
emplace_back
(tmp_key);
}
}
if
(op.
end
) {
regex +=
"
$
"
;
}
else
if
(op.
strict
) {
regex +=
"
/
\\
S*
"
;
}
else
{
regex +=
"
\\
S*
"
;
}
#
if
EXPRESSCPP_CONFIG_DEBUG_PATH_TO_REGEX
if
(keys.
size
() >
0
) {
std::cout <<
"
printing keys ***********************
"
<< std::endl;
for
(
const
auto
& k : keys) {
std::cout <<
"
key found :
"
<<
"
\"
"
<< k.
name_
<<
"
\"
"
<< std::endl;
}
std::cout <<
"
printing keys **********************
"
<< std::endl;
}
#
endif
return
regex;
}
}
//
namespace expresscpp
Back
|
FazBrowse Home
|
New Git URL