Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qbytearraylist.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Copyright (C) 2014 by Southwest Research Institute (R) | - | ||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
6 | ** | - | ||||||
7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
8 | ** | - | ||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
10 | ** Commercial License Usage | - | ||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
17 | ** | - | ||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
25 | ** | - | ||||||
26 | ** GNU General Public License Usage | - | ||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
36 | ** | - | ||||||
37 | ** $QT_END_LICENSE$ | - | ||||||
38 | ** | - | ||||||
39 | ****************************************************************************/ | - | ||||||
40 | - | |||||||
41 | #include <qbytearraylist.h> | - | ||||||
42 | - | |||||||
43 | QT_BEGIN_NAMESPACE | - | ||||||
44 | - | |||||||
45 | /*! \typedef QByteArrayListIterator | - | ||||||
46 | \relates QByteArrayList | - | ||||||
47 | - | |||||||
48 | The QByteArrayListIterator type definition provides a Java-style const | - | ||||||
49 | iterator for QByteArrayList. | - | ||||||
50 | - | |||||||
51 | QByteArrayList provides both \l{Java-style iterators} and | - | ||||||
52 | \l{STL-style iterators}. The Java-style const iterator is simply | - | ||||||
53 | a type definition for QListIterator<QByteArray>. | - | ||||||
54 | - | |||||||
55 | \sa QMutableByteArrayListIterator, QByteArrayList::const_iterator | - | ||||||
56 | */ | - | ||||||
57 | - | |||||||
58 | /*! \typedef QMutableByteArrayListIterator | - | ||||||
59 | \relates QByteArrayList | - | ||||||
60 | - | |||||||
61 | The QByteArrayListIterator type definition provides a Java-style | - | ||||||
62 | non-const iterator for QByteArrayList. | - | ||||||
63 | - | |||||||
64 | QByteArrayList provides both \l{Java-style iterators} and | - | ||||||
65 | \l{STL-style iterators}. The Java-style non-const iterator is | - | ||||||
66 | simply a type definition for QMutableListIterator<QByteArray>. | - | ||||||
67 | - | |||||||
68 | \sa QByteArrayListIterator, QByteArrayList::iterator | - | ||||||
69 | */ | - | ||||||
70 | - | |||||||
71 | /*! | - | ||||||
72 | \class QByteArrayList | - | ||||||
73 | \inmodule QtCore | - | ||||||
74 | \since 5.4 | - | ||||||
75 | \brief The QByteArrayList class provides a list of byte arrays. | - | ||||||
76 | - | |||||||
77 | \ingroup tools | - | ||||||
78 | \ingroup shared | - | ||||||
79 | \ingroup string-processing | - | ||||||
80 | - | |||||||
81 | \reentrant | - | ||||||
82 | - | |||||||
83 | QByteArrayList is actually just a QList<QByteArray>. It is documented as a | - | ||||||
84 | full class just for simplicity of documenting the member methods that exist | - | ||||||
85 | only in QList<QByteArray>. | - | ||||||
86 | - | |||||||
87 | All of QList's functionality also applies to QByteArrayList. For example, you | - | ||||||
88 | can use isEmpty() to test whether the list is empty, and you can call | - | ||||||
89 | functions like append(), prepend(), insert(), replace(), removeAll(), | - | ||||||
90 | removeAt(), removeFirst(), removeLast(), and removeOne() to modify a | - | ||||||
91 | QByteArrayList. In addition, QByteArrayList provides several join() | - | ||||||
92 | methods for concatenating the list into a single QByteArray. | - | ||||||
93 | - | |||||||
94 | The purpose of QByteArrayList is quite different from that of QStringList. | - | ||||||
95 | Whereas QStringList has many methods for manipulation of elements within | - | ||||||
96 | the list, QByteArrayList does not. | - | ||||||
97 | Normally, QStringList should be used whenever working with a list of printable | - | ||||||
98 | strings. QByteArrayList should be used to handle and efficiently join large blobs | - | ||||||
99 | of binary data, as when sequentially receiving serialized data through a | - | ||||||
100 | QIODevice. | - | ||||||
101 | - | |||||||
102 | \sa QByteArray, QStringList | - | ||||||
103 | */ | - | ||||||
104 | - | |||||||
105 | /*! | - | ||||||
106 | \fn QByteArray QByteArrayList::join() const | - | ||||||
107 | - | |||||||
108 | Joins all the byte arrays into a single byte array. | - | ||||||
109 | */ | - | ||||||
110 | - | |||||||
111 | /*! | - | ||||||
112 | \fn QByteArray QByteArrayList::join(const QByteArray &separator) const | - | ||||||
113 | - | |||||||
114 | Joins all the byte arrays into a single byte array with each | - | ||||||
115 | element separated by the given \a separator. | - | ||||||
116 | */ | - | ||||||
117 | - | |||||||
118 | /*! | - | ||||||
119 | \fn QByteArray QByteArrayList::join(char separator) const | - | ||||||
120 | - | |||||||
121 | Joins all the byte arrays into a single byte array with each | - | ||||||
122 | element separated by the given \a separator. | - | ||||||
123 | */ | - | ||||||
124 | - | |||||||
125 | static int QByteArrayList_joinedSize(const QByteArrayList *that, int seplen) | - | ||||||
126 | { | - | ||||||
127 | int totalLength = 0; | - | ||||||
128 | const int size = that->size(); | - | ||||||
129 | - | |||||||
130 | for (int i = 0; i < size; ++i)
| 3979-3989 | ||||||
131 | totalLength += that->at(i).size(); executed 3989 times by 14 tests: totalLength += that->at(i).size(); Executed by:
| 3989 | ||||||
132 | - | |||||||
133 | if (size > 0)
| 5-3974 | ||||||
134 | totalLength += seplen * (size - 1); executed 3974 times by 14 tests: totalLength += seplen * (size - 1); Executed by:
| 3974 | ||||||
135 | - | |||||||
136 | return totalLength; executed 3979 times by 14 tests: return totalLength; Executed by:
| 3979 | ||||||
137 | } | - | ||||||
138 | - | |||||||
139 | QByteArray QtPrivate::QByteArrayList_join(const QByteArrayList *that, const char *sep, int seplen) | - | ||||||
140 | { | - | ||||||
141 | QByteArray res; | - | ||||||
142 | if (const int joinedSize = QByteArrayList_joinedSize(that, seplen))
| 7-3972 | ||||||
143 | res.reserve(joinedSize); // don't call reserve(0) - it allocates one byte for the NUL executed 3972 times by 14 tests: res.reserve(joinedSize); Executed by:
| 3972 | ||||||
144 | const int size = that->size(); | - | ||||||
145 | for (int i = 0; i < size; ++i) {
| 3979-3989 | ||||||
146 | if (i)
| 15-3974 | ||||||
147 | res.append(sep, seplen); executed 15 times by 2 tests: res.append(sep, seplen); Executed by:
| 15 | ||||||
148 | res += that->at(i); | - | ||||||
149 | } executed 3989 times by 14 tests: end of block Executed by:
| 3989 | ||||||
150 | return res; executed 3979 times by 14 tests: return res; Executed by:
| 3979 | ||||||
151 | } | - | ||||||
152 | - | |||||||
153 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |