improved URI documentation regarding setQuery()/getQuery(); added getQueryParameters()/setQueryParameters()

This commit is contained in:
Günter Obiltschnig
2014-11-19 10:38:59 +01:00
parent 4b53f137de
commit a417d49d5d
4 changed files with 151 additions and 6 deletions

View File

@@ -26,7 +26,7 @@ namespace Poco {
const std::string URI::RESERVED_PATH = "?#";
const std::string URI::RESERVED_QUERY = "#/";
const std::string URI::RESERVED_QUERY = "?#/";
const std::string URI::RESERVED_FRAGMENT = "";
const std::string URI::ILLEGAL = "%<>{}|\\\"^`";
@@ -335,9 +335,9 @@ void URI::addQueryParameter(const std::string& param, const std::string& val)
{
std::string reserved(RESERVED_QUERY);
reserved += "=&";
if (!_query.empty()) _query.append(1, '&');
if (!_query.empty()) _query += '&';
encode(param, reserved, _query);
_query.append(1, '=');
_query += '=';
encode(val, reserved, _query);
}
@@ -350,6 +350,56 @@ std::string URI::getQuery() const
}
URI::QueryParameters URI::getQueryParameters() const
{
QueryParameters result;
std::string::const_iterator it(_query.begin());
std::string::const_iterator end(_query.end());
while (it != end)
{
std::string name;
std::string value;
while (it != end && *it != '=' && *it != '&')
{
if (*it == '+')
name += ' ';
else
name += *it;
++it;
}
if (it != end && *it == '=')
{
++it;
while (it != end && *it != '&')
{
if (*it == '+')
value += ' ';
else
value += *it;
++it;
}
}
std::string decodedName;
std::string decodedValue;
URI::decode(name, decodedName);
URI::decode(value, decodedValue);
result.push_back(std::make_pair(decodedName, decodedValue));
if (it != end && *it == '&') ++it;
}
return result;
}
void URI::setQueryParameters(const QueryParameters& params)
{
_query.clear();
for (QueryParameters::const_iterator it = params.begin(); it != params.end(); ++it)
{
addQueryParameter(it->first, it->second);
}
}
void URI::setFragment(const std::string& fragment)
{
_fragment.clear();