Crow  1.1
A C++ microframework for the web
crow::query_string Class Reference

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

#include <query_string.h>

Public Member Functions

 query_string (const query_string &qs)
 
query_stringoperator= (const query_string &qs)
 
query_stringoperator= (query_string &&qs) noexcept
 
 query_string (std::string params, bool url=true)
 
void clear ()
 
char * get (const std::string &name) const
 Get a value from a name, used for ?name=value. More...
 
char * pop (const std::string &name)
 Works similar to get() except it removes the item from the query string.
 
std::vector< char * > get_list (const std::string &name, bool use_brackets=true) const
 Returns a list of values, passed as ?name[]=value1&name[]=value2&...name[]=valuen with n being the size of the list. More...
 
std::vector< char * > pop_list (const std::string &name, bool use_brackets=true)
 Similar to get_list() but it removes the.
 
std::unordered_map< std::string, std::string > get_dict (const std::string &name) const
 Works similar to get_list() except the brackets are mandatory must not be empty. More...
 
std::unordered_map< std::string, std::string > pop_dict (const std::string &name)
 Works the same as get_dict() but removes the values from the query string.
 
std::vector< std::string > keys () const
 

Static Public Attributes

static const int MAX_KEY_VALUE_PAIRS_COUNT = 256
 

Friends

std::ostream & operator<< (std::ostream &os, const query_string &qs)
 

Detailed Description

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

Member Function Documentation

◆ get()

char* crow::query_string::get ( const std::string &  name) const
inline

Get a value from a name, used for ?name=value.

Note: this method returns the value of the first occurrence of the key only, to return all occurrences, see get_list().

◆ get_dict()

std::unordered_map<std::string, std::string> crow::query_string::get_dict ( const std::string &  name) const
inline

Works similar to get_list() except the brackets are mandatory must not be empty.

For example calling get_dict(yourname) on ?yourname[sub1]=42&yourname[sub2]=84 would give a map containing {sub1 : 42, sub2 : 84}.

if your query string has both empty brackets and ones with a key inside, use pop_list() to get all the values without a key before running this method.

◆ get_list()

std::vector<char*> crow::query_string::get_list ( const std::string &  name,
bool  use_brackets = true 
) const
inline

Returns a list of values, passed as ?name[]=value1&name[]=value2&...name[]=valuen with n being the size of the list.

Note: Square brackets in the above example are controlled by use_brackets boolean (true by default). If set to false, the example becomes ?name=value1,name=value2...name=valuen


The documentation for this class was generated from the following file: