URI query component. More...
#include <query.h>
Public Member Functions | |
std::string | encoding () const |
Calculate encoded string. More... | |
const_iterator | find (const std::string &key) const |
Find the const_iterator for the key. More... | |
iterator | find (const std::string &key) |
Find the iterator for the key. More... | |
template<typename T > | |
bool | find (const std::string &key, T &value, bool &is_null) const |
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. More... | |
query () | |
Construct. More... | |
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. More... | |
void | sort () |
Sort the pairs by key. More... | |
bool | sorted () const |
Test if sort() has been called. More... | |
Static Public Attributes | |
static const char | KEY_VALUE_SEP_CHAR = '=' |
key-value separator char ('=') More... | |
static const char | PAIRS_SEP_CHAR = '&' |
pairs separator char ('&') More... | |
static const char | PAIRS_SEP_CHAR2 = ';' |
pairs separator char (';') // added by Lauro More... | |
Private Attributes | |
bool | sorted_ |
Friends | |
bool TECOMMONEXPORT | parse (std::string::const_iterator &first, std::string::const_iterator last, query &v, std::string *errs) |
Parse URI query, returning whether found or not and advancing first and setting query if found. More... | |
URI query component.
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.
te::common::uri::query::query | ( | ) |
Construct.
Definition at line 35 of file query.cpp.
Referenced by te::common::URL::addQuery(), te::common::URL::beginQuery(), te::common::URL::clearQuery(), te::common::URL::endQuery(), te::common::URL::findQueryKey(), and te::common::URL::setEncodedQueryString().
te::common::uri::query::query | ( | const std::string & | v, |
bool | dosort = false |
||
) |
std::string te::common::uri::query::encoding | ( | ) | const |
Calculate encoded string.
Definition at line 50 of file query.cpp.
References te::common::uri::urisyn::encode(), KEY_VALUE_SEP_CHAR, PAIRS_SEP_CHAR, and te::common::uri::urisyn::QUERY_TRAITS.
Referenced by te::common::uri::operator<<().
query::const_iterator te::common::uri::query::find | ( | const std::string & | key | ) | const |
Find the const_iterator for the key.
Note the search is linear if not sorted.
Definition at line 61 of file query.cpp.
References sorted_.
Referenced by te::common::URL::findQueryKey().
query::iterator te::common::uri::query::find | ( | const std::string & | key | ) |
|
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 |
Definition at line 79 of file query.h.
References te::common::uri::convert().
void te::common::uri::query::sort | ( | ) |
|
inline |
|
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
. Definition at line 87 of file query.cpp.
Referenced by query().
|
static |
key-value separator char ('=')
Definition at line 88 of file query.h.
Referenced by encoding(), and te::common::uri::parse().
|
static |
pairs separator char ('&')
Definition at line 86 of file query.h.
Referenced by encoding(), and te::common::uri::parse().
|
static |
pairs separator char (';') // added by Lauro
Definition at line 87 of file query.h.
Referenced by te::common::uri::parse().
|
private |