uripp::query Class Reference

List of all members.

Detailed Description

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.

See also:
http://tools.ietf.org/html/rfc3986#section-3.4


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)


Constructor & Destructor Documentation

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.

Exceptions:
std::invalid_argument if missing key or invalid encoding


Member Function Documentation

std::string uripp::query::encoding (  )  const

Calculate encoded string.

template<typename T>
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.

Exceptions:
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.


Friends And Related Function Documentation

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:


Generated on Wed May 13 09:06:22 2009 for uripp by  doxygen 1.4.7