37 std::string::const_iterator first = v.begin();
39 if (!
parse(first, v.end(), *
this, &errs) || first != v.end())
40 throw std::invalid_argument(
"invalid URI query: \"" + v +
"\"");
42 throw std::invalid_argument(errs);
43 if (!empty() && dosort)
47 std::sort(begin(), end());
52 for (const_iterator it = begin(); it != end(); ++it) {
61 query::const_iterator
query::find(
const std::string& key)
const {
65 const_iterator lb = std::lower_bound(begin(), end(), value_type(key,
""));
66 it = (lb != end() && lb->first == key) ? lb : end();
68 for (it = begin(); it != end(); ++it)
78 iterator lb = std::lower_bound(begin(), end(), value_type(key,
""));
79 it = (lb != end() && lb->first == key) ? lb : end();
81 for (it = begin(); it != end(); ++it)
87 bool parse(std::string::const_iterator& first, std::string::const_iterator last,
query& v, std::string* errs) {
88 std::string::const_iterator f = first;
91 for (
bool eof =
false; !eof;) {
95 for (
int i = 0; i < 2; ++i) {
96 std::string::const_iterator anchor = f;
112 value.assign(anchor, f);
114 key.assign(anchor, f);
124 if (!value.empty()) {
125 if (!errs || tmp.empty())
127 e +=
", (" +
convert(f - first) +
") missing key (ignoring value)";
129 }
else if (nokvsep) {
130 if (!errs || tmp.empty())
135 if (!errs || tmp.empty())
137 e +=
", (" +
convert(f - first) +
") invalid key encoding (using as is)";
140 if (!errs || tmp.empty())
142 e +=
", (" +
convert(f - first) +
") invalid value encoding (using as is)";
144 tmp.push_back(std::make_pair(key, value));
147 if (errs && !e.empty()) {
150 *errs +=
"URI query: \"" + std::string(first, f) +
"\"" + e;
static const char KEY_VALUE_SEP_CHAR
key-value separator char ('=')
void sort()
Sort the pairs by key.
bool parse(std::string::const_iterator &first, std::string::const_iterator last, authority &v)
Parse URI authority, returning whether found or not and advancing first and setting authority if foun...
std::string encoding() const
Calculate encoded string.
static const char PAIRS_SEP_CHAR2
pairs separator char (';') // added by Lauro
std::string encode(const traits &ts, const std::string &comp)
Encode the URI (sub) component.
static const char PAIRS_SEP_CHAR
pairs separator char ('&')
friend 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...
const traits QUERY_TRAITS
query traits
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
const_iterator find(const std::string &key) const
Find the const_iterator for the key.
std::string convert(const path &v)
URI path to string.