Port qIsEffectiveTLD() to QStringView
Also add a piece of documentation that the input needs to be in lower-case (the implementation uses qt_hash to index into a table of TLDs, and qt_hash is case-sensitive). Change-Id: I911c0e2bb0826fc1b0fc01ed60bdfd6e4c0298f2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
bc205d81e7
commit
19bfcdaa43
@ -47,7 +47,7 @@
|
|||||||
#include "private/qtldurl_p.h"
|
#include "private/qtldurl_p.h"
|
||||||
#else
|
#else
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
static bool qIsEffectiveTLD(QString domain)
|
static bool qIsEffectiveTLD(QStringView domain)
|
||||||
{
|
{
|
||||||
// provide minimal checking by not accepting cookies on real TLDs
|
// provide minimal checking by not accepting cookies on real TLDs
|
||||||
return !domain.contains(QLatin1Char('.'));
|
return !domain.contains(QLatin1Char('.'));
|
||||||
|
@ -114,9 +114,11 @@ Q_NETWORK_EXPORT QString qTopLevelDomain(const QString &domain)
|
|||||||
\internal
|
\internal
|
||||||
|
|
||||||
Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.
|
Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.
|
||||||
|
|
||||||
|
The \a domain must be in lower-case format (as per QString::toLower()).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Q_NETWORK_EXPORT bool qIsEffectiveTLD(const QStringRef &domain)
|
Q_NETWORK_EXPORT bool qIsEffectiveTLD(QStringView domain)
|
||||||
{
|
{
|
||||||
// for domain 'foo.bar.com':
|
// for domain 'foo.bar.com':
|
||||||
// 1. return if TLD table contains 'foo.bar.com'
|
// 1. return if TLD table contains 'foo.bar.com'
|
||||||
@ -126,7 +128,7 @@ Q_NETWORK_EXPORT bool qIsEffectiveTLD(const QStringRef &domain)
|
|||||||
if (containsTLDEntry(domain, ExactMatch)) // 1
|
if (containsTLDEntry(domain, ExactMatch)) // 1
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const int dot = domain.indexOf(QLatin1Char('.'));
|
const auto dot = domain.indexOf(QLatin1Char('.'));
|
||||||
if (dot < 0) // Actual TLD: may be effective if the subject of a wildcard rule:
|
if (dot < 0) // Actual TLD: may be effective if the subject of a wildcard rule:
|
||||||
return containsTLDEntry(QString(QLatin1Char('.') + domain), SuffixMatch);
|
return containsTLDEntry(QString(QLatin1Char('.') + domain), SuffixMatch);
|
||||||
if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2
|
if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2
|
||||||
|
@ -60,10 +60,10 @@ QT_REQUIRE_CONFIG(topleveldomain);
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
Q_NETWORK_EXPORT QString qTopLevelDomain(const QString &domain);
|
Q_NETWORK_EXPORT QString qTopLevelDomain(const QString &domain);
|
||||||
Q_NETWORK_EXPORT bool qIsEffectiveTLD(const QStringRef &domain);
|
Q_NETWORK_EXPORT bool qIsEffectiveTLD(QStringView domain);
|
||||||
inline bool qIsEffectiveTLD(const QString &domain)
|
inline bool qIsEffectiveTLD(const QString &domain)
|
||||||
{
|
{
|
||||||
return qIsEffectiveTLD(QStringRef(&domain));
|
return qIsEffectiveTLD(qToStringViewIgnoringNull(domain));
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user