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:
Marc Mutz 2020-04-21 14:27:02 +02:00
parent bc205d81e7
commit 19bfcdaa43
3 changed files with 7 additions and 5 deletions

View File

@ -47,7 +47,7 @@
#include "private/qtldurl_p.h"
#else
QT_BEGIN_NAMESPACE
static bool qIsEffectiveTLD(QString domain)
static bool qIsEffectiveTLD(QStringView domain)
{
// provide minimal checking by not accepting cookies on real TLDs
return !domain.contains(QLatin1Char('.'));

View File

@ -114,9 +114,11 @@ Q_NETWORK_EXPORT QString qTopLevelDomain(const QString &domain)
\internal
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':
// 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
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:
return containsTLDEntry(QString(QLatin1Char('.') + domain), SuffixMatch);
if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2

View File

@ -60,10 +60,10 @@ QT_REQUIRE_CONFIG(topleveldomain);
QT_BEGIN_NAMESPACE
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)
{
return qIsEffectiveTLD(QStringRef(&domain));
return qIsEffectiveTLD(qToStringViewIgnoringNull(domain));
}
QT_END_NAMESPACE