GH #75: Poco::Uri addQueryParameter method

- added GH #75: Poco::Uri addQueryParameter method
This commit is contained in:
aleks-f 2013-03-19 22:51:04 -05:00
Родитель ce666f84f1
Коммит b1c6065ffc
4 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -34,6 +34,7 @@ Release 1.5.2 (2013-03-??)
- fixed GH #130: prefer sysconf over sysctlbyname
- fixed GH #131: no timezone global var on OpenBSD
- fixed GH #102: Some subprojects don't have x64 solutions for VS 2010
- added GH #75: Poco::Uri addQueryParameter method
Release 1.5.1 (2013-01-11)
==========================

Просмотреть файл

@ -175,6 +175,13 @@ public:
void setQuery(const std::string& query);
/// Sets the query part of the URI.
void addQueryParameter(const std::string& param, const std::string& val = "");
/// Adds "param=val" to the query; "param" may not be empty.
/// If val is empty, only '=' is appended to the parameter.
///
/// In addition to regular encoding, function also encodes '&' and '=',
/// if found in param or val.
const std::string& getRawQuery() const;
/// Returns the unencoded query part of the URI.

Просмотреть файл

@ -340,6 +340,18 @@ void URI::setQuery(const std::string& query)
}
void URI::addQueryParameter(const std::string& param, const std::string& val)
{
std::string reserved(RESERVED_QUERY);
reserved += "=&";
if (_query.empty()) _query.append(1, '?');
else _query.append(1, '&');
encode(param, reserved, _query);
_query.append(1, '=');
encode(val, reserved, _query);
}
std::string URI::getQuery() const
{
std::string query;

Просмотреть файл

@ -764,6 +764,13 @@ void URITest::testOther()
assert(uri.getRawQuery() == "q=pony%7eride");
assert(uri.toString() == "http://google.com/search?q=pony%7eride#frag%20ment");
assert(uri.getPathEtc() == "/search?q=pony%7eride#frag%20ment");
uri.addQueryParameter("pa=ra&m1");
assert(uri.getRawQuery() == "q=pony%7eride&pa%3Dra%26m1=");
assert(uri.getQuery() == "q=pony~ride&pa=ra&m1=");
uri.addQueryParameter("pa=ra&m2", "val&ue");
assert(uri.getRawQuery() == "q=pony%7eride&pa%3Dra%26m1=&pa%3Dra%26m2=val%26ue");
assert(uri.getQuery() == "q=pony~ride&pa=ra&m1=&pa=ra&m2=val&ue");
}