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