aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJaeseung Ha <ipknhama@gmail.com>2017-09-17 13:50:50 +0900
committerGitHub <noreply@github.com>2017-09-17 13:50:50 +0900
commit13fdc9390be442a0a9d9ffe37cf63c729bfeaf3e (patch)
treef12829eec022aca042bf0664bb7132445b27227b /include
parent16064ec9ba04266655e3474b687f2d53472fcc4c (diff)
parent15d377907fd8b63e2d8474dfeeeb1765fd8b729d (diff)
downloadcrow-13fdc9390be442a0a9d9ffe37cf63c729bfeaf3e.tar.gz
crow-13fdc9390be442a0a9d9ffe37cf63c729bfeaf3e.zip
Merge pull request #202 from Rasie1/master
Conflict with std namespace
Diffstat (limited to 'include')
-rw-r--r--include/crow/query_string.h60
-rw-r--r--include/crow/routing.h8
2 files changed, 64 insertions, 4 deletions
diff --git a/include/crow/query_string.h b/include/crow/query_string.h
index 3f8bffe..2740441 100644
--- a/include/crow/query_string.h
+++ b/include/crow/query_string.h
@@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <iostream>
+#include <boost/optional.hpp>
namespace crow
{
@@ -197,6 +198,50 @@ inline char * qs_k2v(const char * key, char * const * qs_kv, int qs_kv_size, int
return NULL;
}
+inline boost::optional<std::pair<std::string, std::string>> qs_dict_name2kv(const char * dict_name, char * const * qs_kv, int qs_kv_size, int nth = 0)
+{
+ int i;
+ size_t name_len, skip_to_eq, skip_to_brace_open, skip_to_brace_close;
+
+ name_len = strlen(dict_name);
+
+#ifdef _qsSORTING
+// TODO: binary search for key in the sorted qs_kv
+#else // _qsSORTING
+ for(i=0; i<qs_kv_size; i++)
+ {
+ if ( strncmp(dict_name, qs_kv[i], name_len) == 0 )
+ {
+ skip_to_eq = strcspn(qs_kv[i], "=");
+ if ( qs_kv[i][skip_to_eq] == '=' )
+ skip_to_eq++;
+ skip_to_brace_open = strcspn(qs_kv[i], "[");
+ if ( qs_kv[i][skip_to_brace_open] == '[' )
+ skip_to_brace_open++;
+ skip_to_brace_close = strcspn(qs_kv[i], "]");
+
+ std::cout << skip_to_brace_open << " FUFUU " << skip_to_brace_close << std::endl;
+
+ if ( skip_to_brace_open <= skip_to_brace_close &&
+ skip_to_brace_open > 0 &&
+ skip_to_brace_close > 0 &&
+ nth == 0 )
+ {
+ auto key = std::string(qs_kv[i] + skip_to_brace_open, skip_to_brace_close - skip_to_brace_open);
+ auto value = std::string(qs_kv[i] + skip_to_eq);
+ return boost::make_optional(std::make_pair(key, value));
+ }
+ else
+ {
+ --nth;
+ }
+ }
+ }
+#endif // _qsSORTING
+
+ return boost::none;
+}
+
inline char * qs_scanvalue(const char * key, const char * qs, char * val, size_t val_len)
{
@@ -336,6 +381,21 @@ namespace crow
return ret;
}
+ std::vector<std::pair<std::string, std::string>> get_dict (const std::string& name) const
+ {
+ std::vector<std::pair<std::string, std::string>> ret;
+ std::string plus = name;
+
+ int count = 0;
+ while(1)
+ {
+ if (auto element = qs_dict_name2kv(plus.c_str(), key_value_pairs_.data(), key_value_pairs_.size(), count++))
+ ret.push_back(*element);
+ else
+ break;
+ }
+ return ret;
+ }
private:
std::string url_;
diff --git a/include/crow/routing.h b/include/crow/routing.h
index a8aa233..fe65ac4 100644
--- a/include/crow/routing.h
+++ b/include/crow/routing.h
@@ -156,7 +156,7 @@ namespace crow
struct Wrapped
{
template <typename ... Args>
- void set(Func f, typename std::enable_if<
+ void set_(Func f, typename std::enable_if<
!std::is_same<typename std::tuple_element<0, std::tuple<Args..., void>>::type, const request&>::value
, int>::type = 0)
{
@@ -190,7 +190,7 @@ namespace crow
};
template <typename ... Args>
- void set(Func f, typename std::enable_if<
+ void set_(Func f, typename std::enable_if<
std::is_same<typename std::tuple_element<0, std::tuple<Args..., void>>::type, const request&>::value &&
!std::is_same<typename std::tuple_element<1, std::tuple<Args..., void, void>>::type, response&>::value
, int>::type = 0)
@@ -205,7 +205,7 @@ namespace crow
}
template <typename ... Args>
- void set(Func f, typename std::enable_if<
+ void set_(Func f, typename std::enable_if<
std::is_same<typename std::tuple_element<0, std::tuple<Args..., void>>::type, const request&>::value &&
std::is_same<typename std::tuple_element<1, std::tuple<Args..., void, void>>::type, response&>::value
, int>::type = 0)
@@ -410,7 +410,7 @@ namespace crow
throw std::runtime_error("route_dynamic: Handler type is mismatched with URL parameters: " + rule_);
}
auto ret = detail::routing_handler_call_helper::Wrapped<Func, typename function_t::template arg<Indices>...>();
- ret.template set<
+ ret.template set_<
typename function_t::template arg<Indices>...
>(std::move(f));
return ret;