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;
|
|
|
|
}
|
|
|
|
|
2018-04-24 19:09:20 +00:00
|
|
|
bool is_ipv6(const QString &ip) {
|
|
|
|
//static const auto regexp = QRegularExpression("^[a-fA-F0-9:]+$");
|
|
|
|
//return regexp.match(ip).hasMatch();
|
2018-05-17 10:27:27 +00:00
|
|
|
return ip.indexOf('.') < 0 && ip.indexOf(':') >= 0;
|
2018-04-24 19:09:20 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 15:45:04 +00:00
|
|
|
QString url_append_query(const QString &url, const QString &add) {
|
|
|
|
const auto query = ranges::find(url, '?');
|
|
|
|
const auto hash = ranges::find(url, '#');
|
|
|
|
const auto base = url.mid(0, hash - url.begin());
|
|
|
|
const auto added = base
|
|
|
|
+ (hash <= query ? '?' : '&')
|
|
|
|
+ add;
|
|
|
|
const auto result = added
|
|
|
|
+ (hash < url.end() ? url.mid(hash - url.begin()) : QString());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
} // namespace qthelp
|