本文整理汇总了C++中QUrl::topLevelDomain方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::topLevelDomain方法的具体用法?C++ QUrl::topLevelDomain怎么用?C++ QUrl::topLevelDomain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::topLevelDomain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toSecondLevelDomain
// Version for Qt < 4.8 has one issue, it will wrongly
// count .co.uk (and others) as second-level domain
static QString toSecondLevelDomain(const QUrl &url)
{
#if QT_VERSION >= 0x040800
const QString topLevelDomain = url.topLevelDomain();
const QString urlHost = url.host();
if (topLevelDomain.isEmpty() || urlHost.isEmpty()) {
return QString();
}
QString domain = urlHost.left(urlHost.size() - topLevelDomain.size());
if (domain.count(QL1C('.')) == 0) {
return urlHost;
}
while (domain.count(QL1C('.')) != 0) {
domain = domain.mid(domain.indexOf(QL1C('.')) + 1);
}
return domain + topLevelDomain;
#else
QString domain = url.host();
if (domain.count(QL1C('.')) == 0) {
return QString();
}
while (domain.count(QL1C('.')) != 1) {
domain = domain.mid(domain.indexOf(QL1C('.')) + 1);
}
return domain;
#endif
}
示例2: urlsShareSameDomain
static bool urlsShareSameDomain(const QUrl& url, const QUrl& firstPartyUrl)
{
QString firstPartyTLD = firstPartyUrl.topLevelDomain();
QString requestTLD = url.topLevelDomain();
if (firstPartyTLD != requestTLD)
return false;
QString firstPartyDomain = QString(firstPartyUrl.host().toLower());
QString requestDomain = QString(url.host().toLower());
removeTopLevelDomain(&firstPartyDomain, firstPartyTLD);
removeTopLevelDomain(&requestDomain, requestTLD);
if (firstPartyDomain.section(QLatin1Char('.'), -1) == requestDomain.section(QLatin1Char('.'), -1))
return true;
return false;
}
示例3: isDomainTheSame
bool CookieJar::isDomainTheSame(const QUrl &first, const QUrl &second)
{
const QString firstTld(first.topLevelDomain());
const QString secondTld(second.topLevelDomain());
if (firstTld != secondTld)
{
return false;
}
QString firstDomain(QLatin1Char('.') + first.host().toLower());
firstDomain.remove((firstDomain.length() - firstTld.length()), firstTld.length());
QString secondDomain(QLatin1Char('.') + second.host().toLower());
secondDomain.remove((secondDomain.length() - secondTld.length()), secondTld.length());
if (firstDomain.section(QLatin1Char('.'), -1) == secondDomain.section(QLatin1Char('.'), -1))
{
return true;
}
return false;
}