diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/http_response.h | 5 | ||||
-rw-r--r-- | include/json.h | 41 | ||||
-rw-r--r-- | include/query_string.h | 33 |
3 files changed, 70 insertions, 9 deletions
diff --git a/include/http_response.h b/include/http_response.h index 7288cc3..807e6ac 100644 --- a/include/http_response.h +++ b/include/http_response.h @@ -41,8 +41,11 @@ namespace crow explicit response(int code) : code(code) {} response(std::string body) : body(std::move(body)) {} response(json::wvalue&& json_value) : json_value(std::move(json_value)) {} - response(const json::wvalue& json_value) : body(json::dump(json_value)) {} response(int code, std::string body) : body(std::move(body)), code(code) {} + response(const json::wvalue& json_value) : body(json::dump(json_value)) + { + set_header("Content-Type", "application/json"); + } response(response&& r) { diff --git a/include/json.h b/include/json.h index d79fe88..68f06a2 100644 --- a/include/json.h +++ b/include/json.h @@ -284,6 +284,15 @@ namespace crow return boost::lexical_cast<double>(start_, end_-start_); } + bool b() const + { +#ifndef CROW_JSON_NO_ERROR_CHECK + if (t() != type::True && t() != type::False) + throw std::runtime_error("value is not boolean"); +#endif + return t() == type::True; + } + void unescape() const { if (*(start_-1)) @@ -824,9 +833,9 @@ namespace crow return {};*/ break; case '.': - state = (NumberParsingState)"\7\7\7\4\7\7\7"[state]; + state = (NumberParsingState)"\7\7\4\4\7\7\7"[state]; /* - if (state == NumberParsingState::Digits) + if (state == NumberParsingState::Digits || state == NumberParsingState::ZeroFirst) { state = NumberParsingState::DigitsAfterPoints; } @@ -1134,7 +1143,23 @@ namespace crow return *this; } - wvalue& operator = (uint16_t value) + wvalue& operator = (unsigned short value) + { + reset(); + t_ = type::Number; + d = (double)value; + return *this; + } + + wvalue& operator = (short value) + { + reset(); + t_ = type::Number; + d = (double)value; + return *this; + } + + wvalue& operator = (long long value) { reset(); t_ = type::Number; @@ -1142,7 +1167,7 @@ namespace crow return *this; } - wvalue& operator = (int16_t value) + wvalue& operator = (long value) { reset(); t_ = type::Number; @@ -1150,7 +1175,7 @@ namespace crow return *this; } - wvalue& operator = (uint32_t value) + wvalue& operator = (int value) { reset(); t_ = type::Number; @@ -1158,7 +1183,7 @@ namespace crow return *this; } - wvalue& operator = (int32_t value) + wvalue& operator = (unsigned long long value) { reset(); t_ = type::Number; @@ -1166,7 +1191,7 @@ namespace crow return *this; } - wvalue& operator = (uint64_t value) + wvalue& operator = (unsigned long value) { reset(); t_ = type::Number; @@ -1174,7 +1199,7 @@ namespace crow return *this; } - wvalue& operator = (int64_t value) + wvalue& operator = (unsigned int value) { reset(); t_ = type::Number; diff --git a/include/query_string.h b/include/query_string.h index d0a93ea..86c99cc 100644 --- a/include/query_string.h +++ b/include/query_string.h @@ -245,6 +245,39 @@ namespace crow } + query_string(const query_string& qs) + : url_(qs.url_) + { + for(auto p:qs.key_value_pairs_) + { + key_value_pairs_.push_back((char*)(p-qs.url_.c_str()+url_.c_str())); + } + } + + query_string& operator = (const query_string& qs) + { + url_ = qs.url_; + key_value_pairs_.clear(); + for(auto p:qs.key_value_pairs_) + { + key_value_pairs_.push_back((char*)(p-qs.url_.c_str()+url_.c_str())); + } + return *this; + } + + query_string& operator = (query_string&& qs) + { + key_value_pairs_ = std::move(qs.key_value_pairs_); + char* old_data = (char*)qs.url_.c_str(); + url_ = std::move(qs.url_); + for(auto& p:key_value_pairs_) + { + p += (char*)url_.c_str() - old_data; + } + return *this; + } + + query_string(std::string url) : url_(std::move(url)) { |