Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qbytearraylist.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2014 by Southwest Research Institute (R)
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#include <qbytearraylist.h>
7
9
10/*! \typedef QByteArrayListIterator
11 \relates QByteArrayList
12
13 The QByteArrayListIterator type definition provides a Java-style const
14 iterator for QByteArrayList.
15
16 QByteArrayList provides both \l{Java-style iterators} and
17 \l{STL-style iterators}. The Java-style const iterator is simply
18 a type definition for QListIterator<QByteArray>.
19
20 \sa QMutableByteArrayListIterator, QByteArrayList::const_iterator
21*/
22
23/*! \typedef QMutableByteArrayListIterator
24 \relates QByteArrayList
25
26 The QByteArrayListIterator type definition provides a Java-style
27 non-const iterator for QByteArrayList.
28
29 QByteArrayList provides both \l{Java-style iterators} and
30 \l{STL-style iterators}. The Java-style non-const iterator is
31 simply a type definition for QMutableListIterator<QByteArray>.
32
33 \sa QByteArrayListIterator, QByteArrayList::iterator
34*/
35
36/*!
37 \class QByteArrayList
38 \inmodule QtCore
39 \since 5.4
40 \brief The QByteArrayList class provides a list of byte arrays.
41
42 \ingroup tools
43 \ingroup shared
44 \ingroup string-processing
45
46 \reentrant
47
48 QByteArrayList is actually just a QList<QByteArray>. It is documented as a
49 full class just for simplicity of documenting the member methods that exist
50 only in QList<QByteArray>.
51
52 All of QList's functionality also applies to QByteArrayList. For example, you
53 can use isEmpty() to test whether the list is empty, and you can call
54 functions like append(), prepend(), insert(), replace(), removeAll(),
55 removeAt(), removeFirst(), removeLast(), and removeOne() to modify a
56 QByteArrayList. In addition, QByteArrayList provides several join()
57 methods for concatenating the list into a single QByteArray.
58
59 The purpose of QByteArrayList is quite different from that of QStringList.
60 Whereas QStringList has many methods for manipulation of elements within
61 the list, QByteArrayList does not.
62 Normally, QStringList should be used whenever working with a list of printable
63 strings. QByteArrayList should be used to handle and efficiently join large blobs
64 of binary data, as when sequentially receiving serialized data through a
65 QIODevice.
66
67 \sa QByteArray, QStringList
68*/
69
70/*!
71 \fn QByteArray QByteArrayList::join(const QByteArray &separator) const
72
73 Joins all the byte arrays into a single byte array with each
74 element separated by the given \a separator.
75*/
76
77/*!
78 \fn QByteArray QByteArrayList::join(QByteArrayView separator) const
79 \since 6.3
80
81 Joins all the byte arrays into a single byte array with each
82 element separated by the given \a separator, if any.
83*/
84
85/*!
86 \fn QByteArray QByteArrayList::join(char separator) const
87
88 Joins all the byte arrays into a single byte array with each
89 element separated by the given \a separator.
90*/
91
92static qsizetype QByteArrayList_joinedSize(const QByteArrayList *that, qsizetype seplen)
93{
94 qsizetype totalLength = 0;
95 const qsizetype size = that->size();
96
97 for (qsizetype i = 0; i < size; ++i)
98 totalLength += that->at(i).size();
99
100 if (size > 0)
101 totalLength += seplen * (size - 1);
102
103 return totalLength;
104}
105
106QByteArray QtPrivate::QByteArrayList_join(const QByteArrayList *that, const char *sep, qsizetype seplen)
107{
108 QByteArray res;
109 if (const qsizetype joinedSize = QByteArrayList_joinedSize(that, seplen))
110 res.reserve(joinedSize); // don't call reserve(0) - it allocates one byte for the NUL
111 const qsizetype size = that->size();
112 for (qsizetype i = 0; i < size; ++i) {
113 if (i)
114 res.append(sep, seplen);
115 res += that->at(i);
116 }
117 return res;
118}
119
120QT_END_NAMESPACE
static qsizetype QByteArrayList_joinedSize(const QByteArrayList *that, qsizetype seplen)