Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:26:52

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // Copyright (C) 2016 Intel Corporation.
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 
0005 #ifndef QURL_H
0006 #define QURL_H
0007 
0008 #include <QtCore/qbytearray.h>
0009 #include <QtCore/qcompare.h>
0010 #include <QtCore/qobjectdefs.h>
0011 #include <QtCore/qstring.h>
0012 #include <QtCore/qlist.h>
0013 #include <QtCore/qglobal.h>
0014 
0015 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0016 Q_FORWARD_DECLARE_CF_TYPE(CFURL);
0017 Q_FORWARD_DECLARE_OBJC_CLASS(NSURL);
0018 #endif
0019 
0020 QT_BEGIN_NAMESPACE
0021 
0022 
0023 class QUrlQuery;
0024 class QUrlPrivate;
0025 class QDataStream;
0026 
0027 template <typename E1, typename E2>
0028 class QUrlTwoFlags
0029 {
0030     int i;
0031 public:
0032     constexpr inline QUrlTwoFlags() : i(0) {}
0033     constexpr inline QUrlTwoFlags(E1 f) : i(f) {}
0034     constexpr inline QUrlTwoFlags(E2 f) : i(f) {}
0035     constexpr inline QUrlTwoFlags(QFlag f) : i(f) {}
0036     constexpr inline QUrlTwoFlags(QFlags<E1> f) : i(f.operator typename QFlags<E1>::Int()) {}
0037     constexpr inline QUrlTwoFlags(QFlags<E2> f) : i(f.operator typename QFlags<E2>::Int()) {}
0038 
0039     inline QUrlTwoFlags &operator&=(int mask) { i &= mask; return *this; }
0040     inline QUrlTwoFlags &operator&=(uint mask) { i &= mask; return *this; }
0041     inline QUrlTwoFlags &operator&=(QFlags<E1> mask) { i &= mask.toInt(); return *this; }
0042     inline QUrlTwoFlags &operator&=(QFlags<E2> mask) { i &= mask.toInt(); return *this; }
0043     inline QUrlTwoFlags &operator|=(QUrlTwoFlags f) { i |= f.i; return *this; }
0044     inline QUrlTwoFlags &operator|=(E1 f) { i |= f; return *this; }
0045     inline QUrlTwoFlags &operator|=(E2 f) { i |= f; return *this; }
0046     inline QUrlTwoFlags &operator|=(QFlags<E1> mask) { i |= mask.toInt(); return *this; }
0047     inline QUrlTwoFlags &operator|=(QFlags<E2> mask) { i |= mask.toInt(); return *this; }
0048     inline QUrlTwoFlags &operator^=(QUrlTwoFlags f) { i ^= f.i; return *this; }
0049     inline QUrlTwoFlags &operator^=(E1 f) { i ^= f; return *this; }
0050     inline QUrlTwoFlags &operator^=(E2 f) { i ^= f; return *this; }
0051     inline QUrlTwoFlags &operator^=(QFlags<E1> mask) { i ^= mask.toInt(); return *this; }
0052     inline QUrlTwoFlags &operator^=(QFlags<E2> mask) { i ^= mask.toInt(); return *this; }
0053 
0054     constexpr inline operator QFlags<E1>() const { return QFlag(i); }
0055     constexpr inline operator QFlags<E2>() const { return QFlag(i); }
0056     constexpr inline operator int() const { return i; }
0057     constexpr inline bool operator!() const { return !i; }
0058 
0059     constexpr inline QUrlTwoFlags operator|(QUrlTwoFlags f) const
0060     { return QUrlTwoFlags(QFlag(i | f.i)); }
0061     constexpr inline QUrlTwoFlags operator|(E1 f) const
0062     { return QUrlTwoFlags(QFlag(i | f)); }
0063     constexpr inline QUrlTwoFlags operator|(E2 f) const
0064     { return QUrlTwoFlags(QFlag(i | f)); }
0065     constexpr inline QUrlTwoFlags operator^(QUrlTwoFlags f) const
0066     { return QUrlTwoFlags(QFlag(i ^ f.i)); }
0067     constexpr inline QUrlTwoFlags operator^(E1 f) const
0068     { return QUrlTwoFlags(QFlag(i ^ f)); }
0069     constexpr inline QUrlTwoFlags operator^(E2 f) const
0070     { return QUrlTwoFlags(QFlag(i ^ f)); }
0071     constexpr inline QUrlTwoFlags operator&(int mask) const
0072     { return QUrlTwoFlags(QFlag(i & mask)); }
0073     constexpr inline QUrlTwoFlags operator&(uint mask) const
0074     { return QUrlTwoFlags(QFlag(i & mask)); }
0075     constexpr inline QUrlTwoFlags operator&(E1 f) const
0076     { return QUrlTwoFlags(QFlag(i & f)); }
0077     constexpr inline QUrlTwoFlags operator&(E2 f) const
0078     { return QUrlTwoFlags(QFlag(i & f)); }
0079     constexpr inline QUrlTwoFlags operator~() const
0080     { return QUrlTwoFlags(QFlag(~i)); }
0081 
0082     constexpr inline bool testFlag(E1 f) const { return (i & f) == f && (f != 0 || i == int(f)); }
0083     constexpr inline bool testFlag(E2 f) const { return (i & f) == f && (f != 0 || i == int(f)); }
0084 };
0085 
0086 template<typename E1, typename E2>
0087 class QTypeInfo<QUrlTwoFlags<E1, E2> > : public QTypeInfoMerger<QUrlTwoFlags<E1, E2>, E1, E2> {};
0088 
0089 class QUrl;
0090 // qHash is a friend, but we can't use default arguments for friends (ยง8.3.6.4)
0091 Q_CORE_EXPORT size_t qHash(const QUrl &url, size_t seed = 0) noexcept;
0092 
0093 class Q_CORE_EXPORT QUrl
0094 {
0095 public:
0096     enum ParsingMode {
0097         TolerantMode,
0098         StrictMode,
0099         DecodedMode
0100     };
0101 
0102     // encoding / toString values
0103     enum UrlFormattingOption : unsigned int {
0104         None = 0x0,
0105         RemoveScheme = 0x1,
0106         RemovePassword = 0x2,
0107         RemoveUserInfo = RemovePassword | 0x4,
0108         RemovePort = 0x8,
0109         RemoveAuthority = RemoveUserInfo | RemovePort | 0x10,
0110         RemovePath = 0x20,
0111         RemoveQuery = 0x40,
0112         RemoveFragment = 0x80,
0113         // 0x100 was a private code in Qt 4, keep unused for a while
0114         PreferLocalFile = 0x200,
0115         StripTrailingSlash = 0x400,
0116         RemoveFilename = 0x800,
0117         NormalizePathSegments = 0x1000
0118     };
0119 
0120     enum ComponentFormattingOption : unsigned int {
0121         PrettyDecoded = 0x000000,
0122         EncodeSpaces = 0x100000,
0123         EncodeUnicode = 0x200000,
0124         EncodeDelimiters = 0x400000 | 0x800000,
0125         EncodeReserved = 0x1000000,
0126         DecodeReserved = 0x2000000,
0127         // 0x4000000 used to indicate full-decode mode
0128 
0129         FullyEncoded = EncodeSpaces | EncodeUnicode | EncodeDelimiters | EncodeReserved,
0130         FullyDecoded = FullyEncoded | DecodeReserved | 0x4000000
0131     };
0132     Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption)
0133 #ifdef Q_QDOC
0134 private:
0135     // We need to let qdoc think that FormattingOptions is a normal QFlags, but
0136     // it needs to be a QUrlTwoFlags for compiling default arguments of some functions.
0137     template<typename T> struct QFlags : QUrlTwoFlags<T, ComponentFormattingOption>
0138     { using QUrlTwoFlags<T, ComponentFormattingOption>::QUrlTwoFlags; };
0139 public:
0140     Q_DECLARE_FLAGS(FormattingOptions, UrlFormattingOption)
0141 #else
0142     typedef QUrlTwoFlags<UrlFormattingOption, ComponentFormattingOption> FormattingOptions;
0143 #endif
0144 
0145     QUrl();
0146     QUrl(const QUrl &copy) noexcept;
0147     QUrl &operator =(const QUrl &copy) noexcept;
0148 #ifdef QT_NO_URL_CAST_FROM_STRING
0149     explicit QUrl(const QString &url, ParsingMode mode = TolerantMode);
0150 #else
0151     QUrl(const QString &url, ParsingMode mode = TolerantMode);
0152     QUrl &operator=(const QString &url);
0153 #endif
0154     QUrl(QUrl &&other) noexcept : d(other.d)
0155     { other.d = nullptr; }
0156     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrl)
0157     ~QUrl();
0158 
0159     void swap(QUrl &other) noexcept { qt_ptr_swap(d, other.d); }
0160 
0161     void setUrl(const QString &url, ParsingMode mode = TolerantMode);
0162     QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
0163     QString toString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
0164     QString toDisplayString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
0165     [[nodiscard]] QUrl adjusted(FormattingOptions options) const;
0166 
0167     QByteArray toEncoded(FormattingOptions options = FullyEncoded) const;
0168 #if QT_CORE_REMOVED_SINCE(6, 7)
0169     static QUrl fromEncoded(const QByteArray &url, ParsingMode mode = TolerantMode);
0170 #endif
0171     static QUrl fromEncoded(QByteArrayView input, ParsingMode mode = TolerantMode);
0172 
0173     enum UserInputResolutionOption {
0174         DefaultResolution,
0175         AssumeLocalFile
0176     };
0177     Q_DECLARE_FLAGS(UserInputResolutionOptions, UserInputResolutionOption)
0178 
0179     static QUrl fromUserInput(const QString &userInput, const QString &workingDirectory = QString(),
0180                               UserInputResolutionOptions options = DefaultResolution);
0181 
0182     bool isValid() const;
0183     QString errorString() const;
0184 
0185     bool isEmpty() const;
0186     void clear();
0187 
0188     void setScheme(const QString &scheme);
0189     QString scheme() const;
0190 
0191     void setAuthority(const QString &authority, ParsingMode mode = TolerantMode);
0192     QString authority(ComponentFormattingOptions options = PrettyDecoded) const;
0193 
0194     void setUserInfo(const QString &userInfo, ParsingMode mode = TolerantMode);
0195     QString userInfo(ComponentFormattingOptions options = PrettyDecoded) const;
0196 
0197     void setUserName(const QString &userName, ParsingMode mode = DecodedMode);
0198     QString userName(ComponentFormattingOptions options = FullyDecoded) const;
0199 
0200     void setPassword(const QString &password, ParsingMode mode = DecodedMode);
0201     QString password(ComponentFormattingOptions = FullyDecoded) const;
0202 
0203     void setHost(const QString &host, ParsingMode mode = DecodedMode);
0204     QString host(ComponentFormattingOptions = FullyDecoded) const;
0205 
0206     void setPort(int port);
0207     int port(int defaultPort = -1) const;
0208 
0209     void setPath(const QString &path, ParsingMode mode = DecodedMode);
0210     QString path(ComponentFormattingOptions options = FullyDecoded) const;
0211     QString fileName(ComponentFormattingOptions options = FullyDecoded) const;
0212 
0213     bool hasQuery() const;
0214     void setQuery(const QString &query, ParsingMode mode = TolerantMode);
0215     void setQuery(const QUrlQuery &query);
0216     QString query(ComponentFormattingOptions = PrettyDecoded) const;
0217 
0218     bool hasFragment() const;
0219     QString fragment(ComponentFormattingOptions options = PrettyDecoded) const;
0220     void setFragment(const QString &fragment, ParsingMode mode = TolerantMode);
0221 
0222     [[nodiscard]] QUrl resolved(const QUrl &relative) const;
0223 
0224     bool isRelative() const;
0225     bool isParentOf(const QUrl &url) const;
0226 
0227     bool isLocalFile() const;
0228     static QUrl fromLocalFile(const QString &localfile);
0229     QString toLocalFile() const;
0230 
0231     void detach();
0232     bool isDetached() const;
0233 
0234 #if QT_CORE_REMOVED_SINCE(6, 8)
0235     bool operator <(const QUrl &url) const;
0236     bool operator ==(const QUrl &url) const;
0237     bool operator !=(const QUrl &url) const;
0238 #endif
0239 
0240     bool matches(const QUrl &url, FormattingOptions options) const;
0241 
0242     static QString fromPercentEncoding(const QByteArray &);
0243     static QByteArray toPercentEncoding(const QString &,
0244                                         const QByteArray &exclude = QByteArray(),
0245                                         const QByteArray &include = QByteArray());
0246 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0247     static QUrl fromCFURL(CFURLRef url);
0248     CFURLRef toCFURL() const Q_DECL_CF_RETURNS_RETAINED;
0249     static QUrl fromNSURL(const NSURL *url);
0250     NSURL *toNSURL() const Q_DECL_NS_RETURNS_AUTORELEASED;
0251 #endif
0252 
0253     enum AceProcessingOption : unsigned int {
0254         IgnoreIDNWhitelist = 0x1,
0255         AceTransitionalProcessing = 0x2,
0256     };
0257     Q_DECLARE_FLAGS(AceProcessingOptions, AceProcessingOption)
0258 
0259 #if QT_CORE_REMOVED_SINCE(6, 3)
0260     static QString fromAce(const QByteArray &);
0261     static QByteArray toAce(const QString &);
0262 #endif
0263     static QString fromAce(const QByteArray &domain, AceProcessingOptions options = {});
0264     static QByteArray toAce(const QString &domain, AceProcessingOptions options = {});
0265 
0266     static QStringList idnWhitelist();
0267     static QStringList toStringList(const QList<QUrl> &uris, FormattingOptions options = FormattingOptions(PrettyDecoded));
0268     static QList<QUrl> fromStringList(const QStringList &uris, ParsingMode mode = TolerantMode);
0269 
0270     static void setIdnWhitelist(const QStringList &);
0271     friend Q_CORE_EXPORT size_t qHash(const QUrl &url, size_t seed) noexcept;
0272 
0273 private:
0274     friend Q_CORE_EXPORT bool comparesEqual(const QUrl &lhs, const QUrl &rhs);
0275     friend Q_CORE_EXPORT Qt::weak_ordering
0276     compareThreeWay(const QUrl &lhs, const QUrl &rhs);
0277     Q_DECLARE_WEAKLY_ORDERED_NON_NOEXCEPT(QUrl)
0278 
0279     QUrlPrivate *d;
0280     friend class QUrlQuery;
0281 
0282 public:
0283     typedef QUrlPrivate * DataPtr;
0284     inline DataPtr &data_ptr() { return d; }
0285 };
0286 
0287 Q_DECLARE_SHARED(QUrl)
0288 Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::ComponentFormattingOptions)
0289 //Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions)
0290 Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::AceProcessingOptions)
0291 
0292 #ifndef Q_QDOC
0293 constexpr inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption f1, QUrl::UrlFormattingOption f2)
0294 { return QUrl::FormattingOptions(f1) | f2; }
0295 constexpr inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption f1, QUrl::FormattingOptions f2)
0296 { return f2 | f1; }
0297 constexpr inline QIncompatibleFlag operator|(QUrl::UrlFormattingOption f1, int f2)
0298 { return QIncompatibleFlag(uint(f1) | f2); }
0299 
0300 // add operators for OR'ing the two types of flags
0301 inline QUrl::FormattingOptions &operator|=(QUrl::FormattingOptions &i, QUrl::ComponentFormattingOptions f)
0302 { i |= QUrl::UrlFormattingOption(f.toInt()); return i; }
0303 constexpr inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption i, QUrl::ComponentFormattingOption f)
0304 { return i | QUrl::UrlFormattingOption(qToUnderlying(f)); }
0305 constexpr inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption i, QUrl::ComponentFormattingOptions f)
0306 { return i | QUrl::UrlFormattingOption(f.toInt()); }
0307 constexpr inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOption f, QUrl::UrlFormattingOption i)
0308 { return i | QUrl::UrlFormattingOption(qToUnderlying(f)); }
0309 constexpr inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOptions f, QUrl::UrlFormattingOption i)
0310 { return i | QUrl::UrlFormattingOption(f.toInt()); }
0311 constexpr inline QUrl::FormattingOptions operator|(QUrl::FormattingOptions i, QUrl::ComponentFormattingOptions f)
0312 { return i | QUrl::UrlFormattingOption(f.toInt()); }
0313 constexpr inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOption f, QUrl::FormattingOptions i)
0314 { return i | QUrl::UrlFormattingOption(qToUnderlying(f)); }
0315 constexpr inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOptions f, QUrl::FormattingOptions i)
0316 { return i | QUrl::UrlFormattingOption(f.toInt()); }
0317 
0318 //inline QUrl::UrlFormattingOption &operator=(const QUrl::UrlFormattingOption &i, QUrl::ComponentFormattingOptions f)
0319 //{ i = int(f); f; }
0320 #endif // Q_QDOC
0321 
0322 #ifndef QT_NO_DATASTREAM
0323 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUrl &);
0324 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUrl &);
0325 #endif
0326 
0327 #ifndef QT_NO_DEBUG_STREAM
0328 Q_CORE_EXPORT QDebug operator<<(QDebug, const QUrl &);
0329 #endif
0330 
0331 QT_END_NAMESPACE
0332 
0333 #endif // QURL_H