summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearray.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qbytearray.h')
-rw-r--r--src/corelib/text/qbytearray.h68
1 files changed, 63 insertions, 5 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index 5d8ccbfb1a..e3bb9ea937 100644
--- a/src/corelib/text/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
@@ -164,10 +164,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);
@@ -230,8 +240,8 @@ public:
int count(const char *a) const;
int count(const QByteArray &a) const;
- inline int compare(const char *c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- inline int compare(const QByteArray &a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
+ inline int compare(const char *c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
+ inline int compare(const QByteArray &a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
Q_REQUIRED_RESULT QByteArray left(int len) const;
Q_REQUIRED_RESULT QByteArray right(int len) const;
@@ -379,6 +389,10 @@ 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);
+
+ 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);
Q_REQUIRED_RESULT static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous
Q_REQUIRED_RESULT static QByteArray fromHex(const QByteArray &hexEncoded);
@@ -649,12 +663,12 @@ inline bool QByteArray::contains(const QByteArray &a) const
{ return indexOf(a) != -1; }
inline bool QByteArray::contains(char c) const
{ return indexOf(c) != -1; }
-inline int QByteArray::compare(const char *c, Qt::CaseSensitivity cs) const
+inline int QByteArray::compare(const char *c, Qt::CaseSensitivity cs) const noexcept
{
return cs == Qt::CaseSensitive ? qstrcmp(*this, c) :
qstrnicmp(data(), size(), c, -1);
}
-inline int QByteArray::compare(const QByteArray &a, Qt::CaseSensitivity cs) const
+inline int QByteArray::compare(const QByteArray &a, Qt::CaseSensitivity cs) const noexcept
{
return cs == Qt::CaseSensitive ? qstrcmp(*this, a) :
qstrnicmp(data(), size(), a.data(), a.size());
@@ -749,6 +763,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