2016-07-28 17:01:08 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-28 17:01:08 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/qthelp_url.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
namespace qthelp {
|
|
|
|
|
2017-11-23 09:58:12 +00:00
|
|
|
QMap<QString, QString> url_parse_params(
|
|
|
|
const QString ¶ms,
|
|
|
|
UrlParamNameTransform transform) {
|
|
|
|
auto result = QMap<QString, QString>();
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2017-11-23 09:58:12 +00:00
|
|
|
const auto transformParamName = [transform](const QString &name) {
|
2016-07-28 17:01:08 +00:00
|
|
|
if (transform == UrlParamNameTransform::ToLower) {
|
|
|
|
return name.toLower();
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
};
|
2017-11-23 09:58:12 +00:00
|
|
|
for (const auto ¶m : params.split('&')) {
|
2016-07-28 17:01:08 +00:00
|
|
|
// Skip params without a name (starting with '=').
|
|
|
|
if (auto separatorPosition = param.indexOf('=')) {
|
2017-11-23 09:58:12 +00:00
|
|
|
const auto paramName = transformParamName(
|
|
|
|
(separatorPosition > 0)
|
|
|
|
? param.mid(0, separatorPosition)
|
|
|
|
: param);
|
|
|
|
const auto paramValue = (separatorPosition > 0)
|
|
|
|
? url_decode(param.mid(separatorPosition + 1))
|
|
|
|
: QString();
|
2016-12-20 13:03:51 +00:00
|
|
|
if (!result.contains(paramName)) {
|
|
|
|
result.insert(paramName, paramValue);
|
|
|
|
}
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace qthelp
|