Qt 4.8
Functions
qtldurl_p.h File Reference
#include "QtCore/qurl.h"
#include "QtCore/qstring.h"

Go to the source code of this file.

Functions

Q_CORE_EXPORT bool qIsEffectiveTLD (const QString &domain)
 Return true if domain is a top-level-domain per Qt's copy of the Mozilla public suffix list. More...
 
Q_CORE_EXPORT QString qTopLevelDomain (const QString &domain)
 Return the top-level-domain per Qt's copy of the Mozilla public suffix list of domain. More...
 

Function Documentation

◆ qIsEffectiveTLD()

Q_CORE_EXPORT bool qIsEffectiveTLD ( const QString domain)

Return true if domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.

Warning
This function is not part of the public interface.

Definition at line 97 of file qtldurl.cpp.

Referenced by qTopLevelDomain(), and QNetworkCookieJar::setCookiesFromUrl().

98 {
99  // for domain 'foo.bar.com':
100  // 1. return if TLD table contains 'foo.bar.com'
101  if (containsTLDEntry(domain))
102  return true;
103 
104  if (domain.contains(QLatin1Char('.'))) {
105  int count = domain.size() - domain.indexOf(QLatin1Char('.'));
106  QString wildCardDomain;
107  wildCardDomain.reserve(count + 1);
108  wildCardDomain.append(QLatin1Char('*'));
109  wildCardDomain.append(domain.right(count));
110  // 2. if table contains '*.bar.com',
111  // test if table contains '!foo.bar.com'
112  if (containsTLDEntry(wildCardDomain)) {
113  QString exceptionDomain;
114  exceptionDomain.reserve(domain.size() + 1);
115  exceptionDomain.append(QLatin1Char('!'));
116  exceptionDomain.append(domain);
117  return (! containsTLDEntry(exceptionDomain));
118  }
119  }
120  return false;
121 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
static bool containsTLDEntry(const QString &entry)
Definition: qtldurl.cpp:50
The QString class provides a Unicode character string.
Definition: qstring.h:83
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QString & append(QChar c)
Definition: qstring.cpp:1777
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qTopLevelDomain()

Q_CORE_EXPORT QString qTopLevelDomain ( const QString domain)

Return the top-level-domain per Qt's copy of the Mozilla public suffix list of domain.

Warning
This function is not part of the public interface.

Definition at line 73 of file qtldurl.cpp.

Referenced by QUrl::topLevelDomain().

74 {
75  QStringList sections = domain.toLower().split(QLatin1Char('.'), QString::SkipEmptyParts);
76  if (sections.isEmpty())
77  return QString();
78 
79  QString level, tld;
80  for (int j = sections.count() - 1; j >= 0; --j) {
81  level.prepend(QLatin1Char('.') + sections.at(j));
82  if (qIsEffectiveTLD(level.right(level.size() - 1)))
83  tld = level;
84  }
85  return tld;
86 }
QString & prepend(QChar c)
Definition: qstring.h:261
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain)
Return true if domain is a top-level-domain per Qt's copy of the Mozilla public suffix list...
Definition: qtldurl.cpp:97
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55