Crow  1.0
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...

Collaboration diagram for crow::query_string:

Public Member Functions

 query_string ()
 
 query_string (const query_string &qs)
 
query_stringoperator= (const query_string &qs)
 
query_stringoperator= (query_string &&qs)
 
 query_string (std::string url)
 
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. More...
 
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. More...
 
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. More...
 
std::vector< std::string > keys () const
 

Static Public Attributes

static const int MAX_KEY_VALUE_PAIRS_COUNT = 256
 

Private Attributes

std::string url_
 
std::vector< char * > key_value_pairs_
 

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.

Constructor & Destructor Documentation

◆ query_string() [1/3]

crow::query_string::query_string ( )
inline

◆ query_string() [2/3]

crow::query_string::query_string ( const query_string qs)
inline

◆ query_string() [3/3]

crow::query_string::query_string ( std::string  url)
inline
Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

query_string& crow::query_string::operator= ( const query_string qs)
inline

◆ operator=() [2/2]

query_string& crow::query_string::operator= ( query_string &&  qs)
inline

◆ clear()

void crow::query_string::clear ( )
inline
Here is the caller graph for this function:

◆ 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop()

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

Works similar to get() except it removes the item from the query string.

Here is the call graph for this function:

◆ 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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_list()

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

Similar to get_list() but it removes the.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_dict()

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

Works the same as get_dict() but removes the values from the query string.

Here is the call graph for this function:

◆ keys()

std::vector<std::string> crow::query_string::keys ( ) const
inline

Friends And Related Function Documentation

◆ operator<<

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

Member Data Documentation

◆ MAX_KEY_VALUE_PAIRS_COUNT

const int crow::query_string::MAX_KEY_VALUE_PAIRS_COUNT = 256
static

◆ url_

std::string crow::query_string::url_
private

◆ key_value_pairs_

std::vector<char*> crow::query_string::key_value_pairs_
private

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