2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "express/dispatcher/regex_utils.h"
44#include "express/Request.h"
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
54 std::string
path_concat(
const std::vector<std::string>& stringvec) {
57 for (std::vector<std::string>::size_type i = 0; i < stringvec.size(); i++) {
58 if (!stringvec[i].empty() && stringvec[i].front() !=
' ') {
59 s +=
"\\/" + stringvec[i];
66 std::vector<std::string>
explode(
const std::string& input,
char delim) {
67 std::vector<std::string> result;
71 for (
const char ch : input) {
75 }
else if (ch ==
')') {
78 }
else if (ch == delim && parenDepth == 0) {
79 result.push_back(current);
86 if (!current.empty()) {
87 result.push_back(current);
93#define PATH_REGEX ":[a-zA-Z0-9]+(\\(.+\\))?"
111 return std::regex_search(cpath, smatch,
pathRegex());
115 std::vector<std::string> explodedString =
explode(cpath
, '/');
117 for (std::vector<std::string>::size_type i = 0; i < explodedString.size(); i++) {
118 if (explodedString[i].front() ==
':') {
120 std::string regex =
"(.*)";
122 if (smatch.size() > 1) {
123 if (smatch[1] !=
"") {
125 }
else if (i == explodedString.size() - 1) {
126 regex =
"([^/]+)(/)?$";
130 explodedString[i] = regex;
136 return std::regex_match(reqpath, std::regex(regexPath));
140 std::vector<std::string> explodedString =
explode(cpath
, '/');
141 std::vector<std::string> explodedReqString =
explode(req
.url, '/');
143 for (std::vector<std::string>::size_type i = 0; i < explodedString.size() && i < explodedReqString.size(); i++) {
144 if (explodedString[i].front() ==
':') {
146 std::string regex =
"(.*)";
148 if (smatch.size() > 1) {
149 if (smatch[1] !=
"") {
154 if (std::regex_match(explodedReqString[i], std::regex(regex))) {
155 std::string attributeName = smatch[0];
156 attributeName.erase(0, 1);
157 attributeName.erase((attributeName.length() -
static_cast<std::size_t>(smatch[1].length())),
158 static_cast<std::size_t>(smatch[1].length()));
160 req
.params[attributeName] = explodedReqString[i];
std::map< std::string, std::string > params
bool checkForUrlMatch(const std::string &cpath, const std::string &reqpath)
void setParams(const std::string &cpath, express::Request &req)
std::smatch matchResult(const std::string &cpath)
bool hasResult(const std::string &cpath)
std::string path_concat(const std::vector< std::string > &stringvec)
bool matchFunction(const std::string &cpath, const std::string &reqpath)
std::vector< std::string > explode(const std::string &s, char delim)
const std::regex & pathRegex()