Qt 4.8
Public Types | Public Functions | Public Variables | List of all members
QUrlPrivate Class Reference

Public Types

enum  ParseOptions { ParseAndSet, ParseOnly }
 
enum  State { Parsed = 0x1, Validated = 0x2, Normalized = 0x4, HostCanonicalized = 0x8 }
 

Public Functions

QString authority (QUrl::FormattingOptions options=QUrl::None) const
 
QString canonicalHost () const
 
void clear ()
 
QString createErrorString ()
 
void ensureEncodedParts () const
 
QString fragmentImpl () const
 
QByteArray mergePaths (const QByteArray &relativePath) const
 
const QByteArraynormalized () const
 
void parse (ParseOptions parseOptions=ParseAndSet) const
 
void queryItem (int pos, int *value, int *end)
 
 QUrlPrivate ()
 
 QUrlPrivate (const QUrlPrivate &other)
 
void setAuthority (const QString &auth)
 
void setEncodedAuthority (const QByteArray &authority)
 
void setEncodedUrl (const QByteArray &encodedUrl, QUrl::ParsingMode parsingMode)
 
void setEncodedUserInfo (const QUrlParseData *parseData)
 
bool setUrl (const QString &url)
 
void setUserInfo (const QString &userInfo)
 
QByteArray toEncoded (QUrl::FormattingOptions options=QUrl::None) const
 
QString userInfo (QUrl::FormattingOptions options=QUrl::None) const
 
void validate () const
 

Public Variables

QByteArray encodedFragment
 
QByteArray encodedNormalized
 
QByteArray encodedOriginal
 
QByteArray encodedPassword
 
QByteArray encodedPath
 
QByteArray encodedUserName
 
QUrlErrorInfo errorInfo
 
QString fragment
 
bool hasFragment
 
bool hasQuery
 
QString host
 
bool isHostValid
 
bool isValid
 
QMutex mutex
 
char pairDelimiter
 
QUrl::ParsingMode parsingMode
 
QString password
 
QString path
 
int port
 
QByteArray query
 
QAtomicInt ref
 
QString scheme
 
int stateFlags
 
QString userName
 
char valueDelimiter
 

Detailed Description

Definition at line 320 of file qurl.cpp.

Enumerations

◆ ParseOptions

Enumerator
ParseAndSet 
ParseOnly 

Definition at line 343 of file qurl.cpp.

◆ State

Enumerator
Parsed 
Validated 
Normalized 
HostCanonicalized 

Definition at line 381 of file qurl.cpp.

381  {
382  Parsed = 0x1,
383  Validated = 0x2,
384  Normalized = 0x4,
385  HostCanonicalized = 0x8
386  };

Constructors and Destructors

◆ QUrlPrivate() [1/2]

QUrlPrivate::QUrlPrivate ( )

Definition at line 3439 of file qurl.cpp.

3440 {
3441  ref = 1;
3442  port = -1;
3443  isValid = false;
3444  isHostValid = true;
3446  valueDelimiter = '=';
3447  pairDelimiter = '&';
3448  stateFlags = 0;
3449  hasFragment = false;
3450  hasQuery = false;
3451 }
bool hasFragment
Definition: qurl.cpp:374
int stateFlags
Definition: qurl.cpp:387
QAtomicInt ref
Definition: qurl.cpp:354
QUrl::ParsingMode parsingMode
Definition: qurl.cpp:371
bool hasQuery
Definition: qurl.cpp:373
int port
Definition: qurl.cpp:370
char valueDelimiter
Definition: qurl.cpp:378
bool isValid
Definition: qurl.cpp:375
char pairDelimiter
Definition: qurl.cpp:379
bool isHostValid
Definition: qurl.cpp:376

◆ QUrlPrivate() [2/2]

QUrlPrivate::QUrlPrivate ( const QUrlPrivate other)

Definition at line 3454 of file qurl.cpp.

3455  : scheme(copy.scheme),
3456  userName(copy.userName),
3457  password(copy.password),
3458  host(copy.host),
3459  path(copy.path),
3460  query(copy.query),
3461  fragment(copy.fragment),
3462  encodedOriginal(copy.encodedOriginal),
3463  encodedUserName(copy.encodedUserName),
3464  encodedPassword(copy.encodedPassword),
3465  encodedPath(copy.encodedPath),
3466  encodedFragment(copy.encodedFragment),
3467  port(copy.port),
3468  parsingMode(copy.parsingMode),
3469  hasQuery(copy.hasQuery),
3470  hasFragment(copy.hasFragment),
3471  isValid(copy.isValid),
3472  isHostValid(copy.isHostValid),
3473  valueDelimiter(copy.valueDelimiter),
3474  pairDelimiter(copy.pairDelimiter),
3475  stateFlags(copy.stateFlags),
3476  encodedNormalized(copy.encodedNormalized)
3477 { ref = 1; }
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
QByteArray encodedUserName
Definition: qurl.cpp:365
bool hasFragment
Definition: qurl.cpp:374
QByteArray encodedNormalized
Definition: qurl.cpp:396
QString fragment
Definition: qurl.cpp:362
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
QAtomicInt ref
Definition: qurl.cpp:354
QUrl::ParsingMode parsingMode
Definition: qurl.cpp:371
QByteArray query
Definition: qurl.cpp:361
bool hasQuery
Definition: qurl.cpp:373
QByteArray encodedOriginal
Definition: qurl.cpp:364
QString scheme
Definition: qurl.cpp:356
QString host
Definition: qurl.cpp:359
QByteArray encodedFragment
Definition: qurl.cpp:368
int port
Definition: qurl.cpp:370
QString userName
Definition: qurl.cpp:357
char valueDelimiter
Definition: qurl.cpp:378
bool isValid
Definition: qurl.cpp:375
char pairDelimiter
Definition: qurl.cpp:379
bool isHostValid
Definition: qurl.cpp:376

Functions

◆ authority()

QString QUrlPrivate::authority ( QUrl::FormattingOptions  options = QUrl::None) const

Definition at line 3568 of file qurl.cpp.

Referenced by QUrl::authority(), mergePaths(), QUrl::resolved(), toEncoded(), QUrl::toString(), and validate().

3569 {
3570  // Caller must lock mutex first
3571 
3572  if ((options & QUrl::RemoveAuthority) == QUrl::RemoveAuthority)
3573  return QString();
3574 
3575  QString tmp = userInfo(options);
3576  if (!tmp.isEmpty())
3577  tmp += QLatin1Char('@');
3578  tmp += canonicalHost();
3579  if (!(options & QUrl::RemovePort) && port != -1)
3580  tmp += QLatin1Char(':') + QString::number(port);
3581 
3582  return tmp;
3583 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString userInfo(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3673
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString canonicalHost() const
Definition: qurl.cpp:3479
int port
Definition: qurl.cpp:370
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ canonicalHost()

QString QUrlPrivate::canonicalHost ( ) const

Definition at line 3479 of file qurl.cpp.

Referenced by authority(), QUrl::host(), and normalized().

3480 {
3481  // Caller must lock mutex first
3483  return host;
3484 
3485  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
3487  if (host.contains(QLatin1Char(':'))) {
3488  // This is an IP Literal, use _IPLiteral to validate
3489  QByteArray ba = host.toLatin1();
3490  bool needsBraces = false;
3491  if (!ba.startsWith('[')) {
3492  // surround the IP Literal with [ ] if it's not already done so
3493  ba.reserve(ba.length() + 2);
3494  ba.prepend('[');
3495  ba.append(']');
3496  needsBraces = true;
3497  }
3498 
3499  const char *ptr = ba.constData();
3500  if (!_IPLiteral(&ptr))
3501  that->host.clear();
3502  else if (needsBraces)
3503  that->host = QString::fromLatin1(ba.toLower());
3504  else
3505  that->host = host.toLower();
3506  } else {
3507  that->host = qt_ACE_do(host, NormalizeAce);
3508  }
3509  that->isHostValid = !that->host.isNull();
3510  return that->host;
3511 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QByteArray & append(char c)
Appends the character ch to this byte array.
static bool QT_FASTCALL _IPLiteral(const char **ptr)
Definition: qurl.cpp:754
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toLower() const
Returns a lowercase copy of the byte array.
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
#define QURL_SETFLAG(a, b)
Definition: qurl.cpp:276
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
int stateFlags
Definition: qurl.cpp:387
static QString qt_ACE_do(const QString &domain, AceOperation op)
Definition: qurl.cpp:3334
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T * ptr(const T &t)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QString host
Definition: qurl.cpp:359
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isHostValid
Definition: qurl.cpp:376

◆ clear()

void QUrlPrivate::clear ( )

Definition at line 3968 of file qurl.cpp.

Referenced by QUrl::setEncodedUrl(), and QUrl::setUrl().

3969 {
3970  scheme.clear();
3971  userName.clear();
3972  password.clear();
3973  host.clear();
3974  port = -1;
3975  path.clear();
3976  query.clear();
3977  fragment.clear();
3978 
3982  encodedPath.clear();
3985 
3986  isValid = false;
3987  hasQuery = false;
3988  hasFragment = false;
3989 
3990  valueDelimiter = '=';
3991  pairDelimiter = '&';
3992 
3994 }
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
QByteArray encodedUserName
Definition: qurl.cpp:365
bool hasFragment
Definition: qurl.cpp:374
QByteArray encodedNormalized
Definition: qurl.cpp:396
QString fragment
Definition: qurl.cpp:362
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
QByteArray query
Definition: qurl.cpp:361
bool hasQuery
Definition: qurl.cpp:373
QByteArray encodedOriginal
Definition: qurl.cpp:364
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString scheme
Definition: qurl.cpp:356
QString host
Definition: qurl.cpp:359
QByteArray encodedFragment
Definition: qurl.cpp:368
int port
Definition: qurl.cpp:370
QString userName
Definition: qurl.cpp:357
char valueDelimiter
Definition: qurl.cpp:378
bool isValid
Definition: qurl.cpp:375
char pairDelimiter
Definition: qurl.cpp:379
void clear()
Clears the contents of the byte array and makes it empty.

◆ createErrorString()

QString QUrlPrivate::createErrorString ( )

Definition at line 4164 of file qurl.cpp.

Referenced by QUrl::errorString().

4165 {
4166  if (isValid && isHostValid)
4167  return QString();
4168 
4172 
4173  if (errorInfo._source) {
4175  if (position > 0) {
4176  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ": error at position "));
4177  errorString += QString::number(position);
4178  } else {
4179  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ": "));
4180  errorString += QLatin1String(errorInfo._source);
4181  }
4182  }
4183 
4184  if (errorInfo._expected) {
4185  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ": expected \'"));
4186  errorString += QLatin1Char(errorInfo._expected);
4187  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, "\'"));
4188  } else {
4189  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ": "));
4190  if (isHostValid)
4191  errorString += QLatin1String(errorInfo._message);
4192  else
4193  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, "invalid hostname"));
4194  }
4195  if (errorInfo._found) {
4196  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ", but found \'"));
4197  errorString += QLatin1Char(errorInfo._found);
4198  errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, "\'"));
4199  }
4200  return errorString;
4201 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
const char * _message
Definition: qurl.cpp:285
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
char _expected
Definition: qurl.cpp:286
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
char _found
Definition: qurl.cpp:287
QByteArray encodedOriginal
Definition: qurl.cpp:364
const char * _source
Definition: qurl.cpp:284
bool isValid
Definition: qurl.cpp:375
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isHostValid
Definition: qurl.cpp:376
QUrlErrorInfo errorInfo
Definition: qurl.cpp:399

◆ ensureEncodedParts()

void QUrlPrivate::ensureEncodedParts ( ) const

Definition at line 3550 of file qurl.cpp.

Referenced by QUrl::encodedFragment(), QUrl::encodedPassword(), QUrl::encodedPath(), QUrl::encodedUserName(), mergePaths(), normalized(), QUrl::resolved(), and toEncoded().

3551 {
3552  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
3553 
3554  if (encodedUserName.isNull())
3555  // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
3557  if (encodedPassword.isNull())
3558  // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
3560  if (encodedPath.isNull())
3561  // pchar = unreserved / pct-encoded / sub-delims / ":" / "@" ... also "/"
3563  if (encodedFragment.isNull())
3564  // fragment = *( pchar / "/" / "?" )
3566 }
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
static QByteArray toPercentEncodingHelper(const QString &s, const char *exclude, const char *include=0)
Definition: qurl.cpp:233
static const char fragmentExcludeChars[]
Definition: qurl.cpp:3548
QByteArray encodedUserName
Definition: qurl.cpp:365
QString fragment
Definition: qurl.cpp:362
static const char passwordExcludeChars[]
Definition: qurl.cpp:3545
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
static const char pathExcludeChars[]
Definition: qurl.cpp:3546
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
static const char userNameExcludeChars[]
Definition: qurl.cpp:3544
QByteArray encodedFragment
Definition: qurl.cpp:368
QString userName
Definition: qurl.cpp:357

◆ fragmentImpl()

QString QUrlPrivate::fragmentImpl ( ) const

Definition at line 5696 of file qurl.cpp.

Referenced by QUrl::fragment(), QUrl::resolved(), and QUrl::toString().

5697 {
5698  if (fragment.isNull() && !encodedFragment.isNull()) {
5699  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
5701  }
5702  return fragment;
5703 }
static QString fromPercentEncodingHelper(const QByteArray &ba)
Definition: qurl.cpp:242
QString fragment
Definition: qurl.cpp:362
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QByteArray encodedFragment
Definition: qurl.cpp:368

◆ mergePaths()

QByteArray QUrlPrivate::mergePaths ( const QByteArray relativePath) const

Definition at line 3700 of file qurl.cpp.

Referenced by QUrl::resolved().

3701 {
3702  // Caller must lock mutex first
3703 
3704  if (encodedPath.isNull())
3706 
3707  // If the base URI has a defined authority component and an empty
3708  // path, then return a string consisting of "/" concatenated with
3709  // the reference's path; otherwise,
3710  if (!authority().isEmpty() && encodedPath.isEmpty())
3711  return '/' + relativePath;
3712 
3713  // Return a string consisting of the reference's path component
3714  // appended to all but the last segment of the base URI's path
3715  // (i.e., excluding any characters after the right-most "/" in the
3716  // base URI path, or excluding the entire base URI path if it does
3717  // not contain any "/" characters).
3718  QByteArray newPath;
3719  if (!encodedPath.contains('/'))
3720  newPath = relativePath;
3721  else
3722  newPath = encodedPath.left(encodedPath.lastIndexOf('/') + 1) + relativePath;
3723 
3724  return newPath;
3725 }
QByteArray encodedPath
Definition: qurl.cpp:367
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int lastIndexOf(char c, int from=-1) const
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QString authority(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3568
void ensureEncodedParts() const
Definition: qurl.cpp:3550
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
Definition: qbytearray.h:525

◆ normalized()

const QByteArray & QUrlPrivate::normalized ( ) const

Definition at line 4082 of file qurl.cpp.

Referenced by QUrl::operator<(), QUrl::operator==(), and toEncoded().

4083 {
4084  // Caller must lock mutex first
4086  return encodedNormalized;
4087 
4088  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
4090 
4091  QUrlPrivate tmp = *this;
4092  tmp.scheme = tmp.scheme.toLower();
4093  tmp.host = tmp.canonicalHost();
4094 
4095  // ensure the encoded and normalized parts of the URL
4096  tmp.ensureEncodedParts();
4097  if (tmp.encodedUserName.contains('%'))
4099  if (tmp.encodedPassword.contains('%'))
4101  if (tmp.encodedFragment.contains('%'))
4103 
4104  if (tmp.encodedPath.contains('%')) {
4105  // the path is a bit special:
4106  // the slashes shouldn't be encoded or decoded.
4107  // They should remain exactly like they are right now
4108  //
4109  // treat the path as a slash-separated sequence of pchar
4110  QByteArray result;
4111  result.reserve(tmp.encodedPath.length());
4112  if (tmp.encodedPath.startsWith('/'))
4113  result.append('/');
4114 
4115  const char *data = tmp.encodedPath.constData();
4116  int lastSlash = 0;
4117  int nextSlash;
4118  do {
4119  ++lastSlash;
4120  nextSlash = tmp.encodedPath.indexOf('/', lastSlash);
4121  int len;
4122  if (nextSlash == -1)
4123  len = tmp.encodedPath.length() - lastSlash;
4124  else
4125  len = nextSlash - lastSlash;
4126 
4127  if (memchr(data + lastSlash, '%', len)) {
4128  // there's at least one percent before the next slash
4129  QByteArray block = QByteArray(data + lastSlash, len);
4131  result.append(block);
4132  } else {
4133  // no percents in this path segment, append wholesale
4134  result.append(data + lastSlash, len);
4135  }
4136 
4137  // append the slash too, if it's there
4138  if (nextSlash != -1)
4139  result.append('/');
4140 
4141  lastSlash = nextSlash;
4142  } while (lastSlash != -1);
4143 
4144  tmp.encodedPath = result;
4145  }
4146 
4147  if (!tmp.scheme.isEmpty()) // relative test
4149 
4150  int qLen = tmp.query.length();
4151  for (int i = 0; i < qLen; i++) {
4152  if (qLen - i > 2 && tmp.query.at(i) == '%') {
4153  ++i;
4154  tmp.query[i] = qToLower(tmp.query.at(i));
4155  ++i;
4156  tmp.query[i] = qToLower(tmp.query.at(i));
4157  }
4158  }
4159  encodedNormalized = tmp.toEncoded();
4160 
4161  return encodedNormalized;
4162 }
QByteArray encodedPath
Definition: qurl.cpp:367
static const char fragmentExcludeChars[]
Definition: qurl.cpp:3548
QByteArray encodedUserName
Definition: qurl.cpp:365
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray encodedNormalized
Definition: qurl.cpp:396
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
#define QURL_SETFLAG(a, b)
Definition: qurl.cpp:276
static const char passwordExcludeChars[]
Definition: qurl.cpp:3545
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static void removeDotsFromPath(QByteArray *path)
Definition: qurl.cpp:3746
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
static const char pathExcludeChars[]
Definition: qurl.cpp:3546
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static const char * data(const QByteArray &arr)
QByteArray toEncoded(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3996
QByteArray query
Definition: qurl.cpp:361
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
static const char userNameExcludeChars[]
Definition: qurl.cpp:3544
void q_normalizePercentEncoding(QByteArray *ba, const char *exclude)
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QString scheme
Definition: qurl.cpp:356
QString host
Definition: qurl.cpp:359
QString canonicalHost() const
Definition: qurl.cpp:3479
QByteArray encodedFragment
Definition: qurl.cpp:368
void ensureEncodedParts() const
Definition: qurl.cpp:3550
#define qToLower(ch)
Definition: qurl.cpp:4080
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
Definition: qbytearray.h:525

◆ parse()

void QUrlPrivate::parse ( ParseOptions  parseOptions = ParseAndSet) const

Definition at line 3852 of file qurl.cpp.

Referenced by QUrl::addEncodedQueryItem(), QUrl::addQueryItem(), QUrl::allEncodedQueryItemValues(), QUrl::allQueryItemValues(), QUrl::authority(), QUrl::encodedFragment(), QUrl::encodedPassword(), QUrl::encodedPath(), QUrl::encodedQuery(), QUrl::encodedQueryItems(), QUrl::encodedQueryItemValue(), QUrl::encodedUserName(), QUrl::fragment(), QUrl::hasEncodedQueryItem(), QUrl::hasFragment(), QUrl::hasQuery(), QUrl::host(), QUrl::isLocalFile(), QUrl::isParentOf(), QUrl::isRelative(), QUrl::isValid(), QUrl::operator<(), QUrl::operator==(), QUrl::password(), QUrl::path(), QUrl::port(), QUrl::queryItems(), QUrl::removeAllEncodedQueryItems(), QUrl::removeEncodedQueryItem(), QUrl::resolved(), QUrl::scheme(), QUrl::setAuthority(), QUrl::setEncodedFragment(), QUrl::setEncodedPassword(), QUrl::setEncodedPath(), QUrl::setEncodedQuery(), QUrl::setEncodedQueryItems(), QUrl::setEncodedUserName(), QUrl::setFragment(), QUrl::setHost(), QUrl::setPassword(), QUrl::setPath(), QUrl::setPort(), QUrl::setQueryItems(), QUrl::setScheme(), QUrl::setUserInfo(), QUrl::setUserName(), toEncoded(), QUrl::toString(), QUrl::userInfo(), QUrl::userName(), and validate().

3853 {
3854  // Caller must lock mutex first
3855  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
3856  that->errorInfo.setParams(0, 0, 0, 0);
3857  if (encodedOriginal.isEmpty()) {
3858  that->isValid = false;
3859  that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "empty"),
3860  0, 0);
3862  return;
3863  }
3864 
3865 
3866  QUrlParseData parseData;
3867  memset(&parseData, 0, sizeof(parseData));
3868  parseData.userInfoDelimIndex = -1;
3869  parseData.port = -1;
3870 
3871  const char *pptr = (char *) encodedOriginal.constData();
3872  const char **ptr = &pptr;
3873 
3874 #if defined (QURL_DEBUG)
3875  qDebug("QUrlPrivate::parse(), parsing \"%s\"", pptr);
3876 #endif
3877 
3878  // optional scheme
3879  bool isSchemeValid = _scheme(ptr, &parseData);
3880 
3881  if (isSchemeValid == false) {
3882  that->isValid = false;
3883  char ch = *((*ptr)++);
3884  that->errorInfo.setParams(*ptr, QT_TRANSLATE_NOOP(QUrl, "unexpected URL scheme"),
3885  0, ch);
3887 #if defined (QURL_DEBUG)
3888  qDebug("QUrlPrivate::parse(), unrecognized: %c%s", ch, *ptr);
3889 #endif
3890  return;
3891  }
3892 
3893  // hierpart
3894  _hierPart(ptr, &parseData);
3895 
3896  // optional query
3897  char ch = *((*ptr)++);
3898  if (ch == '?') {
3899  that->hasQuery = true;
3900  _query(ptr, &parseData);
3901  ch = *((*ptr)++);
3902  }
3903 
3904  // optional fragment
3905  if (ch == '#') {
3906  that->hasFragment = true;
3907  _fragment(ptr, &parseData);
3908  } else if (ch != '\0') {
3909  that->isValid = false;
3910  that->errorInfo.setParams(*ptr, QT_TRANSLATE_NOOP(QUrl, "expected end of URL"),
3911  0, ch);
3913 #if defined (QURL_DEBUG)
3914  qDebug("QUrlPrivate::parse(), unrecognized: %c%s", ch, *ptr);
3915 #endif
3916  return;
3917  }
3918 
3919  // when doing lazy validation, this function is called after
3920  // encodedOriginal has been constructed from the individual parts,
3921  // only to see if the constructed URL can be parsed. in that case,
3922  // parse() is called in ParseOnly mode; we don't want to set all
3923  // the members over again.
3924  if (parseOptions == ParseAndSet) {
3926 
3927  if (parseData.scheme) {
3928  QByteArray s(parseData.scheme, parseData.schemeLength);
3929  that->scheme = fromPercentEncodingMutable(&s);
3930  }
3931 
3932  that->setEncodedUserInfo(&parseData);
3933 
3934  QByteArray h(parseData.host, parseData.hostLength);
3935  that->host = fromPercentEncodingMutable(&h);
3936  that->port = uint(parseData.port) <= 0xffffU ? parseData.port : -1;
3937 
3938  that->path.clear();
3939  that->encodedPath = QByteArray(parseData.path, parseData.pathLength);
3940 
3941  if (that->hasQuery)
3942  that->query = QByteArray(parseData.query, parseData.queryLength);
3943  else
3944  that->query.clear();
3945 
3946  that->fragment.clear();
3947  if (that->hasFragment) {
3948  that->encodedFragment = QByteArray(parseData.fragment, parseData.fragmentLength);
3949  } else {
3950  that->encodedFragment.clear();
3951  }
3952  }
3953 
3954  that->isValid = true;
3955  QURL_SETFLAG(that->stateFlags, Parsed);
3956 
3957 #if defined (QURL_DEBUG)
3958  qDebug("QUrl::setUrl(), scheme = %s", that->scheme.toLatin1().constData());
3959  qDebug("QUrl::setUrl(), userInfo = %s", that->userInfo.toLatin1().constData());
3960  qDebug("QUrl::setUrl(), host = %s", that->host.toLatin1().constData());
3961  qDebug("QUrl::setUrl(), port = %i", that->port);
3962  qDebug("QUrl::setUrl(), path = %s", fromPercentEncodingHelper(__path).toLatin1().constData());
3963  qDebug("QUrl::setUrl(), query = %s", __query.constData());
3964  qDebug("QUrl::setUrl(), fragment = %s", fromPercentEncodingHelper(__fragment).toLatin1().constData());
3965 #endif
3966 }
int fragmentLength
Definition: qurl.cpp:316
void setParams(const char *source, const char *message, char expected, char found)
Definition: qurl.cpp:289
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
static void QT_FASTCALL _query(const char **ptr, QUrlParseData *parseData)
Definition: qurl.cpp:972
bool hasFragment
Definition: qurl.cpp:374
const char * path
Definition: qurl.cpp:311
static QString fromPercentEncodingHelper(const QByteArray &ba)
Definition: qurl.cpp:242
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
#define QURL_SETFLAG(a, b)
Definition: qurl.cpp:276
QString fragment
Definition: qurl.cpp:362
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
int queryLength
Definition: qurl.cpp:314
int stateFlags
Definition: qurl.cpp:387
QString userInfo(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3673
Q_CORE_EXPORT void qDebug(const char *,...)
static void QT_FASTCALL _fragment(const char **ptr, QUrlParseData *parseData)
Definition: qurl.cpp:988
const char * scheme
Definition: qurl.cpp:300
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
static QString fromPercentEncodingMutable(QByteArray *ba)
Definition: qurl.cpp:251
static bool QT_FASTCALL _scheme(const char **ptr, QUrlParseData *parseData)
Definition: qurl.cpp:483
unsigned int uint
Definition: qglobal.h:996
int userInfoDelimIndex
Definition: qurl.cpp:304
const char * fragment
Definition: qurl.cpp:315
const T * ptr(const T &t)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QByteArray query
Definition: qurl.cpp:361
const char * host
Definition: qurl.cpp:307
int schemeLength
Definition: qurl.cpp:301
int pathLength
Definition: qurl.cpp:312
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool hasQuery
Definition: qurl.cpp:373
QByteArray encodedOriginal
Definition: qurl.cpp:364
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static void QT_FASTCALL _hierPart(const char **ptr, QUrlParseData *parseData)
Definition: qurl.cpp:951
QString scheme
Definition: qurl.cpp:356
QString host
Definition: qurl.cpp:359
int hostLength
Definition: qurl.cpp:308
QByteArray encodedFragment
Definition: qurl.cpp:368
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void setEncodedUserInfo(const QUrlParseData *parseData)
Definition: qurl.cpp:3656
int port
Definition: qurl.cpp:370
const char * query
Definition: qurl.cpp:313
bool isValid
Definition: qurl.cpp:375
void clear()
Clears the contents of the byte array and makes it empty.
QUrlErrorInfo errorInfo
Definition: qurl.cpp:399

◆ queryItem()

void QUrlPrivate::queryItem ( int  pos,
int *  value,
int *  end 
)

Definition at line 3727 of file qurl.cpp.

Referenced by QUrl::allEncodedQueryItemValues(), QUrl::allQueryItemValues(), QUrl::encodedQueryItems(), QUrl::encodedQueryItemValue(), QUrl::hasEncodedQueryItem(), QUrl::queryItems(), QUrl::removeAllEncodedQueryItems(), and QUrl::removeEncodedQueryItem().

3728 {
3729  *end = query.indexOf(pairDelimiter, pos);
3730  if (*end == -1)
3731  *end = query.size();
3732  *value = pos;
3733  while (*value < *end) {
3734  if (query[*value] == valueDelimiter)
3735  break;
3736  ++*value;
3737  }
3738 }
QByteArray query
Definition: qurl.cpp:361
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
char valueDelimiter
Definition: qurl.cpp:378
static const KeyPair *const end
char pairDelimiter
Definition: qurl.cpp:379

◆ setAuthority()

void QUrlPrivate::setAuthority ( const QString auth)

Definition at line 3585 of file qurl.cpp.

Referenced by QUrl::setAuthority().

3586 {
3587  isHostValid = true;
3588  if (auth.isEmpty()) {
3589  setUserInfo(QString());
3590  if (auth.isNull())
3591  host.clear();
3592  else
3593  host = QLatin1String("");
3594  port = -1;
3595  return;
3596  }
3597 
3598  // find the port section of the authority by searching from the
3599  // end towards the beginning for numbers until a ':' is reached.
3600  int portIndex = auth.length() - 1;
3601  if (portIndex == 0) {
3602  portIndex = -1;
3603  } else {
3604  short c = auth.at(portIndex--).unicode();
3605  if (c < '0' || c > '9') {
3606  portIndex = -1;
3607  } else while (portIndex >= 0) {
3608  c = auth.at(portIndex).unicode();
3609  if (c == ':') {
3610  break;
3611  } else if (c == '.') {
3612  portIndex = -1;
3613  break;
3614  }
3615  --portIndex;
3616  }
3617  }
3618 
3619  if (portIndex != -1) {
3620  port = 0;
3621  for (int i = portIndex + 1; i < auth.length(); ++i)
3622  port = (port * 10) + (auth.at(i).unicode() - '0');
3623  } else {
3624  port = -1;
3625  }
3626 
3627  int userInfoIndex = auth.indexOf(QLatin1Char('@'));
3628  if (userInfoIndex != -1 && (portIndex == -1 || userInfoIndex < portIndex))
3629  setUserInfo(auth.left(userInfoIndex));
3630 
3631  int hostIndex = 0;
3632  if (userInfoIndex != -1)
3633  hostIndex = userInfoIndex + 1;
3634  int hostLength = auth.length() - hostIndex;
3635  if (portIndex != -1)
3636  hostLength -= (auth.length() - portIndex);
3637 
3638  host = auth.mid(hostIndex, hostLength).trimmed();
3639 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setUserInfo(const QString &userInfo)
Definition: qurl.cpp:3641
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString host
Definition: qurl.cpp:359
int port
Definition: qurl.cpp:370
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isHostValid
Definition: qurl.cpp:376

◆ setEncodedAuthority()

void QUrlPrivate::setEncodedAuthority ( const QByteArray authority)

◆ setEncodedUrl()

void QUrlPrivate::setEncodedUrl ( const QByteArray encodedUrl,
QUrl::ParsingMode  parsingMode 
)

Definition at line 4458 of file qurl.cpp.

Referenced by QUrl::setEncodedUrl(), and QUrl::setUrl().

4459 {
4460  // Caller must lock mutex first
4461  QByteArray tmp = encodedUrl;
4462  if ((this->parsingMode = parsingMode) == QUrl::TolerantMode) {
4463  // Replace stray % with %25
4464  QByteArray copy = tmp;
4465  for (int i = 0, j = 0; i < copy.size(); ++i, ++j) {
4466  if (copy.at(i) == '%') {
4467  if (i + 2 >= copy.size() || !isHex(copy.at(i + 1)) || !isHex(copy.at(i + 2))) {
4468  tmp.replace(j, 1, "%25");
4469  j += 2;
4470  }
4471  }
4472  }
4473 
4474  // Find the host part
4475  int hostStart = tmp.indexOf("//");
4476  int hostEnd = -1;
4477  if (hostStart != -1) {
4478  // Has host part, find delimiter
4479  hostStart += 2; // skip "//"
4480  hostEnd = tmp.indexOf('/', hostStart);
4481  if (hostEnd == -1)
4482  hostEnd = tmp.indexOf('#', hostStart);
4483  if (hostEnd == -1)
4484  hostEnd = tmp.indexOf('?');
4485  if (hostEnd == -1)
4486  hostEnd = tmp.length() - 1;
4487  }
4488 
4489  // Reserved and unreserved characters are fine
4490 // unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
4491 // reserved = gen-delims / sub-delims
4492 // gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
4493 // sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
4494 // / "*" / "+" / "," / ";" / "="
4495  // Replace everything else with percent encoding
4496  static const char doEncode[] = " \"<>[\\]^`{|}";
4497  static const char doEncodeHost[] = " \"<>\\^`{|}";
4498  for (int i = 0; i < tmp.size(); ++i) {
4499  quint8 c = quint8(tmp.at(i));
4500  if (c < 32 || c > 127 ||
4501  strchr(hostStart <= i && i <= hostEnd ? doEncodeHost : doEncode, c)) {
4502  char buf[4];
4503  buf[0] = '%';
4504  buf[1] = toHex(c >> 4);
4505  buf[2] = toHex(c & 0xf);
4506  buf[3] = '\0';
4507  tmp.replace(i, 1, buf);
4508  i += 2;
4509  }
4510  }
4511  }
4512 
4513  encodedOriginal = tmp;
4514 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
unsigned char quint8
Definition: qglobal.h:934
static char toHex(quint8 c)
Definition: qurl.cpp:4440
QUrl::ParsingMode parsingMode
Definition: qurl.cpp:371
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int length() const
Same as size().
Definition: qbytearray.h:356
QByteArray encodedOriginal
Definition: qurl.cpp:364
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray & replace(int index, int len, const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static bool isHex(char c)
Definition: qurl.cpp:4434
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413

◆ setEncodedUserInfo()

void QUrlPrivate::setEncodedUserInfo ( const QUrlParseData parseData)

Definition at line 3656 of file qurl.cpp.

Referenced by parse().

3657 {
3658  userName.clear();
3659  password.clear();
3660  if (!parseData->userInfoLength) {
3663  } else if (parseData->userInfoDelimIndex == -1) {
3664  encodedUserName = QByteArray(parseData->userInfo, parseData->userInfoLength);
3666  } else {
3667  encodedUserName = QByteArray(parseData->userInfo, parseData->userInfoDelimIndex);
3668  encodedPassword = QByteArray(parseData->userInfo + parseData->userInfoDelimIndex + 1,
3669  parseData->userInfoLength - parseData->userInfoDelimIndex - 1);
3670  }
3671 }
QByteArray encodedUserName
Definition: qurl.cpp:365
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * userInfo
Definition: qurl.cpp:303
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
int userInfoLength
Definition: qurl.cpp:305
int userInfoDelimIndex
Definition: qurl.cpp:304
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString userName
Definition: qurl.cpp:357
void clear()
Clears the contents of the byte array and makes it empty.

◆ setUrl()

bool QUrlPrivate::setUrl ( const QString url)

◆ setUserInfo()

void QUrlPrivate::setUserInfo ( const QString userInfo)

Definition at line 3641 of file qurl.cpp.

Referenced by setAuthority(), and QUrl::setUserInfo().

3642 {
3645 
3646  int delimIndex = userInfo.indexOf(QLatin1Char(':'));
3647  if (delimIndex == -1) {
3648  userName = userInfo;
3649  password.clear();
3650  return;
3651  }
3652  userName = userInfo.left(delimIndex);
3653  password = userInfo.right(userInfo.length() - delimIndex - 1);
3654 }
QByteArray encodedUserName
Definition: qurl.cpp:365
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
QString userInfo(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3673
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
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
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString userName
Definition: qurl.cpp:357
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void clear()
Clears the contents of the byte array and makes it empty.

◆ toEncoded()

QByteArray QUrlPrivate::toEncoded ( QUrl::FormattingOptions  options = QUrl::None) const

Definition at line 3996 of file qurl.cpp.

Referenced by normalized(), QUrl::resolved(), QUrl::toEncoded(), and validate().

3997 {
3998  // Caller must lock mutex first
3999  if (!QURL_HASFLAG(stateFlags, Parsed)) parse();
4000  else ensureEncodedParts();
4001 
4002  if (options==0x100) // private - see qHash(QUrl)
4003  return normalized();
4004 
4005  QByteArray url;
4006 
4007  if (!(options & QUrl::RemoveScheme) && !scheme.isEmpty()) {
4008  url += scheme.toLatin1();
4009  url += ':';
4010  }
4011  QString savedHost = host; // pre-validation, may be invalid!
4012  QString auth = authority();
4013  bool doFileScheme = scheme == QLatin1String("file") && encodedPath.startsWith('/');
4014  if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority && (!auth.isNull() || doFileScheme || !savedHost.isEmpty())) {
4015  if (doFileScheme && !encodedPath.startsWith('/'))
4016  url += '/';
4017  url += "//";
4018 
4019  if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) {
4020  bool hasUserOrPass = false;
4021  if (!userName.isEmpty()) {
4022  url += encodedUserName;
4023  hasUserOrPass = true;
4024  }
4025  if (!(options & QUrl::RemovePassword) && !password.isEmpty()) {
4026  url += ':';
4027  url += encodedPassword;
4028  hasUserOrPass = true;
4029  }
4030  if (hasUserOrPass)
4031  url += '@';
4032  }
4033 
4034  if (host.startsWith(QLatin1Char('['))) {
4035  url += host.toLatin1();
4036  } else if (host.contains(QLatin1Char(':'))) {
4037  url += '[';
4038  url += host.toLatin1();
4039  url += ']';
4040  } else if (host.isEmpty() && !savedHost.isEmpty()) {
4041  // this case is only possible with an invalid URL
4042  // it's here only so that we can keep the original, invalid hostname
4043  // in encodedOriginal.
4044  // QUrl::isValid() will return false, so toEncoded() can be anything (it's not valid)
4045  url += savedHost.toUtf8();
4046  } else {
4047  url += QUrl::toAce(host);
4048  }
4049  if (!(options & QUrl::RemovePort) && port != -1) {
4050  url += ':';
4051  url += QString::number(port).toAscii();
4052  }
4053  }
4054 
4055  if (!(options & QUrl::RemovePath)) {
4056  // check if we need to insert a slash
4057  if (!encodedPath.isEmpty() && !auth.isEmpty()) {
4058  if (!encodedPath.startsWith('/'))
4059  url += '/';
4060  }
4061  url += encodedPath;
4062 
4063  // check if we need to remove trailing slashes
4064  while ((options & QUrl::StripTrailingSlash) && url.endsWith('/'))
4065  url.chop(1);
4066  }
4067 
4068  if (!(options & QUrl::RemoveQuery) && hasQuery) {
4069  url += '?';
4070  url += query;
4071  }
4072  if (!(options & QUrl::RemoveFragment) && hasFragment) {
4073  url += '#';
4074  url += encodedFragment;
4075  }
4076 
4077  return url;
4078 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
void chop(int n)
Removes n bytes from the end of the byte array.
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QByteArray encodedPath
Definition: qurl.cpp:367
QByteArray encodedUserName
Definition: qurl.cpp:365
bool hasFragment
Definition: qurl.cpp:374
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString password
Definition: qurl.cpp:358
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
Definition: qurl.cpp:6158
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QByteArray query
Definition: qurl.cpp:361
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
bool hasQuery
Definition: qurl.cpp:373
const QByteArray & normalized() const
Definition: qurl.cpp:4082
QString scheme
Definition: qurl.cpp:356
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
QString authority(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3568
QString host
Definition: qurl.cpp:359
QByteArray encodedFragment
Definition: qurl.cpp:368
void ensureEncodedParts() const
Definition: qurl.cpp:3550
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int port
Definition: qurl.cpp:370
QString userName
Definition: qurl.cpp:357
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ userInfo()

QString QUrlPrivate::userInfo ( QUrl::FormattingOptions  options = QUrl::None) const

Definition at line 3673 of file qurl.cpp.

Referenced by authority(), parse(), QUrl::password(), setUserInfo(), QUrl::userInfo(), and QUrl::userName().

3674 {
3675  if ((options & QUrl::RemoveUserInfo) == QUrl::RemoveUserInfo)
3676  return QString();
3677 
3678  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
3679  if (userName.isNull())
3681  if (password.isNull())
3683 
3684  QString tmp = userName;
3685 
3686  if (!(options & QUrl::RemovePassword) && !password.isEmpty()) {
3687  tmp += QLatin1Char(':');
3688  tmp += password;
3689  }
3690 
3691  return tmp;
3692 }
QByteArray encodedUserName
Definition: qurl.cpp:365
static QString fromPercentEncodingHelper(const QByteArray &ba)
Definition: qurl.cpp:242
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString userName
Definition: qurl.cpp:357
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ validate()

void QUrlPrivate::validate ( ) const

Definition at line 3818 of file qurl.cpp.

Referenced by QUrl::isValid(), and QUrl::port().

3819 {
3820  // Caller must lock mutex first
3821  QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
3822  that->encodedOriginal = that->toEncoded(); // may detach
3823  parse(ParseOnly);
3824 
3826 
3827  if (!isValid)
3828  return;
3829 
3830  QString auth = authority(); // causes the non-encoded forms to be valid
3831 
3832  // authority() calls canonicalHost() which sets this
3833  if (!isHostValid)
3834  return;
3835 
3836  if (scheme == QLatin1String("mailto")) {
3837  if (!host.isEmpty() || port != -1 || !userName.isEmpty() || !password.isEmpty()) {
3838  that->isValid = false;
3839  that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "expected empty host, username,"
3840  "port and password"),
3841  0, 0);
3842  }
3843  } else if (scheme == QLatin1String("ftp") || scheme == QLatin1String("http")) {
3844  if (host.isEmpty() && !(path.isEmpty() && encodedPath.isEmpty())) {
3845  that->isValid = false;
3846  that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "the host is empty, but not the path"),
3847  0, 0);
3848  }
3849  }
3850 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
void setParams(const char *source, const char *message, char expected, char found)
Definition: qurl.cpp:289
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define QURL_SETFLAG(a, b)
Definition: qurl.cpp:276
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString password
Definition: qurl.cpp:358
int stateFlags
Definition: qurl.cpp:387
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toEncoded(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3996
QByteArray encodedOriginal
Definition: qurl.cpp:364
QString scheme
Definition: qurl.cpp:356
QString authority(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3568
QString host
Definition: qurl.cpp:359
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int port
Definition: qurl.cpp:370
QString userName
Definition: qurl.cpp:357
bool isValid
Definition: qurl.cpp:375
bool isHostValid
Definition: qurl.cpp:376
QUrlErrorInfo errorInfo
Definition: qurl.cpp:399

Properties

◆ encodedFragment

QByteArray QUrlPrivate::encodedFragment

◆ encodedNormalized

QByteArray QUrlPrivate::encodedNormalized
mutable

Definition at line 396 of file qurl.cpp.

Referenced by clear(), and normalized().

◆ encodedOriginal

QByteArray QUrlPrivate::encodedOriginal

Definition at line 364 of file qurl.cpp.

Referenced by clear(), createErrorString(), QUrl::isEmpty(), parse(), and validate().

◆ encodedPassword

QByteArray QUrlPrivate::encodedPassword

◆ encodedPath

QByteArray QUrlPrivate::encodedPath

◆ encodedUserName

QByteArray QUrlPrivate::encodedUserName

◆ errorInfo

QUrlErrorInfo QUrlPrivate::errorInfo
mutable

Definition at line 399 of file qurl.cpp.

Referenced by createErrorString(), parse(), and validate().

◆ fragment

QString QUrlPrivate::fragment

◆ hasFragment

bool QUrlPrivate::hasFragment

◆ hasQuery

bool QUrlPrivate::hasQuery

◆ host

QString QUrlPrivate::host

◆ isHostValid

bool QUrlPrivate::isHostValid

◆ isValid

bool QUrlPrivate::isValid

Definition at line 375 of file qurl.cpp.

Referenced by clear(), createErrorString(), QUrl::isValid(), parse(), and validate().

◆ mutex

QMutex QUrlPrivate::mutex
mutable

◆ pairDelimiter

char QUrlPrivate::pairDelimiter

◆ parsingMode

QUrl::ParsingMode QUrlPrivate::parsingMode

Definition at line 371 of file qurl.cpp.

Referenced by QUrl::QUrl().

◆ password

QString QUrlPrivate::password

◆ path

QString QUrlPrivate::path

◆ port

int QUrlPrivate::port

◆ query

QByteArray QUrlPrivate::query

◆ ref

QAtomicInt QUrlPrivate::ref

◆ scheme

QString QUrlPrivate::scheme

◆ stateFlags

int QUrlPrivate::stateFlags

◆ userName

QString QUrlPrivate::userName

◆ valueDelimiter

char QUrlPrivate::valueDelimiter

The documentation for this class was generated from the following file: