⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qurl.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//*!    \class QUrl    \brief The QUrl class provides a convenient interface for working    with URLs.    \reentrant    \ingroup io    \ingroup misc    \ingroup shared    \mainclass    It can parse and construct URLs in both encoded and unencoded    form. QUrl also has support for internationalized domain names    (IDNs).    The most common way to use QUrl is to initialize it via the    constructor by passing a QString. Otherwise, setUrl() and    setEncodedUrl() can also be used.    URLs can be represented in two forms: encoded or unencoded. The    unencoded representation is suitable for showing to users, but    the encoded representation is typically what you would send to    a web server. For example, the unencoded URL    "http://b\uuml\c{}hler.example.com" would be sent to the server as    "http://xn--bhler-kva.example.com/List%20of%20applicants.xml".    A URL can also be constructed piece by piece by calling    setScheme(), setUserName(), setPassword(), setHost(), setPort(),    setPath(), setEncodedQuery() and setFragment(). Some convenience    functions are also available: setAuthority() sets the user name,    password, host and port. setUserInfo() sets the user name and    password at once.    Call isValid() to check if the URL is valid. This can be done at    any point during the constructing of a URL.    Constructing a query is particularly convenient through the use    of setQueryItems(), addQueryItem() and removeQueryItem(). Use    setQueryDelimiters() to customize the delimiters used for    generating the query string.    For the convenience of generating encoded URL strings or query    strings, there are two static functions called    fromPercentEncoding() and toPercentEncoding() which deal with    percent encoding and decoding of QStrings.    Calling isRelative() will tell whether or not the URL is    relative. A relative URL can be resolved by passing it as argument    to resolved(), which returns an absolute URL. isParentOf() is used    for determining whether one URL is a parent of another.    fromLocalFile() constructs a QUrl by parsing a local    file path. toLocalFile() converts a URL to a local file path.    The human readable representation of the URL is fetched with    toString(). This representation is appropriate for displaying a    URL to a user in unencoded form. The encoded form however, as    returned by toEncoded(), is for internal use, passing to web    servers, mail clients and so on.    QUrl conforms to the URI specification from    \l{RFC 3986} (Uniform Resource Identifier: Generic Syntax), and includes scheme extensions from    \l{RFC 1738} (Uniform Resource Locators).    \sa QUrlInfo*//*!    \enum QUrl::ParsingMode    The parsing mode controls the way QUrl parses strings.    \value TolerantMode QUrl will try to correct some common errors in URLs.                        This mode is useful when processing URLs entered by                        users.    \value StrictMode Only valid URLs are accepted. This mode is useful for                      general URL validation.    In TolerantMode, the parser corrects the following invalid input:    \list    \o Spaces and "%20": If an encoded URL contains a space, this will be    replaced with "%20". If a decoded URL contains "%20", this will be    replaced with a single space before the URL is parsed.    \o Single "%" characters: Any occurrences of a percent character "%" not    followed by exactly two hexadecimal characters (e.g., "13% coverage.html")    will be replaced by "%25".    \o Non-US-ASCII characters: An encoded URL should only contain US-ASCII    characters. In TolerantMode, characters outside this range are    automatically percent-encoded.    \o Any occurrence of "[" and "]" following the host part of the    URL is percent-encoded.    \endlist*//*!    \enum QUrl::FormattingOption    The formatting options define how the URL is formatted when written out    as text.    \value None          The URL is left unchanged.    \value RemoveScheme  The scheme is removed from the URL.    \value RemovePassword  Any password in the URL is removed.    \value RemoveUserInfo  Any user information in the URL is removed.    \value RemovePort      Any specified port is removed from the URL.    \value RemoveAuthority    \value RemovePath   The URL's path is removed, leaving only the scheme,                        host address, and port (if present).    \value RemoveQuery  The query part of the URL (following a '?' character)                        is removed.    \value RemoveFragment    \value StripTrailingSlash  The trailing slash is removed if one is present.*/#include "qplatformdefs.h"#include "qurl.h"#include "private/qunicodetables_p.h"#include "qatomic.h"#include "qbytearray.h"#include "qlist.h"#ifndef QT_NO_REGEXP#include "qregexp.h"#endif#include "qstring.h"#include "qstringlist.h"#include "qstack.h"#include "qvarlengtharray.h"#include "qdebug.h"#if defined QT3_SUPPORT#include "qfileinfo.h"#endif// ### Qt 5: Consider accepting empty strings as valid. See task 144227.//#define QURL_DEBUG// implemented in qvsnprintf.cppQ_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);// needed by the punycode encoder/decoder#define Q_MAXINT ((uint)((uint)(-1)>>1))static const uint base = 36;static const uint tmin = 1;static const uint tmax = 26;static const uint skew = 38;static const uint damp = 700;static const uint initial_bias = 72;static const uint initial_n = 128;#define QURL_SETFLAG(a, b) { (a) |= (b); }#define QURL_UNSETFLAG(a, b) { (a) &= ~(b); }#define QURL_HASFLAG(a, b) (((a) & (b)) == (b))struct ErrorInfo {    inline ErrorInfo() : _source(0)    { }    char *_source;    QString _message;    QChar _expected;    QChar _found;    inline void setParams(char *source, const QString &message,                          const QChar &expected, const QChar &found)    {        _source = source;        _message = message;        _expected = expected;        _found = found;    }};class QUrlPrivate{public:    QUrlPrivate();    QUrlPrivate(const QUrlPrivate &other);    bool setUrl(const QString &url);    QString authority(QUrl::FormattingOptions options = QUrl::None) const;    void setAuthority(const QString &auth);    void setUserInfo(const QString &userInfo);    QString userInfo(QUrl::FormattingOptions options = QUrl::None) const;    QString mergePaths(const QString &relativePath) const;    static QString removeDotsFromPath(const QString &path);    enum ParseOptions {        ParseAndSet,        ParseOnly    };    void validate() const;    void parse(ParseOptions parseOptions = ParseAndSet) const;    void clear();    QByteArray toEncoded(QUrl::FormattingOptions options = QUrl::None) const;    QAtomic ref;    QString scheme;    QString userName;    QString password;    QString host;    int port;    QString path;    QByteArray query;    bool hasQuery;    QString fragment;    bool hasFragment;    QByteArray encodedOriginal;    bool isValid;    QUrl::ParsingMode parsingMode;    char valueDelimiter;    char pairDelimiter;    enum State {        Parsed = 0x1,        Validated = 0x2,        Normalized = 0x4    };    int stateFlags;    QByteArray encodedNormalized;    const QByteArray & normalized();    mutable ErrorInfo errorInfo;    QString createErrorString();};static bool QT_FASTCALL _char(char **ptr, char expected, ErrorInfo *errorInfo){    if (*((*ptr)) == expected) {        ++(*ptr);        return true;    }    errorInfo->setParams(*ptr, QLatin1String(""), QLatin1Char(expected), QLatin1Char(*((*ptr))));    return false;}static bool QT_FASTCALL _HEXDIG(char **ptr, char *dig, ErrorInfo *errorInfo){    char ch = **ptr;    if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {        *dig = ch;        ++(*ptr);        return true;    }    errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "expected hexdigit number (0-9, a-f, A-F)")),                         QLatin1Char('\0'), QLatin1Char(ch));    return false;}// pct-encoded = "%" HEXDIG HEXDIGstatic bool QT_FASTCALL _pctEncoded(char **ptr, char pct[], ErrorInfo *errorInfo){    char *ptrBackup = *ptr;    if (!_char(ptr, '%', errorInfo)) return false;    char hex1, hex2;    if (!_HEXDIG(ptr, &hex1, errorInfo)) { *ptr = ptrBackup; return false; }    if (!_HEXDIG(ptr, &hex2, errorInfo)) { *ptr = ptrBackup; return false; }    pct[0] = '%';    pct[1] = hex1;    pct[2] = hex2;    pct[3] = '\0';    return true;}#if 0// gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"static bool QT_FASTCALL _genDelims(char **ptr, char *c){    char ch = **ptr;    switch (ch) {    case ':': case '/': case '?': case '#':    case '[': case ']': case '@':        *c = ch;        ++(*ptr);        return true;    default:        return false;    }}#endif// sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"//             / "*" / "+" / "," / ";" / "="static bool QT_FASTCALL _subDelims(char **ptr, char *c, ErrorInfo *errorInfo){    char ch = **ptr;    switch (ch) {    case '!': case '$': case '&': case '\'':    case '(': case ')': case '*': case '+':    case ',': case ';': case '=':        *c = ch;        ++(*ptr);        return true;    default:        errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "expected sub-delimiter "))                             + QLatin1String("(\"!\", \"$\", \"&\", \"\'\", \"(\", \")\",")                             + QLatin1String("\"*\", \"+\", \",\", \";\", \"=\")"),                             QLatin1Char('\0'), QLatin1Char(ch));        return false;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -