diff options
author | Dennis Oberst <dennis.oberst@qt.io> | 2023-05-17 10:31:38 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-06-02 06:43:31 +0200 |
commit | 18a2c62c073371ab24685d0f98b4b0cc04d11a7e (patch) | |
tree | 0efa8576c1f637aa74a6c67b3d0d839a1e9225f4 /src/corelib/text/qbytearray.h | |
parent | qdbusxml2cpp: Fail if -c option is used with multiple interfaces (diff) | |
download | qtbase-18a2c62c073371ab24685d0f98b4b0cc04d11a7e.tar.xz qtbase-18a2c62c073371ab24685d0f98b4b0cc04d11a7e.zip |
QByteArray: add STL-style assign()
Implemented assign() methods for QByteArray to align with the
criteria of std::basic_string, addressing the previously missing
functionality. This is a subset of the overloads provided by the
standard.
Reference:
https://en.cppreference.com/w/cpp/string/basic_string/assign
[ChangeLog][QtCore][QByteArray] Added assign().
Fixes: QTBUG-106199
Change-Id: I899b14d74e8f774face8690303efb8610ead95b5
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text/qbytearray.h')
-rw-r--r-- | src/corelib/text/qbytearray.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 2c15545ecd..972e2174d3 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -40,6 +40,8 @@ namespace emscripten { } #endif +class tst_QByteArray; + QT_BEGIN_NAMESPACE class QString; @@ -60,6 +62,11 @@ private: DataPointer d; static const char _empty; + + friend class ::tst_QByteArray; + + template <typename InputIterator> + using if_input_iterator = QtPrivate::IfIsInputIterator<InputIterator>; public: enum Base64Option { @@ -227,6 +234,20 @@ public: QByteArray &append(QByteArrayView a) { return insert(size(), a); } + QByteArray &assign(QByteArrayView v); + QByteArray &assign(qsizetype n, char c) + { + Q_ASSERT(n >= 0); + return fill(c, n); + } + template <typename InputIterator, if_input_iterator<InputIterator> = true> + QByteArray &assign(InputIterator first, InputIterator last) + { + d.assign(first, last); + d.data()[d.size] = '\0'; + return *this; + } + QByteArray &insert(qsizetype i, QByteArrayView data); inline QByteArray &insert(qsizetype i, const char *s) { return insert(i, QByteArrayView(s)); } |