MCPcopy Create free account
hub / github.com/CrowCpp/Crow / query_string

Class query_string

include/crow/query_string.h:305–510  ·  view source on GitHub ↗

A class to represent any data coming after the `?` in the request URL into key-value pairs.

Source from the content-addressed store, hash-verified

303 struct request;
304 /// A class to represent any data coming after the `?` in the request URL into key-value pairs.
305 class query_string
306 {
307 public:
308 static const int MAX_KEY_VALUE_PAIRS_COUNT = 256;
309
310 query_string() = default;
311
312 query_string(const query_string& qs):
313 url_(qs.url_)
314 {
315 for (auto p : qs.key_value_pairs_)
316 {
317 key_value_pairs_.push_back((char*)(p - qs.url_.c_str() + url_.c_str()));
318 }
319 }
320
321 query_string& operator=(const query_string& qs)
322 {
323 url_ = qs.url_;
324 key_value_pairs_.clear();
325 for (auto p : qs.key_value_pairs_)
326 {
327 key_value_pairs_.push_back((char*)(p - qs.url_.c_str() + url_.c_str()));
328 }
329 return *this;
330 }
331
332 query_string& operator=(query_string&& qs) noexcept
333 {
334 key_value_pairs_ = std::move(qs.key_value_pairs_);
335 char* old_data = (char*)qs.url_.c_str();
336 url_ = std::move(qs.url_);
337 for (auto& p : key_value_pairs_)
338 {
339 p += (char*)url_.c_str() - old_data;
340 }
341 return *this;
342 }
343
344
345 query_string(std::string params, bool url = true):
346 url_(std::move(params))
347 {
348 if (url_.empty())
349 return;
350
351 key_value_pairs_.resize(MAX_KEY_VALUE_PAIRS_COUNT);
352 size_t count = qs_parse(&url_[0], &key_value_pairs_[0], MAX_KEY_VALUE_PAIRS_COUNT, url);
353
354 key_value_pairs_.resize(count);
355 key_value_pairs_.shrink_to_fit();
356 }
357
358 void clear()
359 {
360 key_value_pairs_.clear();
361 url_.clear();
362 }

Callers 2

on_urlMethod · 0.85
get_body_paramsMethod · 0.85

Calls 2

clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected