52
52
#include " cgimap/http.hpp"
53
53
#include " cgimap/mime_types.hpp"
54
54
55
+ #include < memory>
55
56
#include < optional>
57
+ #include < string>
58
+ #include < vector>
56
59
57
60
#include < boost/algorithm/string.hpp>
58
61
#include < fmt/core.h>
59
62
60
- using std::list;
61
- using std::string;
62
- using std::pair;
63
- using std::unique_ptr;
64
-
65
63
using boost::fusion::make_cons;
66
64
using boost::fusion::invoke;
67
65
@@ -76,7 +74,7 @@ struct router {
76
74
// interface through which all matches and constructions are performed.
77
75
struct rule_base {
78
76
virtual ~rule_base () = default ;
79
- virtual bool invoke_if (const list< string> &, request &, handler_ptr_t &) = 0;
77
+ virtual bool invoke_if (const std::vector<std:: string> &, request &, handler_ptr_t &) = 0;
80
78
};
81
79
82
80
using rule_ptr = std::unique_ptr<rule_base>;
@@ -97,7 +95,7 @@ struct router {
97
95
98
96
// try to match the expression. if it succeeds, call the provided function
99
97
// with the provided params and the matched DSL arguments.
100
- bool invoke_if (const list< string> &parts,
98
+ bool invoke_if (const std::vector<std:: string> &parts,
101
99
request ¶ms,
102
100
handler_ptr_t &ptr) override {
103
101
try {
@@ -164,7 +162,7 @@ struct router {
164
162
* params.
165
163
*/
166
164
167
- handler_ptr_t match (const list< string> &p, request ¶ms) {
165
+ handler_ptr_t match (const std::vector<std:: string> &p, request ¶ms) {
168
166
169
167
handler_ptr_t hptr;
170
168
@@ -223,9 +221,9 @@ struct router {
223
221
}
224
222
225
223
private:
226
- list <rule_ptr> rules_get;
227
- list <rule_ptr> rules_post;
228
- list <rule_ptr> rules_put;
224
+ std::vector <rule_ptr> rules_get;
225
+ std::vector <rule_ptr> rules_post;
226
+ std::vector <rule_ptr> rules_put;
229
227
};
230
228
231
229
routes::routes ()
@@ -290,36 +288,36 @@ namespace {
290
288
* figures out the mime type from the path specification, e.g: a resource ending
291
289
* in .xml should be application/xml, .json should be application/json, etc...
292
290
*/
293
- pair<string, mime::type> resource_mime_type (const string &path) {
291
+ std:: pair<std:: string, mime::type> resource_mime_type (const std:: string &path) {
294
292
295
293
#if HAVE_YAJL
296
294
{
297
295
std::size_t json_found = path.rfind (" .json" );
298
296
299
- if (json_found != string::npos && json_found == path.length () - 5 ) {
300
- return make_pair (path.substr (0 , json_found), mime::type::application_json);
297
+ if (json_found != std:: string::npos && json_found == path.length () - 5 ) {
298
+ return std:: make_pair (path.substr (0 , json_found), mime::type::application_json);
301
299
}
302
300
}
303
301
#endif
304
302
305
303
{
306
304
std::size_t xml_found = path.rfind (" .xml" );
307
305
308
- if (xml_found != string::npos && xml_found == path.length () - 4 ) {
306
+ if (xml_found != std:: string::npos && xml_found == path.length () - 4 ) {
309
307
return make_pair (path.substr (0 , xml_found), mime::type::application_xml);
310
308
}
311
309
}
312
310
313
311
return make_pair (path, mime::type::unspecified_type);
314
312
}
315
313
316
- handler_ptr_t route_resource (request &req, const string &path,
317
- const unique_ptr<router> &r) {
314
+ handler_ptr_t route_resource (request &req, const std:: string &path,
315
+ const std:: unique_ptr<router> &r) {
318
316
// strip off the format-spec, if there is one
319
- pair<string, mime::type> resource = resource_mime_type (path);
317
+ std:: pair<std:: string, mime::type> resource = resource_mime_type (path);
320
318
321
319
// split the URL into bits to be matched.
322
- list< string> path_components;
320
+ std::vector<std:: string> path_components;
323
321
al::split (path_components, resource.first , al::is_any_of (" /" ));
324
322
325
323
handler_ptr_t hptr (r->match (path_components, req));
@@ -338,16 +336,16 @@ handler_ptr_t route_resource(request &req, const string &path,
338
336
339
337
handler_ptr_t routes::operator ()(request &req) const {
340
338
// full path from request handler
341
- string path = get_request_path (req);
339
+ auto path = get_request_path (req);
342
340
handler_ptr_t hptr;
343
341
// check the prefix
344
342
if (path.compare (0 , common_prefix.size (), common_prefix) == 0 ) {
345
- hptr = route_resource (req, string (path, common_prefix.size ()), r);
343
+ hptr = route_resource (req, std:: string (path, common_prefix.size ()), r);
346
344
347
345
#ifdef ENABLE_API07
348
346
} else if (path.compare (0 , experimental_prefix.size (), experimental_prefix) ==
349
347
0 ) {
350
- hptr = route_resource (req, string (path, experimental_prefix.size ()),
348
+ hptr = route_resource (req, std:: string (path, experimental_prefix.size ()),
351
349
r_experimental);
352
350
#endif /* ENABLE_API07 */
353
351
}
0 commit comments