diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-12-09 01:00:35 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-09 10:16:01 +0100 |
commit | bef74b6c3a0a9c8649ea8eb333d80015f76863e4 (patch) | |
tree | 41cdf5b6776c90a6d04a1d6680f4d47a90593746 /src/corelib/text/qbytearray.h | |
parent | f8d2975b6a8b36bf8dd304c99783947a72081b79 (diff) | |
parent | 4c3c63d4cbb81b38e88e06b72749e7e01497b6f1 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: Ia24cc8b86def0d9d9c17d6775cc519e491b860b1
Diffstat (limited to 'src/corelib/text/qbytearray.h')
-rw-r--r-- | src/corelib/text/qbytearray.h | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index af8e4da36d..fa87ebf058 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -145,10 +145,20 @@ public: Base64UrlEncoding = 1, KeepTrailingEquals = 0, - OmitTrailingEquals = 2 + OmitTrailingEquals = 2, + + IgnoreBase64DecodingErrors = 0, + AbortOnBase64DecodingErrors = 4, }; Q_DECLARE_FLAGS(Base64Options, Base64Option) + enum class Base64DecodingStatus { + Ok, + IllegalInputLength, + IllegalCharacter, + IllegalPadding, + }; + inline QByteArray() noexcept; QByteArray(const char *, int size = -1); QByteArray(int size, char c); @@ -356,8 +366,11 @@ public: Q_REQUIRED_RESULT static QByteArray number(qulonglong, int base = 10); Q_REQUIRED_RESULT static QByteArray number(double, char f = 'g', int prec = 6); Q_REQUIRED_RESULT static QByteArray fromRawData(const char *, int size); - Q_REQUIRED_RESULT static QByteArray fromBase64(const QByteArray &base64, - Base64Options options = Base64Encoding); + + class FromBase64Result; + Q_REQUIRED_RESULT static FromBase64Result fromBase64Encoding(QByteArray &&base64, Base64Options options = Base64Encoding); + Q_REQUIRED_RESULT static FromBase64Result fromBase64Encoding(const QByteArray &base64, Base64Options options = Base64Encoding); + Q_REQUIRED_RESULT static QByteArray fromBase64(const QByteArray &base64, Base64Options options = Base64Encoding); Q_REQUIRED_RESULT static QByteArray fromHex(const QByteArray &hexEncoded); Q_REQUIRED_RESULT static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); @@ -642,6 +655,50 @@ inline QByteArray qUncompress(const QByteArray& data) Q_DECLARE_SHARED(QByteArray) +class QByteArray::FromBase64Result +{ +public: + QByteArray decoded; + QByteArray::Base64DecodingStatus decodingStatus; + + void swap(QByteArray::FromBase64Result &other) noexcept + { + qSwap(decoded, other.decoded); + qSwap(decodingStatus, other.decodingStatus); + } + + explicit operator bool() const noexcept { return decodingStatus == QByteArray::Base64DecodingStatus::Ok; } + +#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC) + QByteArray &operator*() & noexcept { return decoded; } + const QByteArray &operator*() const & noexcept { return decoded; } + QByteArray &&operator*() && noexcept { return std::move(decoded); } +#else + QByteArray &operator*() noexcept { return decoded; } + const QByteArray &operator*() const noexcept { return decoded; } +#endif +}; + +Q_DECLARE_SHARED(QByteArray::FromBase64Result) + +inline bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept +{ + if (lhs.decodingStatus != rhs.decodingStatus) + return false; + + if (lhs.decodingStatus == QByteArray::Base64DecodingStatus::Ok && lhs.decoded != rhs.decoded) + return false; + + return true; +} + +inline bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray::FromBase64Result &key, uint seed = 0) noexcept; + QT_END_NAMESPACE #endif // QBYTEARRAY_H |