qTopLevelDomain: use QStringRef more

qIsEffectiveTLD() and containsTLDEntry() now
have overloaded versions with QStringRef arg.

Change-Id: Ic2b7fd56c8ea1579d3e4bdf4ed0e10405515d417
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Anton Kudryavtsev 2016-04-21 22:35:32 +03:00
parent ebbfc55667
commit be6c14211e
2 changed files with 14 additions and 5 deletions

View File

@ -46,7 +46,7 @@
QT_BEGIN_NAMESPACE
static bool containsTLDEntry(const QString &entry)
static bool containsTLDEntry(const QStringRef &entry)
{
int index = qt_hash(entry) % tldCount;
@ -69,6 +69,11 @@ static bool containsTLDEntry(const QString &entry)
return false;
}
static inline bool containsTLDEntry(const QString &entry)
{
return containsTLDEntry(QStringRef(&entry));
}
/*!
\internal
@ -86,7 +91,7 @@ Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain)
QString level, tld;
for (int j = sections.count() - 1; j >= 0; --j) {
level.prepend(QLatin1Char('.') + sections.at(j));
if (qIsEffectiveTLD(level.right(level.size() - 1)))
if (qIsEffectiveTLD(level.rightRef(level.size() - 1)))
tld = level;
}
return tld;
@ -98,7 +103,7 @@ Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain)
Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.
*/
Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain)
Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain)
{
// for domain 'foo.bar.com':
// 1. return if TLD table contains 'foo.bar.com'
@ -108,7 +113,7 @@ Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain)
const int dot = domain.indexOf(QLatin1Char('.'));
if (dot >= 0) {
int count = domain.size() - dot;
QString wildCardDomain = QLatin1Char('*') + domain.rightRef(count);
QString wildCardDomain = QLatin1Char('*') + domain.right(count);
// 2. if table contains '*.bar.com',
// test if table contains '!foo.bar.com'
if (containsTLDEntry(wildCardDomain)) {

View File

@ -57,7 +57,11 @@
QT_BEGIN_NAMESPACE
Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain);
Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain);
Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain);
inline bool qIsEffectiveTLD(const QString &domain)
{
return qIsEffectiveTLD(QStringRef(&domain));
}
QT_END_NAMESPACE