This parses the query component into a list of string pairs, the first is the key and the second the value.
Syntax (see uri_path for additional definitions): Both key and value are pct-decoded after parsing.
query = kv-pair *( "&" kv-pair ) kv-pair = key "=" [ value ] key = 1*qchar value = 1*qchar qchar = <pchar except "=" and "&"> | "/" | "?"
Note that this provides optional sorting for faster finds when there are a non-trivial number of pairs. However, once the query is sorted pairs must not be inserted.
Public Member Functions | |
| query () | |
| query (const std::string &v, bool dosort=false) | |
| void | sort () |
| bool | sorted () const |
| Test if sort() has been called. | |
| std::string | encoding () const |
| const_iterator | find (const std::string &key) const |
| iterator | find (const std::string &key) |
| template<typename T> | |
| bool | find (const std::string &key, T &value, bool &is_null) const |
Static Public Attributes | |
| static const char | PAIRS_SEP_CHAR |
| pairs separator char ('&') | |
| static const char | KEY_VALUE_SEP_CHAR |
| key-value separator char ('=') | |
Friends | |
| bool URIPP_API | parse (std::string::const_iterator &first, std::string::const_iterator last, query &v, std::string *errs) |
| uripp::query::query | ( | ) |
Construct.
| uripp::query::query | ( | const std::string & | v, | |
| bool | dosort = false | |||
| ) |
Construct from encoded string, for example "a=foo%20bar&b=1", and sort the keys if dosort is true. Note that this should not contain the leading '?'. See parse() for less strict construction.
| std::invalid_argument | if missing key or invalid encoding |
| std::string uripp::query::encoding | ( | ) | const |
Calculate encoded string.
| bool uripp::query::find | ( | const std::string & | key, | |
| T & | value, | |||
| bool & | is_null | |||
| ) | const [inline] |
Find the key and convert its associated value, returning true if the key is found and is_null true if the key is found but the value string is empty or isspace. The value is only set if found but not null. Note the search is linear.
| std::invalid_argument | if not null and cannot convert |
| iterator uripp::query::find | ( | const std::string & | key | ) |
Find the iterator for the key. Note the search is linear if not sorted.
| const_iterator uripp::query::find | ( | const std::string & | key | ) | const |
Find the const_iterator for the key. Note the search is linear if not sorted.
| void uripp::query::sort | ( | ) |
Sort the pairs by key. This will speed the find methods if there are more than a trivial number of pairs.
| bool URIPP_API parse | ( | std::string::const_iterator & | first, | |
| std::string::const_iterator | last, | |||
| query & | v, | |||
| std::string * | errs | |||
| ) | [friend] |
Parse URI query, returning whether found or not and advancing first and setting query if found. Does not skip leading space.
If errs is specified the following take place:
errs.
1.4.7