tools/qbytearray.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qbytearray.h" -
43#include "qbytearraymatcher.h" -
44#include "qtools_p.h" -
45#include "qstring.h" -
46#include "qlist.h" -
47#include "qlocale.h" -
48#include "qlocale_p.h" -
49#include "qscopedpointer.h" -
50#include <qdatastream.h> -
51 -
52#ifndef QT_NO_COMPRESS -
53#include <zlib.h> -
54#endif -
55#include <ctype.h> -
56#include <limits.h> -
57#include <string.h> -
58#include <stdlib.h> -
59 -
60#define IS_RAW_DATA(d) ((d)->offset != sizeof(QByteArrayData)) -
61 -
62QT_BEGIN_NAMESPACE -
63 -
64 -
65int qFindByteArray( -
66 const char *haystack0, int haystackLen, int from, -
67 const char *needle0, int needleLen); -
68 -
69 -
70int qAllocMore(int alloc, int extra) -
71{ -
72 Q_ASSERT(alloc >= 0 && extra >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
73 Q_ASSERT_X(alloc < (1 << 30) - extra, "qAllocMore", "Requested size is too large!");
executed (the execution status of this line is deduced): qt_noop();
-
74 -
75 unsigned nalloc = alloc + extra;
executed (the execution status of this line is deduced): unsigned nalloc = alloc + extra;
-
76 -
77 // Round up to next power of 2 -
78 -
79 // Assuming container is growing, always overshoot -
80 //--nalloc; -
81 -
82 nalloc |= nalloc >> 1;
executed (the execution status of this line is deduced): nalloc |= nalloc >> 1;
-
83 nalloc |= nalloc >> 2;
executed (the execution status of this line is deduced): nalloc |= nalloc >> 2;
-
84 nalloc |= nalloc >> 4;
executed (the execution status of this line is deduced): nalloc |= nalloc >> 4;
-
85 nalloc |= nalloc >> 8;
executed (the execution status of this line is deduced): nalloc |= nalloc >> 8;
-
86 nalloc |= nalloc >> 16;
executed (the execution status of this line is deduced): nalloc |= nalloc >> 16;
-
87 ++nalloc;
executed (the execution status of this line is deduced): ++nalloc;
-
88 -
89 Q_ASSERT(nalloc > unsigned(alloc + extra));
executed (the execution status of this line is deduced): qt_noop();
-
90 -
91 return nalloc - extra;
executed: return nalloc - extra;
Execution Count:20272755
20272755
92} -
93 -
94/***************************************************************************** -
95 Safe and portable C string functions; extensions to standard string.h -
96 *****************************************************************************/ -
97 -
98/*! \relates QByteArray -
99 -
100 Returns a duplicate string. -
101 -
102 Allocates space for a copy of \a src, copies it, and returns a -
103 pointer to the copy. If \a src is 0, it immediately returns 0. -
104 -
105 Ownership is passed to the caller, so the returned string must be -
106 deleted using \c delete[]. -
107*/ -
108 -
109char *qstrdup(const char *src) -
110{ -
111 if (!src)
evaluated: !src
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1270237
1-1270237
112 return 0;
executed: return 0;
Execution Count:1
1
113 char *dst = new char[strlen(src) + 1];
executed (the execution status of this line is deduced): char *dst = new char[strlen(src) + 1];
-
114 return qstrcpy(dst, src);
executed: return qstrcpy(dst, src);
Execution Count:1270237
1270237
115} -
116 -
117/*! \relates QByteArray -
118 -
119 Copies all the characters up to and including the '\\0' from \a -
120 src into \a dst and returns a pointer to \a dst. If \a src is 0, -
121 it immediately returns 0. -
122 -
123 This function assumes that \a dst is large enough to hold the -
124 contents of \a src. -
125 -
126 \sa qstrncpy() -
127*/ -
128 -
129char *qstrcpy(char *dst, const char *src) -
130{ -
131 if (!src)
evaluated: !src
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1271446
2-1271446
132 return 0;
executed: return 0;
Execution Count:2
2
133#if defined(_MSC_VER) && _MSC_VER >= 1400 -
134 const int len = int(strlen(src)); -
135 // This is actually not secure!!! It will be fixed -
136 // properly in a later release! -
137 if (len >= 0 && strcpy_s(dst, len+1, src) == 0) -
138 return dst; -
139 return 0; -
140#else -
141 return strcpy(dst, src);
executed: return strcpy(dst, src);
Execution Count:1271446
1271446
142#endif -
143} -
144 -
145/*! \relates QByteArray -
146 -
147 A safe \c strncpy() function. -
148 -
149 Copies at most \a len bytes from \a src (stopping at \a len or the -
150 terminating '\\0' whichever comes first) into \a dst and returns a -
151 pointer to \a dst. Guarantees that \a dst is '\\0'-terminated. If -
152 \a src or \a dst is 0, returns 0 immediately. -
153 -
154 This function assumes that \a dst is at least \a len characters -
155 long. -
156 -
157 \note When compiling with Visual C++ compiler version 14.00 -
158 (Visual C++ 2005) or later, internally the function strncpy_s -
159 will be used. -
160 -
161 \sa qstrcpy() -
162*/ -
163 -
164char *qstrncpy(char *dst, const char *src, uint len) -
165{ -
166 if (!src || !dst)
evaluated: !src
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:19
partially evaluated: !dst
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19
0-19
167 return 0;
executed: return 0;
Execution Count:2
2
168#if defined(_MSC_VER) && _MSC_VER >= 1400 -
169 strncpy_s(dst, len, src, len-1); -
170#else -
171 strncpy(dst, src, len);
executed (the execution status of this line is deduced): strncpy(dst, src, len);
-
172#endif -
173 if (len > 0)
partially evaluated: len > 0
TRUEFALSE
yes
Evaluation Count:19
no
Evaluation Count:0
0-19
174 dst[len-1] = '\0';
executed: dst[len-1] = '\0';
Execution Count:19
19
175 return dst;
executed: return dst;
Execution Count:19
19
176} -
177 -
178/*! \fn uint qstrlen(const char *str) -
179 \relates QByteArray -
180 -
181 A safe \c strlen() function. -
182 -
183 Returns the number of characters that precede the terminating '\\0', -
184 or 0 if \a str is 0. -
185 -
186 \sa qstrnlen() -
187*/ -
188 -
189/*! \fn uint qstrnlen(const char *str, uint maxlen) -
190 \relates QByteArray -
191 \since 4.2 -
192 -
193 A safe \c strnlen() function. -
194 -
195 Returns the number of characters that precede the terminating '\\0', but -
196 at most \a maxlen. If \a str is 0, returns 0. -
197 -
198 \sa qstrlen() -
199*/ -
200 -
201/*! -
202 \relates QByteArray -
203 -
204 A safe \c strcmp() function. -
205 -
206 Compares \a str1 and \a str2. Returns a negative value if \a str1 -
207 is less than \a str2, 0 if \a str1 is equal to \a str2 or a -
208 positive value if \a str1 is greater than \a str2. -
209 -
210 Special case 1: Returns 0 if \a str1 and \a str2 are both 0. -
211 -
212 Special case 2: Returns an arbitrary non-zero value if \a str1 is 0 -
213 or \a str2 is 0 (but not both). -
214 -
215 \sa qstrncmp(), qstricmp(), qstrnicmp(), {8-bit Character Comparisons} -
216*/ -
217int qstrcmp(const char *str1, const char *str2) -
218{ -
219 return (str1 && str2) ? strcmp(str1, str2)
executed: return (str1 && str2) ? strcmp(str1, str2) : (str1 ? 1 : (str2 ? -1 : 0));
Execution Count:247040
247040
220 : (str1 ? 1 : (str2 ? -1 : 0));
executed: return (str1 && str2) ? strcmp(str1, str2) : (str1 ? 1 : (str2 ? -1 : 0));
Execution Count:247040
247040
221} -
222 -
223/*! \fn int qstrncmp(const char *str1, const char *str2, uint len); -
224 -
225 \relates QByteArray -
226 -
227 A safe \c strncmp() function. -
228 -
229 Compares at most \a len bytes of \a str1 and \a str2. -
230 -
231 Returns a negative value if \a str1 is less than \a str2, 0 if \a -
232 str1 is equal to \a str2 or a positive value if \a str1 is greater -
233 than \a str2. -
234 -
235 Special case 1: Returns 0 if \a str1 and \a str2 are both 0. -
236 -
237 Special case 2: Returns a random non-zero value if \a str1 is 0 -
238 or \a str2 is 0 (but not both). -
239 -
240 \sa qstrcmp(), qstricmp(), qstrnicmp(), {8-bit Character Comparisons} -
241*/ -
242 -
243/*! \relates QByteArray -
244 -
245 A safe \c stricmp() function. -
246 -
247 Compares \a str1 and \a str2 ignoring the case of the -
248 characters. The encoding of the strings is assumed to be Latin-1. -
249 -
250 Returns a negative value if \a str1 is less than \a str2, 0 if \a -
251 str1 is equal to \a str2 or a positive value if \a str1 is greater -
252 than \a str2. -
253 -
254 Special case 1: Returns 0 if \a str1 and \a str2 are both 0. -
255 -
256 Special case 2: Returns a random non-zero value if \a str1 is 0 -
257 or \a str2 is 0 (but not both). -
258 -
259 \sa qstrcmp(), qstrncmp(), qstrnicmp(), {8-bit Character Comparisons} -
260*/ -
261 -
262int qstricmp(const char *str1, const char *str2) -
263{ -
264 register const uchar *s1 = reinterpret_cast<const uchar *>(str1);
executed (the execution status of this line is deduced): register const uchar *s1 = reinterpret_cast<const uchar *>(str1);
-
265 register const uchar *s2 = reinterpret_cast<const uchar *>(str2);
executed (the execution status of this line is deduced): register const uchar *s2 = reinterpret_cast<const uchar *>(str2);
-
266 int res;
executed (the execution status of this line is deduced): int res;
-
267 uchar c;
executed (the execution status of this line is deduced): uchar c;
-
268 if (!s1 || !s2)
evaluated: !s1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:114495
evaluated: !s2
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:114494
1-114495
269 return s1 ? 1 : (s2 ? -1 : 0);
executed: return s1 ? 1 : (s2 ? -1 : 0);
Execution Count:3
3
270 for (; !(res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)); s1++, s2++)
evaluated: !(res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2))
TRUEFALSE
yes
Evaluation Count:191633
yes
Evaluation Count:105873
105873-191633
271 if (!c) // strings are equal
evaluated: !c
TRUEFALSE
yes
Evaluation Count:8620
yes
Evaluation Count:183015
8620-183015
272 break;
executed: break;
Execution Count:8620
8620
273 return res;
executed: return res;
Execution Count:114490
114490
274} -
275 -
276/*! \relates QByteArray -
277 -
278 A safe \c strnicmp() function. -
279 -
280 Compares at most \a len bytes of \a str1 and \a str2 ignoring the -
281 case of the characters. The encoding of the strings is assumed to -
282 be Latin-1. -
283 -
284 Returns a negative value if \a str1 is less than \a str2, 0 if \a str1 -
285 is equal to \a str2 or a positive value if \a str1 is greater than \a -
286 str2. -
287 -
288 Special case 1: Returns 0 if \a str1 and \a str2 are both 0. -
289 -
290 Special case 2: Returns a random non-zero value if \a str1 is 0 -
291 or \a str2 is 0 (but not both). -
292 -
293 \sa qstrcmp(), qstrncmp(), qstricmp(), {8-bit Character Comparisons} -
294*/ -
295 -
296int qstrnicmp(const char *str1, const char *str2, uint len) -
297{ -
298 register const uchar *s1 = reinterpret_cast<const uchar *>(str1);
executed (the execution status of this line is deduced): register const uchar *s1 = reinterpret_cast<const uchar *>(str1);
-
299 register const uchar *s2 = reinterpret_cast<const uchar *>(str2);
executed (the execution status of this line is deduced): register const uchar *s2 = reinterpret_cast<const uchar *>(str2);
-
300 int res;
executed (the execution status of this line is deduced): int res;
-
301 uchar c;
executed (the execution status of this line is deduced): uchar c;
-
302 if (!s1 || !s2)
evaluated: !s1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:123
evaluated: !s2
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:122
1-123
303 return s1 ? 1 : (s2 ? -1 : 0);
executed: return s1 ? 1 : (s2 ? -1 : 0);
Execution Count:3
3
304 for (; len--; s1++, s2++) {
evaluated: len--
TRUEFALSE
yes
Evaluation Count:243
yes
Evaluation Count:10
10-243
305 if ((res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)))
evaluated: (res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2))
TRUEFALSE
yes
Evaluation Count:111
yes
Evaluation Count:132
111-132
306 return res;
executed: return res;
Execution Count:111
111
307 if (!c) // strings are equal
evaluated: !c
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:131
1-131
308 break;
executed: break;
Execution Count:1
1
309 }
executed: }
Execution Count:131
131
310 return 0;
executed: return 0;
Execution Count:11
11
311} -
312 -
313/*! -
314 \internal -
315 */ -
316int qstrcmp(const QByteArray &str1, const char *str2) -
317{ -
318 if (!str2)
evaluated: !str2
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:1556794
32-1556794
319 return str1.isEmpty() ? 0 : +1;
executed: return str1.isEmpty() ? 0 : +1;
Execution Count:32
32
320 -
321 const char *str1data = str1.constData();
executed (the execution status of this line is deduced): const char *str1data = str1.constData();
-
322 const char *str1end = str1data + str1.length();
executed (the execution status of this line is deduced): const char *str1end = str1data + str1.length();
-
323 for ( ; str1data < str1end && *str2; ++str1data, ++str2) {
evaluated: str1data < str1end
TRUEFALSE
yes
Evaluation Count:5228338
yes
Evaluation Count:419018
evaluated: *str2
TRUEFALSE
yes
Evaluation Count:5228059
yes
Evaluation Count:280
280-5228338
324 register int diff = int(uchar(*str1data)) - uchar(*str2);
executed (the execution status of this line is deduced): register int diff = int(uchar(*str1data)) - uchar(*str2);
-
325 if (diff)
evaluated: diff
TRUEFALSE
yes
Evaluation Count:1137494
yes
Evaluation Count:4090563
1137494-4090563
326 // found a difference -
327 return diff;
executed: return diff;
Execution Count:1137494
1137494
328 }
executed: }
Execution Count:4090564
4090564
329 -
330 // Why did we stop? -
331 if (*str2 != '\0')
evaluated: *str2 != '\0'
TRUEFALSE
yes
Evaluation Count:1697
yes
Evaluation Count:417601
1697-417601
332 // not the null, so we stopped because str1 is shorter -
333 return -1;
executed: return -1;
Execution Count:1697
1697
334 if (str1data < str1end)
evaluated: str1data < str1end
TRUEFALSE
yes
Evaluation Count:280
yes
Evaluation Count:417321
280-417321
335 // we haven't reached the end, so str1 must be longer -
336 return +1;
executed: return +1;
Execution Count:280
280
337 return 0;
executed: return 0;
Execution Count:417321
417321
338} -
339 -
340/*! -
341 \internal -
342 */ -
343int qstrcmp(const QByteArray &str1, const QByteArray &str2) -
344{ -
345 int l1 = str1.length();
executed (the execution status of this line is deduced): int l1 = str1.length();
-
346 int l2 = str2.length();
executed (the execution status of this line is deduced): int l2 = str2.length();
-
347 int ret = memcmp(str1.constData(), str2.constData(), qMin(l1, l2));
executed (the execution status of this line is deduced): int ret = memcmp(str1.constData(), str2.constData(), qMin(l1, l2));
-
348 if (ret != 0)
evaluated: ret != 0
TRUEFALSE
yes
Evaluation Count:30290
yes
Evaluation Count:1197
1197-30290
349 return ret;
executed: return ret;
Execution Count:30290
30290
350 -
351 // they matched qMin(l1, l2) bytes -
352 // so the longer one is lexically after the shorter one -
353 return l1 - l2;
executed: return l1 - l2;
Execution Count:1197
1197
354} -
355 -
356// the CRC table below is created by the following piece of code -
357#if 0 -
358static void createCRC16Table() // build CRC16 lookup table -
359{ -
360 register unsigned int i; -
361 register unsigned int j; -
362 unsigned short crc_tbl[16]; -
363 unsigned int v0, v1, v2, v3; -
364 for (i = 0; i < 16; i++) { -
365 v0 = i & 1; -
366 v1 = (i >> 1) & 1; -
367 v2 = (i >> 2) & 1; -
368 v3 = (i >> 3) & 1; -
369 j = 0; -
370#undef SET_BIT -
371#define SET_BIT(x, b, v) (x) |= (v) << (b) -
372 SET_BIT(j, 0, v0); -
373 SET_BIT(j, 7, v0); -
374 SET_BIT(j, 12, v0); -
375 SET_BIT(j, 1, v1); -
376 SET_BIT(j, 8, v1); -
377 SET_BIT(j, 13, v1); -
378 SET_BIT(j, 2, v2); -
379 SET_BIT(j, 9, v2); -
380 SET_BIT(j, 14, v2); -
381 SET_BIT(j, 3, v3); -
382 SET_BIT(j, 10, v3); -
383 SET_BIT(j, 15, v3); -
384 crc_tbl[i] = j; -
385 } -
386 printf("static const quint16 crc_tbl[16] = {\n"); -
387 for (int i = 0; i < 16; i +=4) -
388 printf(" 0x%04x, 0x%04x, 0x%04x, 0x%04x,\n", crc_tbl[i], crc_tbl[i+1], crc_tbl[i+2], crc_tbl[i+3]); -
389 printf("};\n"); -
390} -
391#endif -
392 -
393static const quint16 crc_tbl[16] = { -
394 0x0000, 0x1081, 0x2102, 0x3183, -
395 0x4204, 0x5285, 0x6306, 0x7387, -
396 0x8408, 0x9489, 0xa50a, 0xb58b, -
397 0xc60c, 0xd68d, 0xe70e, 0xf78f -
398}; -
399 -
400/*! -
401 \relates QByteArray -
402 -
403 Returns the CRC-16 checksum of the first \a len bytes of \a data. -
404 -
405 The checksum is independent of the byte order (endianness). -
406 -
407 \note This function is a 16-bit cache conserving (16 entry table) -
408 implementation of the CRC-16-CCITT algorithm. -
409*/ -
410 -
411quint16 qChecksum(const char *data, uint len) -
412{ -
413 register quint16 crc = 0xffff;
executed (the execution status of this line is deduced): register quint16 crc = 0xffff;
-
414 uchar c;
executed (the execution status of this line is deduced): uchar c;
-
415 const uchar *p = reinterpret_cast<const uchar *>(data);
executed (the execution status of this line is deduced): const uchar *p = reinterpret_cast<const uchar *>(data);
-
416 while (len--) {
evaluated: len--
TRUEFALSE
yes
Evaluation Count:5933
yes
Evaluation Count:21
21-5933
417 c = *p++;
executed (the execution status of this line is deduced): c = *p++;
-
418 crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)];
executed (the execution status of this line is deduced): crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)];
-
419 c >>= 4;
executed (the execution status of this line is deduced): c >>= 4;
-
420 crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)];
executed (the execution status of this line is deduced): crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)];
-
421 }
executed: }
Execution Count:5933
5933
422 return ~crc & 0xffff;
executed: return ~crc & 0xffff;
Execution Count:21
21
423} -
424 -
425/*! -
426 \fn QByteArray qCompress(const QByteArray& data, int compressionLevel) -
427 -
428 \relates QByteArray -
429 -
430 Compresses the \a data byte array and returns the compressed data -
431 in a new byte array. -
432 -
433 The \a compressionLevel parameter specifies how much compression -
434 should be used. Valid values are between 0 and 9, with 9 -
435 corresponding to the greatest compression (i.e. smaller compressed -
436 data) at the cost of using a slower algorithm. Smaller values (8, -
437 7, ..., 1) provide successively less compression at slightly -
438 faster speeds. The value 0 corresponds to no compression at all. -
439 The default value is -1, which specifies zlib's default -
440 compression. -
441 -
442 \sa qUncompress() -
443*/ -
444 -
445/*! \relates QByteArray -
446 -
447 \overload -
448 -
449 Compresses the first \a nbytes of \a data and returns the -
450 compressed data in a new byte array. -
451*/ -
452 -
453#ifndef QT_NO_COMPRESS -
454QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel) -
455{ -
456 if (nbytes == 0) {
evaluated: nbytes == 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:18
1-18
457 return QByteArray(4, '\0');
executed: return QByteArray(4, '\0');
Execution Count:1
1
458 } -
459 if (!data) {
partially evaluated: !data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
460 qWarning("qCompress: Data is null");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 460, __PRETTY_FUNCTION__).warning("qCompress: Data is null");
-
461 return QByteArray();
never executed: return QByteArray();
0
462 } -
463 if (compressionLevel < -1 || compressionLevel > 9)
partially evaluated: compressionLevel < -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
partially evaluated: compressionLevel > 9
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
464 compressionLevel = -1;
never executed: compressionLevel = -1;
0
465 -
466 ulong len = nbytes + nbytes / 100 + 13;
executed (the execution status of this line is deduced): ulong len = nbytes + nbytes / 100 + 13;
-
467 QByteArray bazip;
executed (the execution status of this line is deduced): QByteArray bazip;
-
468 int res;
executed (the execution status of this line is deduced): int res;
-
469 do { -
470 bazip.resize(len + 4);
executed (the execution status of this line is deduced): bazip.resize(len + 4);
-
471 res = ::compress2((uchar*)bazip.data()+4, &len, (uchar*)data, nbytes, compressionLevel);
executed (the execution status of this line is deduced): res = ::compress2((uchar*)bazip.data()+4, &len, (uchar*)data, nbytes, compressionLevel);
-
472 -
473 switch (res) { -
474 case Z_OK: -
475 bazip.resize(len + 4);
executed (the execution status of this line is deduced): bazip.resize(len + 4);
-
476 bazip[0] = (nbytes & 0xff000000) >> 24;
executed (the execution status of this line is deduced): bazip[0] = (nbytes & 0xff000000) >> 24;
-
477 bazip[1] = (nbytes & 0x00ff0000) >> 16;
executed (the execution status of this line is deduced): bazip[1] = (nbytes & 0x00ff0000) >> 16;
-
478 bazip[2] = (nbytes & 0x0000ff00) >> 8;
executed (the execution status of this line is deduced): bazip[2] = (nbytes & 0x0000ff00) >> 8;
-
479 bazip[3] = (nbytes & 0x000000ff);
executed (the execution status of this line is deduced): bazip[3] = (nbytes & 0x000000ff);
-
480 break;
executed: break;
Execution Count:18
18
481 case Z_MEM_ERROR: -
482 qWarning("qCompress: Z_MEM_ERROR: Not enough memory");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 482, __PRETTY_FUNCTION__).warning("qCompress: Z_MEM_ERROR: Not enough memory");
-
483 bazip.resize(0);
never executed (the execution status of this line is deduced): bazip.resize(0);
-
484 break;
never executed: break;
0
485 case Z_BUF_ERROR: -
486 len *= 2;
never executed (the execution status of this line is deduced): len *= 2;
-
487 break;
never executed: break;
0
488 } -
489 } while (res == Z_BUF_ERROR);
executed: }
Execution Count:18
partially evaluated: res == (-5)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
490 -
491 return bazip;
executed: return bazip;
Execution Count:18
18
492} -
493#endif -
494 -
495/*! -
496 \fn QByteArray qUncompress(const QByteArray &data) -
497 -
498 \relates QByteArray -
499 -
500 Uncompresses the \a data byte array and returns a new byte array -
501 with the uncompressed data. -
502 -
503 Returns an empty QByteArray if the input data was corrupt. -
504 -
505 This function will uncompress data compressed with qCompress() -
506 from this and any earlier Qt version, back to Qt 3.1 when this -
507 feature was added. -
508 -
509 \b{Note:} If you want to use this function to uncompress external -
510 data that was compressed using zlib, you first need to prepend a four -
511 byte header to the byte array containing the data. The header must -
512 contain the expected length (in bytes) of the uncompressed data, -
513 expressed as an unsigned, big-endian, 32-bit integer. -
514 -
515 \sa qCompress() -
516*/ -
517 -
518/*! \relates QByteArray -
519 -
520 \overload -
521 -
522 Uncompresses the first \a nbytes of \a data and returns a new byte -
523 array with the uncompressed data. -
524*/ -
525 -
526#ifndef QT_NO_COMPRESS -
527QByteArray qUncompress(const uchar* data, int nbytes) -
528{ -
529 if (!data) {
partially evaluated: !data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:668
0-668
530 qWarning("qUncompress: Data is null");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 530, __PRETTY_FUNCTION__).warning("qUncompress: Data is null");
-
531 return QByteArray();
never executed: return QByteArray();
0
532 } -
533 if (nbytes <= 4) {
evaluated: nbytes <= 4
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:655
13-655
534 if (nbytes < 4 || (data[0]!=0 || data[1]!=0 || data[2]!=0 || data[3]!=0))
partially evaluated: nbytes < 4
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
evaluated: data[0]!=0
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:3
partially evaluated: data[1]!=0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: data[2]!=0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
evaluated: data[3]!=0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
0-13
535 qWarning("qUncompress: Input data is corrupted");
executed: QMessageLogger("tools/qbytearray.cpp", 535, __PRETTY_FUNCTION__).warning("qUncompress: Input data is corrupted");
Execution Count:11
11
536 return QByteArray();
executed: return QByteArray();
Execution Count:13
13
537 } -
538 ulong expectedSize = (data[0] << 24) | (data[1] << 16) |
executed (the execution status of this line is deduced): ulong expectedSize = (data[0] << 24) | (data[1] << 16) |
-
539 (data[2] << 8) | (data[3] );
executed (the execution status of this line is deduced): (data[2] << 8) | (data[3] );
-
540 ulong len = qMax(expectedSize, 1ul);
executed (the execution status of this line is deduced): ulong len = qMax(expectedSize, 1ul);
-
541 QScopedPointer<QByteArray::Data, QScopedPointerPodDeleter> d;
executed (the execution status of this line is deduced): QScopedPointer<QByteArray::Data, QScopedPointerPodDeleter> d;
-
542 -
543 forever {
executed (the execution status of this line is deduced): for(;;) {
-
544 ulong alloc = len;
executed (the execution status of this line is deduced): ulong alloc = len;
-
545 if (len >= (1u << 31u) - sizeof(QByteArray::Data)) {
evaluated: len >= (1u << 31u) - sizeof(QByteArray::Data)
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:648
7-648
546 //QByteArray does not support that huge size anyway. -
547 qWarning("qUncompress: Input data is corrupted");
executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 547, __PRETTY_FUNCTION__).warning("qUncompress: Input data is corrupted");
-
548 return QByteArray();
executed: return QByteArray();
Execution Count:7
7
549 } -
550 QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + alloc + 1));
executed (the execution status of this line is deduced): QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + alloc + 1));
-
551 if (!p) {
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:648
0-648
552 // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS -
553 qWarning("qUncompress: could not allocate enough memory to uncompress data");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 553, __PRETTY_FUNCTION__).warning("qUncompress: could not allocate enough memory to uncompress data");
-
554 return QByteArray();
never executed: return QByteArray();
0
555 } -
556 d.take(); // realloc was successful
executed (the execution status of this line is deduced): d.take();
-
557 d.reset(p);
executed (the execution status of this line is deduced): d.reset(p);
-
558 d->offset = sizeof(QByteArrayData);
executed (the execution status of this line is deduced): d->offset = sizeof(QByteArrayData);
-
559 -
560 int res = ::uncompress((uchar*)d->data(), &len,
executed (the execution status of this line is deduced): int res = ::uncompress((uchar*)d->data(), &len,
-
561 (uchar*)data+4, nbytes-4);
executed (the execution status of this line is deduced): (uchar*)data+4, nbytes-4);
-
562 -
563 switch (res) { -
564 case Z_OK: -
565 if (len != alloc) {
partially evaluated: len != alloc
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:643
0-643
566 if (len >= (1u << 31u) - sizeof(QByteArray::Data)) {
never evaluated: len >= (1u << 31u) - sizeof(QByteArray::Data)
0
567 //QByteArray does not support that huge size anyway. -
568 qWarning("qUncompress: Input data is corrupted");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 568, __PRETTY_FUNCTION__).warning("qUncompress: Input data is corrupted");
-
569 return QByteArray();
never executed: return QByteArray();
0
570 } -
571 QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + len + 1));
never executed (the execution status of this line is deduced): QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + len + 1));
-
572 if (!p) {
never evaluated: !p
0
573 // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS -
574 qWarning("qUncompress: could not allocate enough memory to uncompress data");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 574, __PRETTY_FUNCTION__).warning("qUncompress: could not allocate enough memory to uncompress data");
-
575 return QByteArray();
never executed: return QByteArray();
0
576 } -
577 d.take(); // realloc was successful
never executed (the execution status of this line is deduced): d.take();
-
578 d.reset(p);
never executed (the execution status of this line is deduced): d.reset(p);
-
579 }
never executed: }
0
580 d->ref.initializeOwned();
never executed (the execution status of this line is deduced): d->ref.initializeOwned();
-
581 d->size = len;
never executed (the execution status of this line is deduced): d->size = len;
-
582 d->alloc = uint(len) + 1u;
never executed (the execution status of this line is deduced): d->alloc = uint(len) + 1u;
-
583 d->capacityReserved = false;
never executed (the execution status of this line is deduced): d->capacityReserved = false;
-
584 d->offset = sizeof(QByteArrayData);
never executed (the execution status of this line is deduced): d->offset = sizeof(QByteArrayData);
-
585 d->data()[len] = 0;
never executed (the execution status of this line is deduced): d->data()[len] = 0;
-
586 -
587 { -
588 QByteArrayDataPtr dataPtr = { reinterpret_cast<QByteArrayData *>(d.take()) };
executed (the execution status of this line is deduced): QByteArrayDataPtr dataPtr = { reinterpret_cast<QByteArrayData *>(d.take()) };
-
589 return QByteArray(dataPtr);
executed: return QByteArray(dataPtr);
Execution Count:643
643
590 } -
591 -
592 case Z_MEM_ERROR: -
593 qWarning("qUncompress: Z_MEM_ERROR: Not enough memory");
never executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 593, __PRETTY_FUNCTION__).warning("qUncompress: Z_MEM_ERROR: Not enough memory");
-
594 return QByteArray();
never executed: return QByteArray();
0
595 -
596 case Z_BUF_ERROR: -
597 len *= 2;
never executed (the execution status of this line is deduced): len *= 2;
-
598 continue;
never executed: continue;
0
599 -
600 case Z_DATA_ERROR: -
601 qWarning("qUncompress: Z_DATA_ERROR: Input data is corrupted");
executed (the execution status of this line is deduced): QMessageLogger("tools/qbytearray.cpp", 601, __PRETTY_FUNCTION__).warning("qUncompress: Z_DATA_ERROR: Input data is corrupted");
-
602 return QByteArray();
executed: return QByteArray();
Execution Count:5
5
603 } -
604 }
never executed: }
0
605}
never executed: }
0
606#endif -
607 -
608static inline bool qIsUpper(char c) -
609{ -
610 return c >= 'A' && c <= 'Z';
executed: return c >= 'A' && c <= 'Z';
Execution Count:450222
450222
611} -
612 -
613static inline char qToLower(char c) -
614{ -
615 if (c >= 'A' && c <= 'Z')
partially evaluated: c >= 'A'
TRUEFALSE
yes
Evaluation Count:450222
no
Evaluation Count:0
partially evaluated: c <= 'Z'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:450222
0-450222
616 return c - 'A' + 'a';
never executed: return c - 'A' + 'a';
0
617 else -
618 return c;
executed: return c;
Execution Count:450222
450222
619} -
620 -
621/*! -
622 \class QByteArray -
623 \inmodule QtCore -
624 \brief The QByteArray class provides an array of bytes. -
625 -
626 \ingroup tools -
627 \ingroup shared -
628 \ingroup string-processing -
629 -
630 \reentrant -
631 -
632 QByteArray can be used to store both raw bytes (including '\\0's) -
633 and traditional 8-bit '\\0'-terminated strings. Using QByteArray -
634 is much more convenient than using \c{const char *}. Behind the -
635 scenes, it always ensures that the data is followed by a '\\0' -
636 terminator, and uses \l{implicit sharing} (copy-on-write) to -
637 reduce memory usage and avoid needless copying of data. -
638 -
639 In addition to QByteArray, Qt also provides the QString class to -
640 store string data. For most purposes, QString is the class you -
641 want to use. It stores 16-bit Unicode characters, making it easy -
642 to store non-ASCII/non-Latin-1 characters in your application. -
643 Furthermore, QString is used throughout in the Qt API. The two -
644 main cases where QByteArray is appropriate are when you need to -
645 store raw binary data, and when memory conservation is critical -
646 (e.g., with Qt for Embedded Linux). -
647 -
648 One way to initialize a QByteArray is simply to pass a \c{const -
649 char *} to its constructor. For example, the following code -
650 creates a byte array of size 5 containing the data "Hello": -
651 -
652 \snippet code/src_corelib_tools_qbytearray.cpp 0 -
653 -
654 Although the size() is 5, the byte array also maintains an extra -
655 '\\0' character at the end so that if a function is used that -
656 asks for a pointer to the underlying data (e.g. a call to -
657 data()), the data pointed to is guaranteed to be -
658 '\\0'-terminated. -
659 -
660 QByteArray makes a deep copy of the \c{const char *} data, so you -
661 can modify it later without experiencing side effects. (If for -
662 performance reasons you don't want to take a deep copy of the -
663 character data, use QByteArray::fromRawData() instead.) -
664 -
665 Another approach is to set the size of the array using resize() -
666 and to initialize the data byte per byte. QByteArray uses 0-based -
667 indexes, just like C++ arrays. To access the byte at a particular -
668 index position, you can use operator[](). On non-const byte -
669 arrays, operator[]() returns a reference to a byte that can be -
670 used on the left side of an assignment. For example: -
671 -
672 \snippet code/src_corelib_tools_qbytearray.cpp 1 -
673 -
674 For read-only access, an alternative syntax is to use at(): -
675 -
676 \snippet code/src_corelib_tools_qbytearray.cpp 2 -
677 -
678 at() can be faster than operator[](), because it never causes a -
679 \l{deep copy} to occur. -
680 -
681 To extract many bytes at a time, use left(), right(), or mid(). -
682 -
683 A QByteArray can embed '\\0' bytes. The size() function always -
684 returns the size of the whole array, including embedded '\\0' -
685 bytes, but excluding the terminating '\\0' added by QByteArray. -
686 For example: -
687 -
688 \snippet code/src_corelib_tools_qbytearray.cpp 48 -
689 -
690 If you want to obtain the length of the data up to and -
691 excluding the first '\\0' character, call qstrlen() on the byte -
692 array. -
693 -
694 After a call to resize(), newly allocated bytes have undefined -
695 values. To set all the bytes to a particular value, call fill(). -
696 -
697 To obtain a pointer to the actual character data, call data() or -
698 constData(). These functions return a pointer to the beginning of the data. -
699 The pointer is guaranteed to remain valid until a non-const function is -
700 called on the QByteArray. It is also guaranteed that the data ends with a -
701 '\\0' byte unless the QByteArray was created from a \l{fromRawData()}{raw -
702 data}. This '\\0' byte is automatically provided by QByteArray and is not -
703 counted in size(). -
704 -
705 QByteArray provides the following basic functions for modifying -
706 the byte data: append(), prepend(), insert(), replace(), and -
707 remove(). For example: -
708 -
709 \snippet code/src_corelib_tools_qbytearray.cpp 3 -
710 -
711 The replace() and remove() functions' first two arguments are the -
712 position from which to start erasing and the number of bytes that -
713 should be erased. -
714 -
715 When you append() data to a non-empty array, the array will be -
716 reallocated and the new data copied to it. You can avoid this -
717 behavior by calling reserve(), which preallocates a certain amount -
718 of memory. You can also call capacity() to find out how much -
719 memory QByteArray actually allocated. Data appended to an empty -
720 array is not copied. -
721 -
722 A frequent requirement is to remove whitespace characters from a -
723 byte array ('\\n', '\\t', ' ', etc.). If you want to remove -
724 whitespace from both ends of a QByteArray, use trimmed(). If you -
725 want to remove whitespace from both ends and replace multiple -
726 consecutive whitespaces with a single space character within the -
727 byte array, use simplified(). -
728 -
729 If you want to find all occurrences of a particular character or -
730 substring in a QByteArray, use indexOf() or lastIndexOf(). The -
731 former searches forward starting from a given index position, the -
732 latter searches backward. Both return the index position of the -
733 character or substring if they find it; otherwise, they return -1. -
734 For example, here's a typical loop that finds all occurrences of a -
735 particular substring: -
736 -
737 \snippet code/src_corelib_tools_qbytearray.cpp 4 -
738 -
739 If you simply want to check whether a QByteArray contains a -
740 particular character or substring, use contains(). If you want to -
741 find out how many times a particular character or substring -
742 occurs in the byte array, use count(). If you want to replace all -
743 occurrences of a particular value with another, use one of the -
744 two-parameter replace() overloads. -
745 -
746 QByteArrays can be compared using overloaded operators such as -
747 operator<(), operator<=(), operator==(), operator>=(), and so on. -
748 The comparison is based exclusively on the numeric values -
749 of the characters and is very fast, but is not what a human would -
750 expect. QString::localeAwareCompare() is a better choice for -
751 sorting user-interface strings. -
752 -
753 For historical reasons, QByteArray distinguishes between a null -
754 byte array and an empty byte array. A \e null byte array is a -
755 byte array that is initialized using QByteArray's default -
756 constructor or by passing (const char *)0 to the constructor. An -
757 \e empty byte array is any byte array with size 0. A null byte -
758 array is always empty, but an empty byte array isn't necessarily -
759 null: -
760 -
761 \snippet code/src_corelib_tools_qbytearray.cpp 5 -
762 -
763 All functions except isNull() treat null byte arrays the same as -
764 empty byte arrays. For example, data() returns a pointer to a -
765 '\\0' character for a null byte array (\e not a null pointer), -
766 and QByteArray() compares equal to QByteArray(""). We recommend -
767 that you always use isEmpty() and avoid isNull(). -
768 -
769 \section1 Notes on Locale -
770 -
771 \section2 Number-String Conversions -
772 -
773 Functions that perform conversions between numeric data types and -
774 strings are performed in the C locale, irrespective of the user's -
775 locale settings. Use QString to perform locale-aware conversions -
776 between numbers and strings. -
777 -
778 \section2 8-bit Character Comparisons -
779 -
780 In QByteArray, the notion of uppercase and lowercase and of which -
781 character is greater than or less than another character is -
782 locale dependent. This affects functions that support a case -
783 insensitive option or that compare or lowercase or uppercase -
784 their arguments. Case insensitive operations and comparisons will -
785 be accurate if both strings contain only ASCII characters. (If \c -
786 $LC_CTYPE is set, most Unix systems do "the right thing".) -
787 Functions that this affects include contains(), indexOf(), -
788 lastIndexOf(), operator<(), operator<=(), operator>(), -
789 operator>=(), toLower() and toUpper(). -
790 -
791 This issue does not apply to QStrings since they represent -
792 characters using Unicode. -
793 -
794 \sa QString, QBitArray -
795*/ -
796 -
797/*! \fn QByteArray::iterator QByteArray::begin() -
798 -
799 \internal -
800*/ -
801 -
802/*! \fn QByteArray::const_iterator QByteArray::begin() const -
803 -
804 \internal -
805*/ -
806 -
807/*! \fn QByteArray::const_iterator QByteArray::cbegin() const -
808 \since 5.0 -
809 -
810 \internal -
811*/ -
812 -
813/*! \fn QByteArray::const_iterator QByteArray::constBegin() const -
814 -
815 \internal -
816*/ -
817 -
818/*! \fn QByteArray::iterator QByteArray::end() -
819 -
820 \internal -
821*/ -
822 -
823/*! \fn QByteArray::const_iterator QByteArray::end() const -
824 -
825 \internal -
826*/ -
827 -
828/*! \fn QByteArray::const_iterator QByteArray::cend() const -
829 \since 5.0 -
830 -
831 \internal -
832*/ -
833 -
834/*! \fn QByteArray::const_iterator QByteArray::constEnd() const -
835 -
836 \internal -
837*/ -
838 -
839/*! \fn void QByteArray::push_back(const QByteArray &other) -
840 -
841 This function is provided for STL compatibility. It is equivalent -
842 to append(\a other). -
843*/ -
844 -
845/*! \fn void QByteArray::push_back(const char *str) -
846 -
847 \overload -
848 -
849 Same as append(\a str). -
850*/ -
851 -
852/*! \fn void QByteArray::push_back(char ch) -
853 -
854 \overload -
855 -
856 Same as append(\a ch). -
857*/ -
858 -
859/*! \fn void QByteArray::push_front(const QByteArray &other) -
860 -
861 This function is provided for STL compatibility. It is equivalent -
862 to prepend(\a other). -
863*/ -
864 -
865/*! \fn void QByteArray::push_front(const char *str) -
866 -
867 \overload -
868 -
869 Same as prepend(\a str). -
870*/ -
871 -
872/*! \fn void QByteArray::push_front(char ch) -
873 -
874 \overload -
875 -
876 Same as prepend(\a ch). -
877*/ -
878 -
879/*! \fn QByteArray::QByteArray(const QByteArray &other) -
880 -
881 Constructs a copy of \a other. -
882 -
883 This operation takes \l{constant time}, because QByteArray is -
884 \l{implicitly shared}. This makes returning a QByteArray from a -
885 function very fast. If a shared instance is modified, it will be -
886 copied (copy-on-write), taking \l{linear time}. -
887 -
888 \sa operator=() -
889*/ -
890 -
891/*! \fn QByteArray::QByteArray(QByteArrayDataPtr dd) -
892 -
893 \internal -
894 -
895 Constructs a byte array pointing to the same data as \a dd. -
896*/ -
897 -
898/*! \fn QByteArray::~QByteArray() -
899 Destroys the byte array. -
900*/ -
901 -
902/*! -
903 Assigns \a other to this byte array and returns a reference to -
904 this byte array. -
905*/ -
906QByteArray &QByteArray::operator=(const QByteArray & other) -
907{ -
908 other.d->ref.ref();
executed (the execution status of this line is deduced): other.d->ref.ref();
-
909 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:230964
yes
Evaluation Count:956841
230964-956841
910 Data::deallocate(d);
executed: Data::deallocate(d);
Execution Count:230964
230964
911 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
912 return *this;
executed: return *this;
Execution Count:1187810
1187810
913} -
914 -
915 -
916/*! -
917 \overload -
918 -
919 Assigns \a str to this byte array. -
920*/ -
921 -
922QByteArray &QByteArray::operator=(const char *str) -
923{ -
924 Data *x;
executed (the execution status of this line is deduced): Data *x;
-
925 if (!str) {
evaluated: !str
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:212929
1-212929
926 x = Data::sharedNull();
executed (the execution status of this line is deduced): x = Data::sharedNull();
-
927 } else if (!*str) {
executed: }
Execution Count:1
evaluated: !*str
TRUEFALSE
yes
Evaluation Count:46584
yes
Evaluation Count:166345
1-166345
928 x = Data::allocate(0);
executed (the execution status of this line is deduced): x = Data::allocate(0);
-
929 } else {
executed: }
Execution Count:46584
46584
930 const int len = int(strlen(str));
executed (the execution status of this line is deduced): const int len = int(strlen(str));
-
931 const uint fullLen = len + 1;
executed (the execution status of this line is deduced): const uint fullLen = len + 1;
-
932 if (d->ref.isShared() || fullLen > d->alloc
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:1860
yes
Evaluation Count:164485
evaluated: fullLen > d->alloc
TRUEFALSE
yes
Evaluation Count:82993
yes
Evaluation Count:81492
1860-164485
933 || (len < d->size && fullLen < uint(d->alloc >> 1)))
evaluated: len < d->size
TRUEFALSE
yes
Evaluation Count:13448
yes
Evaluation Count:68044
evaluated: fullLen < uint(d->alloc >> 1)
TRUEFALSE
yes
Evaluation Count:13445
yes
Evaluation Count:3
3-68044
934 reallocData(fullLen, d->detachFlags());
executed: reallocData(fullLen, d->detachFlags());
Execution Count:98298
98298
935 x = d;
executed (the execution status of this line is deduced): x = d;
-
936 memcpy(x->data(), str, fullLen); // include null terminator
executed (the execution status of this line is deduced): memcpy(x->data(), str, fullLen);
-
937 x->size = len;
executed (the execution status of this line is deduced): x->size = len;
-
938 }
executed: }
Execution Count:166345
166345
939 x->ref.ref();
executed (the execution status of this line is deduced): x->ref.ref();
-
940 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:45312
yes
Evaluation Count:167618
45312-167618
941 Data::deallocate(d);
executed: Data::deallocate(d);
Execution Count:45312
45312
942 d = x;
executed (the execution status of this line is deduced): d = x;
-
943 return *this;
executed: return *this;
Execution Count:212930
212930
944} -
945 -
946/*! \fn void QByteArray::swap(QByteArray &other) -
947 \since 4.8 -
948 -
949 Swaps byte array \a other with this byte array. This operation is very -
950 fast and never fails. -
951*/ -
952 -
953/*! \fn int QByteArray::size() const -
954 -
955 Returns the number of bytes in this byte array. -
956 -
957 The last byte in the byte array is at position size() - 1. In addition, -
958 QByteArray ensures that the byte at position size() is always '\\0', so -
959 that you can use the return value of data() and constData() as arguments to -
960 functions that expect '\\0'-terminated strings. If the QByteArray object -
961 was created from a \l{fromRawData()}{raw data} that didn't include the -
962 trailing null-termination character then QByteArray doesn't add it -
963 automaticall unless the \l{deep copy} is created. -
964 -
965 Example: -
966 \snippet code/src_corelib_tools_qbytearray.cpp 6 -
967 -
968 \sa isEmpty(), resize() -
969*/ -
970 -
971/*! \fn bool QByteArray::isEmpty() const -
972 -
973 Returns true if the byte array has size 0; otherwise returns false. -
974 -
975 Example: -
976 \snippet code/src_corelib_tools_qbytearray.cpp 7 -
977 -
978 \sa size() -
979*/ -
980 -
981/*! \fn int QByteArray::capacity() const -
982 -
983 Returns the maximum number of bytes that can be stored in the -
984 byte array without forcing a reallocation. -
985 -
986 The sole purpose of this function is to provide a means of fine -
987 tuning QByteArray's memory usage. In general, you will rarely -
988 ever need to call this function. If you want to know how many -
989 bytes are in the byte array, call size(). -
990 -
991 \sa reserve(), squeeze() -
992*/ -
993 -
994/*! \fn void QByteArray::reserve(int size) -
995 -
996 Attempts to allocate memory for at least \a size bytes. If you -
997 know in advance how large the byte array will be, you can call -
998 this function, and if you call resize() often you are likely to -
999 get better performance. If \a size is an underestimate, the worst -
1000 that will happen is that the QByteArray will be a bit slower. -
1001 -
1002 The sole purpose of this function is to provide a means of fine -
1003 tuning QByteArray's memory usage. In general, you will rarely -
1004 ever need to call this function. If you want to change the size -
1005 of the byte array, call resize(). -
1006 -
1007 \sa squeeze(), capacity() -
1008*/ -
1009 -
1010/*! \fn void QByteArray::squeeze() -
1011 -
1012 Releases any memory not required to store the array's data. -
1013 -
1014 The sole purpose of this function is to provide a means of fine -
1015 tuning QByteArray's memory usage. In general, you will rarely -
1016 ever need to call this function. -
1017 -
1018 \sa reserve(), capacity() -
1019*/ -
1020 -
1021/*! \fn QByteArray::operator const char *() const -
1022 \fn QByteArray::operator const void *() const -
1023 -
1024 \obsolete Use constData() instead. -
1025 -
1026 Returns a pointer to the data stored in the byte array. The -
1027 pointer can be used to access the bytes that compose the array. -
1028 The data is '\\0'-terminated. The pointer remains valid as long -
1029 as the array isn't reallocated or destroyed. -
1030 -
1031 This operator is mostly useful to pass a byte array to a function -
1032 that accepts a \c{const char *}. -
1033 -
1034 You can disable this operator by defining \c -
1035 QT_NO_CAST_FROM_BYTEARRAY when you compile your applications. -
1036 -
1037 Note: A QByteArray can store any byte values including '\\0's, -
1038 but most functions that take \c{char *} arguments assume that the -
1039 data ends at the first '\\0' they encounter. -
1040 -
1041 \sa constData() -
1042*/ -
1043 -
1044/*! -
1045 \macro QT_NO_CAST_FROM_BYTEARRAY -
1046 \relates QByteArray -
1047 -
1048 Disables automatic conversions from QByteArray to -
1049 const char * or const void *. -
1050 -
1051 \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII -
1052*/ -
1053 -
1054/*! \fn char *QByteArray::data() -
1055 -
1056 Returns a pointer to the data stored in the byte array. The -
1057 pointer can be used to access and modify the bytes that compose -
1058 the array. The data is '\\0'-terminated, i.e. the number of -
1059 bytes in the returned character string is size() + 1 for the -
1060 '\\0' terminator. -
1061 -
1062 Example: -
1063 \snippet code/src_corelib_tools_qbytearray.cpp 8 -
1064 -
1065 The pointer remains valid as long as the byte array isn't -
1066 reallocated or destroyed. For read-only access, constData() is -
1067 faster because it never causes a \l{deep copy} to occur. -
1068 -
1069 This function is mostly useful to pass a byte array to a function -
1070 that accepts a \c{const char *}. -
1071 -
1072 The following example makes a copy of the char* returned by -
1073 data(), but it will corrupt the heap and cause a crash because it -
1074 does not allocate a byte for the '\\0' at the end: -
1075 -
1076 \snippet code/src_corelib_tools_qbytearray.cpp 46 -
1077 -
1078 This one allocates the correct amount of space: -
1079 -
1080 \snippet code/src_corelib_tools_qbytearray.cpp 47 -
1081 -
1082 Note: A QByteArray can store any byte values including '\\0's, -
1083 but most functions that take \c{char *} arguments assume that the -
1084 data ends at the first '\\0' they encounter. -
1085 -
1086 \sa constData(), operator[]() -
1087*/ -
1088 -
1089/*! \fn const char *QByteArray::data() const -
1090 -
1091 \overload -
1092*/ -
1093 -
1094/*! \fn const char *QByteArray::constData() const -
1095 -
1096 Returns a pointer to the data stored in the byte array. The pointer can be -
1097 used to access the bytes that compose the array. The data is -
1098 '\\0'-terminated unless the QByteArray object was created from raw data. -
1099 The pointer remains valid as long as the byte array isn't reallocated or -
1100 destroyed. -
1101 -
1102 This function is mostly useful to pass a byte array to a function -
1103 that accepts a \c{const char *}. -
1104 -
1105 Note: A QByteArray can store any byte values including '\\0's, -
1106 but most functions that take \c{char *} arguments assume that the -
1107 data ends at the first '\\0' they encounter. -
1108 -
1109 \sa data(), operator[](), fromRawData() -
1110*/ -
1111 -
1112/*! \fn void QByteArray::detach() -
1113 -
1114 \internal -
1115*/ -
1116 -
1117/*! \fn bool QByteArray::isDetached() const -
1118 -
1119 \internal -
1120*/ -
1121 -
1122/*! \fn bool QByteArray::isSharedWith(const QByteArray &other) const -
1123 -
1124 \internal -
1125*/ -
1126 -
1127/*! \fn char QByteArray::at(int i) const -
1128 -
1129 Returns the character at index position \a i in the byte array. -
1130 -
1131 \a i must be a valid index position in the byte array (i.e., 0 <= -
1132 \a i < size()). -
1133 -
1134 \sa operator[]() -
1135*/ -
1136 -
1137/*! \fn QByteRef QByteArray::operator[](int i) -
1138 -
1139 Returns the byte at index position \a i as a modifiable reference. -
1140 -
1141 If an assignment is made beyond the end of the byte array, the -
1142 array is extended with resize() before the assignment takes -
1143 place. -
1144 -
1145 Example: -
1146 \snippet code/src_corelib_tools_qbytearray.cpp 9 -
1147 -
1148 The return value is of type QByteRef, a helper class for -
1149 QByteArray. When you get an object of type QByteRef, you can use -
1150 it as if it were a char &. If you assign to it, the assignment -
1151 will apply to the character in the QByteArray from which you got -
1152 the reference. -
1153 -
1154 \sa at() -
1155*/ -
1156 -
1157/*! \fn char QByteArray::operator[](int i) const -
1158 -
1159 \overload -
1160 -
1161 Same as at(\a i). -
1162*/ -
1163 -
1164/*! \fn QByteRef QByteArray::operator[](uint i) -
1165 -
1166 \overload -
1167*/ -
1168 -
1169/*! \fn char QByteArray::operator[](uint i) const -
1170 -
1171 \overload -
1172*/ -
1173 -
1174/*! \fn bool QByteArray::contains(const QByteArray &ba) const -
1175 -
1176 Returns true if the byte array contains an occurrence of the byte -
1177 array \a ba; otherwise returns false. -
1178 -
1179 \sa indexOf(), count() -
1180*/ -
1181 -
1182/*! \fn bool QByteArray::contains(const char *str) const -
1183 -
1184 \overload -
1185 -
1186 Returns true if the byte array contains the string \a str; -
1187 otherwise returns false. -
1188*/ -
1189 -
1190/*! \fn bool QByteArray::contains(char ch) const -
1191 -
1192 \overload -
1193 -
1194 Returns true if the byte array contains the character \a ch; -
1195 otherwise returns false. -
1196*/ -
1197 -
1198/*! -
1199 -
1200 Truncates the byte array at index position \a pos. -
1201 -
1202 If \a pos is beyond the end of the array, nothing happens. -
1203 -
1204 Example: -
1205 \snippet code/src_corelib_tools_qbytearray.cpp 10 -
1206 -
1207 \sa chop(), resize(), left() -
1208*/ -
1209void QByteArray::truncate(int pos) -
1210{ -
1211 if (pos < d->size)
evaluated: pos < d->size
TRUEFALSE
yes
Evaluation Count:22579
yes
Evaluation Count:864
864-22579
1212 resize(pos);
executed: resize(pos);
Execution Count:22579
22579
1213}
executed: }
Execution Count:23443
23443
1214 -
1215/*! -
1216 -
1217 Removes \a n bytes from the end of the byte array. -
1218 -
1219 If \a n is greater than size(), the result is an empty byte -
1220 array. -
1221 -
1222 Example: -
1223 \snippet code/src_corelib_tools_qbytearray.cpp 11 -
1224 -
1225 \sa truncate(), resize(), left() -
1226*/ -
1227 -
1228void QByteArray::chop(int n) -
1229{ -
1230 if (n > 0)
evaluated: n > 0
TRUEFALSE
yes
Evaluation Count:4094
yes
Evaluation Count:1
1-4094
1231 resize(d->size - n);
executed: resize(d->size - n);
Execution Count:4094
4094
1232}
executed: }
Execution Count:4095
4095
1233 -
1234 -
1235/*! \fn QByteArray &QByteArray::operator+=(const QByteArray &ba) -
1236 -
1237 Appends the byte array \a ba onto the end of this byte array and -
1238 returns a reference to this byte array. -
1239 -
1240 Example: -
1241 \snippet code/src_corelib_tools_qbytearray.cpp 12 -
1242 -
1243 Note: QByteArray is an \l{implicitly shared} class. Consequently, -
1244 if \e this is an empty QByteArray, then \e this will just share -
1245 the data held in \a ba. In this case, no copying of data is done, -
1246 taking \l{constant time}. If a shared instance is modified, it will -
1247 be copied (copy-on-write), taking \l{linear time}. -
1248 -
1249 If \e this is not an empty QByteArray, a deep copy of the data is -
1250 performed, taking \l{linear time}. -
1251 -
1252 This operation typically does not suffer from allocation overhead, -
1253 because QByteArray preallocates extra space at the end of the data -
1254 so that it may grow without reallocating for each append operation. -
1255 -
1256 \sa append(), prepend() -
1257*/ -
1258 -
1259/*! \fn QByteArray &QByteArray::operator+=(const QString &str) -
1260 -
1261 \overload -
1262 -
1263 Appends the string \a str onto the end of this byte array and -
1264 returns a reference to this byte array. The Unicode data is -
1265 converted into 8-bit characters using QString::toUtf8(). -
1266 -
1267 If the QString contains non-ASCII Unicode characters, using this -
1268 operator can lead to loss of information. You can disable this -
1269 operator by defining \c QT_NO_CAST_TO_ASCII when you compile your -
1270 applications. You then need to call QString::toUtf8() (or -
1271 QString::toLatin1() or QString::toUtf8() or QString::toLocal8Bit()) -
1272 explicitly if you want to convert the data to \c{const char *}. -
1273*/ -
1274 -
1275/*! \fn QByteArray &QByteArray::operator+=(const char *str) -
1276 -
1277 \overload -
1278 -
1279 Appends the string \a str onto the end of this byte array and -
1280 returns a reference to this byte array. -
1281*/ -
1282 -
1283/*! \fn QByteArray &QByteArray::operator+=(char ch) -
1284 -
1285 \overload -
1286 -
1287 Appends the character \a ch onto the end of this byte array and -
1288 returns a reference to this byte array. -
1289*/ -
1290 -
1291/*! \fn int QByteArray::length() const -
1292 -
1293 Same as size(). -
1294*/ -
1295 -
1296/*! \fn bool QByteArray::isNull() const -
1297 -
1298 Returns true if this byte array is null; otherwise returns false. -
1299 -
1300 Example: -
1301 \snippet code/src_corelib_tools_qbytearray.cpp 13 -
1302 -
1303 Qt makes a distinction between null byte arrays and empty byte -
1304 arrays for historical reasons. For most applications, what -
1305 matters is whether or not a byte array contains any data, -
1306 and this can be determined using isEmpty(). -
1307 -
1308 \sa isEmpty() -
1309*/ -
1310 -
1311/*! \fn QByteArray::QByteArray() -
1312 -
1313 Constructs an empty byte array. -
1314 -
1315 \sa isEmpty() -
1316*/ -
1317 -
1318/*! -
1319 Constructs a byte array containing the first \a size bytes of -
1320 array \a data. -
1321 -
1322 If \a data is 0, a null byte array is constructed. -
1323 -
1324 If \a size is negative, \a data is assumed to point to a nul-terminated -
1325 string and its length is determined dynamically. The terminating -
1326 nul-character is not considered part of the byte array. -
1327 -
1328 QByteArray makes a deep copy of the string data. -
1329 -
1330 \sa fromRawData() -
1331*/ -
1332 -
1333QByteArray::QByteArray(const char *data, int size) -
1334{ -
1335 if (!data) {
evaluated: !data
TRUEFALSE
yes
Evaluation Count:409689
yes
Evaluation Count:4815639
409689-4815639
1336 d = Data::sharedNull();
executed (the execution status of this line is deduced): d = Data::sharedNull();
-
1337 } else {
executed: }
Execution Count:409689
409689
1338 if (size < 0)
evaluated: size < 0
TRUEFALSE
yes
Evaluation Count:2113642
yes
Evaluation Count:2702018
2113642-2702018
1339 size = int(strlen(data));
executed: size = int(strlen(data));
Execution Count:2113642
2113642
1340 if (!size) {
evaluated: !size
TRUEFALSE
yes
Evaluation Count:5949
yes
Evaluation Count:4809697
5949-4809697
1341 d = Data::allocate(0);
executed (the execution status of this line is deduced): d = Data::allocate(0);
-
1342 } else {
executed: }
Execution Count:5949
5949
1343 d = Data::allocate(uint(size) + 1u);
executed (the execution status of this line is deduced): d = Data::allocate(uint(size) + 1u);
-
1344 Q_CHECK_PTR(d);
never executed: qBadAlloc();
executed: }
Execution Count:4809715
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4809722
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4809712
0-4809722
1345 d->size = size;
executed (the execution status of this line is deduced): d->size = size;
-
1346 memcpy(d->data(), data, size);
executed (the execution status of this line is deduced): memcpy(d->data(), data, size);
-
1347 d->data()[size] = '\0';
executed (the execution status of this line is deduced): d->data()[size] = '\0';
-
1348 }
executed: }
Execution Count:4809711
4809711
1349 } -
1350} -
1351 -
1352/*! -
1353 Constructs a byte array of size \a size with every byte set to -
1354 character \a ch. -
1355 -
1356 \sa fill() -
1357*/ -
1358 -
1359QByteArray::QByteArray(int size, char ch) -
1360{ -
1361 if (size <= 0) {
evaluated: size <= 0
TRUEFALSE
yes
Evaluation Count:1198
yes
Evaluation Count:757287
1198-757287
1362 d = Data::allocate(0);
executed (the execution status of this line is deduced): d = Data::allocate(0);
-
1363 } else {
executed: }
Execution Count:1198
1198
1364 d = Data::allocate(uint(size) + 1u);
executed (the execution status of this line is deduced): d = Data::allocate(uint(size) + 1u);
-
1365 Q_CHECK_PTR(d);
never executed: qBadAlloc();
executed: }
Execution Count:757287
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:757287
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:757287
0-757287
1366 d->size = size;
executed (the execution status of this line is deduced): d->size = size;
-
1367 memset(d->data(), ch, size);
executed (the execution status of this line is deduced): memset(d->data(), ch, size);
-
1368 d->data()[size] = '\0';
executed (the execution status of this line is deduced): d->data()[size] = '\0';
-
1369 }
executed: }
Execution Count:757287
757287
1370} -
1371 -
1372/*! -
1373 \internal -
1374 -
1375 Constructs a byte array of size \a size with uninitialized contents. -
1376*/ -
1377 -
1378QByteArray::QByteArray(int size, Qt::Initialization) -
1379{ -
1380 d = Data::allocate(uint(size) + 1u);
executed (the execution status of this line is deduced): d = Data::allocate(uint(size) + 1u);
-
1381 Q_CHECK_PTR(d);
never executed: qBadAlloc();
executed: }
Execution Count:1644475
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1644476
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1644475
0-1644476
1382 d->size = size;
executed (the execution status of this line is deduced): d->size = size;
-
1383 d->data()[size] = '\0';
executed (the execution status of this line is deduced): d->data()[size] = '\0';
-
1384}
executed: }
Execution Count:1644476
1644476
1385 -
1386/*! -
1387 Sets the size of the byte array to \a size bytes. -
1388 -
1389 If \a size is greater than the current size, the byte array is -
1390 extended to make it \a size bytes with the extra bytes added to -
1391 the end. The new bytes are uninitialized. -
1392 -
1393 If \a size is less than the current size, bytes are removed from -
1394 the end. -
1395 -
1396 \sa size(), truncate() -
1397*/ -
1398void QByteArray::resize(int size) -
1399{ -
1400 if (size < 0)
evaluated: size < 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:26058655
3-26058655
1401 size = 0;
executed: size = 0;
Execution Count:3
3
1402 -
1403 if (IS_RAW_DATA(d) && !d->ref.isShared() && size < d->size) {
evaluated: ((d)->offset != sizeof(QByteArrayData))
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:26058641
evaluated: !d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:14
partially evaluated: size < d->size
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-26058641
1404 d->size = size;
executed (the execution status of this line is deduced): d->size = size;
-
1405 return;
executed: return;
Execution Count:1
1
1406 } -
1407 -
1408 if (size == 0 && !d->capacityReserved) {
evaluated: size == 0
TRUEFALSE
yes
Evaluation Count:142782
yes
Evaluation Count:25915878
evaluated: !d->capacityReserved
TRUEFALSE
yes
Evaluation Count:142781
yes
Evaluation Count:1
1-25915878
1409 Data *x = Data::allocate(0);
executed (the execution status of this line is deduced): Data *x = Data::allocate(0);
-
1410 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:81207
yes
Evaluation Count:61576
61576-81207
1411 Data::deallocate(d);
executed: Data::deallocate(d);
Execution Count:81206
81206
1412 d = x;
executed (the execution status of this line is deduced): d = x;
-
1413 } else if (d->size == 0 && d->ref.isStatic()) {
executed: }
Execution Count:142780
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:20236244
yes
Evaluation Count:5679645
evaluated: d->ref.isStatic()
TRUEFALSE
yes
Evaluation Count:19878665
yes
Evaluation Count:357581
142780-20236244
1414 // -
1415 // Optimize the idiom: -
1416 // QByteArray a; -
1417 // a.resize(sz); -
1418 // ... -
1419 // which is used in place of the Qt 3 idiom: -
1420 // QByteArray a(sz); -
1421 // -
1422 Data *x = Data::allocate(uint(size) + 1u);
executed (the execution status of this line is deduced): Data *x = Data::allocate(uint(size) + 1u);
-
1423 Q_CHECK_PTR(x);
never executed: qBadAlloc();
executed: }
Execution Count:19878671
partially evaluated: !(x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19878674
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19878670
0-19878674
1424 x->size = size;
executed (the execution status of this line is deduced): x->size = size;
-
1425 x->data()[size] = '\0';
executed (the execution status of this line is deduced): x->data()[size] = '\0';
-
1426 d = x;
executed (the execution status of this line is deduced): d = x;
-
1427 } else {
executed: }
Execution Count:19878673
19878673
1428 if (d->ref.isShared() || uint(size) + 1u > d->alloc
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:193
yes
Evaluation Count:6037032
evaluated: uint(size) + 1u > d->alloc
TRUEFALSE
yes
Evaluation Count:1584077
yes
Evaluation Count:4452956
193-6037032
1429 || (!d->capacityReserved && size < d->size
evaluated: !d->capacityReserved
TRUEFALSE
yes
Evaluation Count:3510760
yes
Evaluation Count:942196
evaluated: size < d->size
TRUEFALSE
yes
Evaluation Count:2531109
yes
Evaluation Count:979650
942196-3510760
1430 && uint(size) + 1u < uint(d->alloc >> 1)))
evaluated: uint(size) + 1u < uint(d->alloc >> 1)
TRUEFALSE
yes
Evaluation Count:1845990
yes
Evaluation Count:685120
685120-1845990
1431 reallocData(uint(size) + 1u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(size) + 1u, d->detachFlags() | Data::Grow);
Execution Count:3430260
3430260
1432 if (d->alloc) {
partially evaluated: d->alloc
TRUEFALSE
yes
Evaluation Count:6037226
no
Evaluation Count:0
0-6037226
1433 d->size = size;
executed (the execution status of this line is deduced): d->size = size;
-
1434 d->data()[size] = '\0';
executed (the execution status of this line is deduced): d->data()[size] = '\0';
-
1435 }
executed: }
Execution Count:6037226
6037226
1436 }
executed: }
Execution Count:6037226
6037226
1437} -
1438 -
1439/*! -
1440 Sets every byte in the byte array to character \a ch. If \a size -
1441 is different from -1 (the default), the byte array is resized to -
1442 size \a size beforehand. -
1443 -
1444 Example: -
1445 \snippet code/src_corelib_tools_qbytearray.cpp 14 -
1446 -
1447 \sa resize() -
1448*/ -
1449 -
1450QByteArray &QByteArray::fill(char ch, int size) -
1451{ -
1452 resize(size < 0 ? d->size : size);
executed (the execution status of this line is deduced): resize(size < 0 ? d->size : size);
-
1453 if (d->size)
partially evaluated: d->size
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
1454 memset(d->data(), ch, d->size);
executed: memset(d->data(), ch, d->size);
Execution Count:4
4
1455 return *this;
executed: return *this;
Execution Count:4
4
1456} -
1457 -
1458void QByteArray::reallocData(uint alloc, Data::AllocationOptions options) -
1459{ -
1460 if (d->ref.isShared() || IS_RAW_DATA(d)) {
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:2558049
yes
Evaluation Count:4035616
evaluated: ((d)->offset != sizeof(QByteArrayData))
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:4035610
5-4035616
1461 Data *x = Data::allocate(alloc, options);
executed (the execution status of this line is deduced): Data *x = Data::allocate(alloc, options);
-
1462 Q_CHECK_PTR(x);
never executed: qBadAlloc();
executed: }
Execution Count:2558085
partially evaluated: !(x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2558094
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2558083
0-2558094
1463 x->size = qMin(int(alloc) - 1, d->size);
executed (the execution status of this line is deduced): x->size = qMin(int(alloc) - 1, d->size);
-
1464 ::memcpy(x->data(), d->data(), x->size);
executed (the execution status of this line is deduced): ::memcpy(x->data(), d->data(), x->size);
-
1465 x->data()[x->size] = '\0';
executed (the execution status of this line is deduced): x->data()[x->size] = '\0';
-
1466 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:2558098
5-2558098
1467 Data::deallocate(d);
executed: Data::deallocate(d);
Execution Count:5
5
1468 d = x;
executed (the execution status of this line is deduced): d = x;
-
1469 } else {
executed: }
Execution Count:2558101
2558101
1470 if (options & Data::Grow)
evaluated: options & Data::Grow
TRUEFALSE
yes
Evaluation Count:3932580
yes
Evaluation Count:103025
103025-3932580
1471 alloc = qAllocMore(alloc, sizeof(Data));
executed: alloc = qAllocMore(alloc, sizeof(Data));
Execution Count:3932585
3932585
1472 Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc));
executed (the execution status of this line is deduced): Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc));
-
1473 Q_CHECK_PTR(x);
never executed: qBadAlloc();
executed: }
Execution Count:4035615
partially evaluated: !(x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4035615
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4035616
0-4035616
1474 x->alloc = alloc;
executed (the execution status of this line is deduced): x->alloc = alloc;
-
1475 x->capacityReserved = (options & Data::CapacityReserved) ? 1 : 0;
evaluated: (options & Data::CapacityReserved)
TRUEFALSE
yes
Evaluation Count:12708
yes
Evaluation Count:4022908
12708-4022908
1476 d = x;
executed (the execution status of this line is deduced): d = x;
-
1477 }
executed: }
Execution Count:4035613
4035613
1478} -
1479 -
1480void QByteArray::expand(int i) -
1481{ -
1482 resize(qMax(i + 1, d->size));
executed (the execution status of this line is deduced): resize(qMax(i + 1, d->size));
-
1483}
executed: }
Execution Count:940294
940294
1484 -
1485/*! -
1486 \internal -
1487 Return a QByteArray that is sure to be NUL-terminated. -
1488 -
1489 By default, all QByteArray have an extra NUL at the end, -
1490 guaranteeing that assumption. However, if QByteArray::fromRawData -
1491 is used, then the NUL is there only if the user put it there. We -
1492 can't be sure. -
1493*/ -
1494QByteArray QByteArray::nulTerminated() const -
1495{ -
1496 // is this fromRawData? -
1497 if (!IS_RAW_DATA(d))
evaluated: !((d)->offset != sizeof(QByteArrayData))
TRUEFALSE
yes
Evaluation Count:184567
yes
Evaluation Count:6
6-184567
1498 return *this; // no, then we're sure we're zero terminated
executed: return *this;
Execution Count:184567
184567
1499 -
1500 QByteArray copy(*this);
executed (the execution status of this line is deduced): QByteArray copy(*this);
-
1501 copy.detach();
executed (the execution status of this line is deduced): copy.detach();
-
1502 return copy;
executed: return copy;
Execution Count:6
6
1503} -
1504 -
1505/*! -
1506 Prepends the byte array \a ba to this byte array and returns a -
1507 reference to this byte array. -
1508 -
1509 Example: -
1510 \snippet code/src_corelib_tools_qbytearray.cpp 15 -
1511 -
1512 This is the same as insert(0, \a ba). -
1513 -
1514 Note: QByteArray is an \l{implicitly shared} class. Consequently, -
1515 if \e this is an empty QByteArray, then \e this will just share -
1516 the data held in \a ba. In this case, no copying of data is done, -
1517 taking \l{constant time}. If a shared instance is modified, it will -
1518 be copied (copy-on-write), taking \l{linear time}. -
1519 -
1520 If \e this is not an empty QByteArray, a deep copy of the data is -
1521 performed, taking \l{linear time}. -
1522 -
1523 \sa append(), insert() -
1524*/ -
1525 -
1526QByteArray &QByteArray::prepend(const QByteArray &ba) -
1527{ -
1528 if (d->size == 0 && d->ref.isStatic() && !IS_RAW_DATA(ba.d)) {
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:425
partially evaluated: d->ref.isStatic()
TRUEFALSE
yes
Evaluation Count:22
no
Evaluation Count:0
evaluated: !((ba.d)->offset != sizeof(QByteArrayData))
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:8
0-425
1529 *this = ba;
executed (the execution status of this line is deduced): *this = ba;
-
1530 } else if (ba.d->size != 0) {
executed: }
Execution Count:14
evaluated: ba.d->size != 0
TRUEFALSE
yes
Evaluation Count:300
yes
Evaluation Count:133
14-300
1531 QByteArray tmp = *this;
executed (the execution status of this line is deduced): QByteArray tmp = *this;
-
1532 *this = ba;
executed (the execution status of this line is deduced): *this = ba;
-
1533 append(tmp);
executed (the execution status of this line is deduced): append(tmp);
-
1534 }
executed: }
Execution Count:300
300
1535 return *this;
executed: return *this;
Execution Count:447
447
1536} -
1537 -
1538/*! -
1539 \overload -
1540 -
1541 Prepends the string \a str to this byte array. -
1542*/ -
1543 -
1544QByteArray &QByteArray::prepend(const char *str) -
1545{ -
1546 return prepend(str, qstrlen(str));
executed: return prepend(str, qstrlen(str));
Execution Count:1307
1307
1547} -
1548 -
1549/*! -
1550 \overload -
1551 \since 4.6 -
1552 -
1553 Prepends \a len bytes of the string \a str to this byte array. -
1554*/ -
1555 -
1556QByteArray &QByteArray::prepend(const char *str, int len) -
1557{ -
1558 if (str) {
evaluated: str
TRUEFALSE
yes
Evaluation Count:1307
yes
Evaluation Count:9
9-1307
1559 if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:182
yes
Evaluation Count:1125
evaluated: uint(d->size + len) + 1u > d->alloc
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:1087
38-1125
1560 reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
Execution Count:220
220
1561 memmove(d->data()+len, d->data(), d->size);
executed (the execution status of this line is deduced): memmove(d->data()+len, d->data(), d->size);
-
1562 memcpy(d->data(), str, len);
executed (the execution status of this line is deduced): memcpy(d->data(), str, len);
-
1563 d->size += len;
executed (the execution status of this line is deduced): d->size += len;
-
1564 d->data()[d->size] = '\0';
executed (the execution status of this line is deduced): d->data()[d->size] = '\0';
-
1565 }
executed: }
Execution Count:1307
1307
1566 return *this;
executed: return *this;
Execution Count:1316
1316
1567} -
1568 -
1569/*! -
1570 \overload -
1571 -
1572 Prepends the character \a ch to this byte array. -
1573*/ -
1574 -
1575QByteArray &QByteArray::prepend(char ch) -
1576{ -
1577 if (d->ref.isShared() || uint(d->size) + 2u > d->alloc)
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:664
evaluated: uint(d->size) + 2u > d->alloc
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:621
43-664
1578 reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow);
Execution Count:98
98
1579 memmove(d->data()+1, d->data(), d->size);
executed (the execution status of this line is deduced): memmove(d->data()+1, d->data(), d->size);
-
1580 d->data()[0] = ch;
executed (the execution status of this line is deduced): d->data()[0] = ch;
-
1581 ++d->size;
executed (the execution status of this line is deduced): ++d->size;
-
1582 d->data()[d->size] = '\0';
executed (the execution status of this line is deduced): d->data()[d->size] = '\0';
-
1583 return *this;
executed: return *this;
Execution Count:719
719
1584} -
1585 -
1586/*! -
1587 Appends the byte array \a ba onto the end of this byte array. -
1588 -
1589 Example: -
1590 \snippet code/src_corelib_tools_qbytearray.cpp 16 -
1591 -
1592 This is the same as insert(size(), \a ba). -
1593 -
1594 Note: QByteArray is an \l{implicitly shared} class. Consequently, -
1595 if \e this is an empty QByteArray, then \e this will just share -
1596 the data held in \a ba. In this case, no copying of data is done, -
1597 taking \l{constant time}. If a shared instance is modified, it will -
1598 be copied (copy-on-write), taking \l{linear time}. -
1599 -
1600 If \e this is not an empty QByteArray, a deep copy of the data is -
1601 performed, taking \l{linear time}. -
1602 -
1603 This operation typically does not suffer from allocation overhead, -
1604 because QByteArray preallocates extra space at the end of the data -
1605 so that it may grow without reallocating for each append operation. -
1606 -
1607 \sa operator+=(), prepend(), insert() -
1608*/ -
1609 -
1610QByteArray &QByteArray::append(const QByteArray &ba) -
1611{ -
1612 if (d->size == 0 && d->ref.isStatic() && !IS_RAW_DATA(ba.d)) {
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:229690
yes
Evaluation Count:5544704
evaluated: d->ref.isStatic()
TRUEFALSE
yes
Evaluation Count:208212
yes
Evaluation Count:21481
evaluated: !((ba.d)->offset != sizeof(QByteArrayData))
TRUEFALSE
yes
Evaluation Count:208172
yes
Evaluation Count:47
47-5544704
1613 *this = ba;
executed (the execution status of this line is deduced): *this = ba;
-
1614 } else if (ba.d->size != 0) {
executed: }
Execution Count:208178
evaluated: ba.d->size != 0
TRUEFALSE
yes
Evaluation Count:5366786
yes
Evaluation Count:199449
199449-5366786
1615 if (d->ref.isShared() || uint(d->size + ba.d->size) + 1u > d->alloc)
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:89346
yes
Evaluation Count:5277486
evaluated: uint(d->size + ba.d->size) + 1u > d->alloc
TRUEFALSE
yes
Evaluation Count:407197
yes
Evaluation Count:4870289
89346-5277486
1616 reallocData(uint(d->size + ba.d->size) + 1u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(d->size + ba.d->size) + 1u, d->detachFlags() | Data::Grow);
Execution Count:496544
496544
1617 memcpy(d->data() + d->size, ba.d->data(), ba.d->size);
executed (the execution status of this line is deduced): memcpy(d->data() + d->size, ba.d->data(), ba.d->size);
-
1618 d->size += ba.d->size;
executed (the execution status of this line is deduced): d->size += ba.d->size;
-
1619 d->data()[d->size] = '\0';
executed (the execution status of this line is deduced): d->data()[d->size] = '\0';
-
1620 }
executed: }
Execution Count:5366799
5366799
1621 return *this;
executed: return *this;
Execution Count:5774409
5774409
1622} -
1623 -
1624/*! \fn QByteArray &QByteArray::append(const QString &str) -
1625 -
1626 \overload -
1627 -
1628 Appends the string \a str to this byte array. The Unicode data is -
1629 converted into 8-bit characters using QString::toUtf8(). -
1630 -
1631 If the QString contains non-ASCII Unicode characters, using this -
1632 function can lead to loss of information. You can disable this -
1633 function by defining \c QT_NO_CAST_TO_ASCII when you compile your -
1634 applications. You then need to call QString::toUtf8() (or -
1635 QString::toLatin1() or QString::toUtf8() or QString::toLocal8Bit()) -
1636 explicitly if you want to convert the data to \c{const char *}. -
1637*/ -
1638 -
1639/*! -
1640 \overload -
1641 -
1642 Appends the string \a str to this byte array. -
1643*/ -
1644 -
1645QByteArray& QByteArray::append(const char *str) -
1646{ -
1647 if (str) {
evaluated: str
TRUEFALSE
yes
Evaluation Count:2701205
yes
Evaluation Count:9
9-2701205
1648 const int len = int(strlen(str));
executed (the execution status of this line is deduced): const int len = int(strlen(str));
-
1649 if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:82095
yes
Evaluation Count:2619110
evaluated: uint(d->size + len) + 1u > d->alloc
TRUEFALSE
yes
Evaluation Count:2792
yes
Evaluation Count:2616318
2792-2619110
1650 reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
Execution Count:84887
84887
1651 memcpy(d->data() + d->size, str, len + 1); // include null terminator
executed (the execution status of this line is deduced): memcpy(d->data() + d->size, str, len + 1);
-
1652 d->size += len;
executed (the execution status of this line is deduced): d->size += len;
-
1653 }
executed: }
Execution Count:2701205
2701205
1654 return *this;
executed: return *this;
Execution Count:2701214
2701214
1655} -
1656 -
1657/*! -
1658 \overload append() -
1659 -
1660 Appends the first \a len characters of the string \a str to this byte -
1661 array and returns a reference to this byte array. -
1662 -
1663 If \a len is negative, the length of the string will be determined -
1664 automatically using qstrlen(). If \a len is zero or \a str is -
1665 null, nothing is appended to the byte array. Ensure that \a len is -
1666 \e not longer than \a str. -
1667*/ -
1668 -
1669QByteArray &QByteArray::append(const char *str, int len) -
1670{ -
1671 if (len < 0)
partially evaluated: len < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:442116
0-442116
1672 len = qstrlen(str);
never executed: len = qstrlen(str);
0
1673 if (str && len) {
partially evaluated: str
TRUEFALSE
yes
Evaluation Count:442116
no
Evaluation Count:0
partially evaluated: len
TRUEFALSE
yes
Evaluation Count:442116
no
Evaluation Count:0
0-442116
1674 if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:442005
yes
Evaluation Count:111
evaluated: uint(d->size + len) + 1u > d->alloc
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:103
8-442005
1675 reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
Execution Count:442013
442013
1676 memcpy(d->data() + d->size, str, len); // include null terminator
executed (the execution status of this line is deduced): memcpy(d->data() + d->size, str, len);
-
1677 d->size += len;
executed (the execution status of this line is deduced): d->size += len;
-
1678 d->data()[d->size] = '\0';
executed (the execution status of this line is deduced): d->data()[d->size] = '\0';
-
1679 }
executed: }
Execution Count:442116
442116
1680 return *this;
executed: return *this;
Execution Count:442116
442116
1681} -
1682 -
1683/*! -
1684 \overload -
1685 -
1686 Appends the character \a ch to this byte array. -
1687*/ -
1688 -
1689QByteArray& QByteArray::append(char ch) -
1690{ -
1691 if (d->ref.isShared() || uint(d->size) + 2u > d->alloc)
evaluated: d->ref.isShared()
TRUEFALSE
yes
Evaluation Count:54361
yes
Evaluation Count:29725917
evaluated: uint(d->size) + 2u > d->alloc
TRUEFALSE
yes
Evaluation Count:92444
yes
Evaluation Count:29633550
54361-29725917
1692 reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow);
executed: reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow);
Execution Count:146805
146805
1693 d->data()[d->size++] = ch;
executed (the execution status of this line is deduced): d->data()[d->size++] = ch;
-
1694 d->data()[d->size] = '\0';
executed (the execution status of this line is deduced): d->data()[d->size] = '\0';
-
1695 return *this;
executed: return *this;
Execution Count:29780233
29780233
1696} -
1697 -
1698/*! -
1699 \internal -
1700 Inserts \a len bytes from the array \a arr at position \a pos and returns a -
1701 reference the modified byte array. -
1702*/ -
1703static inline QByteArray &qbytearray_insert(QByteArray *ba, -
1704 int pos, const char *arr, int len) -
1705{ -
1706 Q_ASSERT(pos >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
1707 -
1708 if (pos < 0 || len <= 0 || arr == 0)
partially evaluated: pos < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:119325
partially evaluated: len <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:119325
partially evaluated: arr == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:119325
0-119325
1709 return *ba;
never executed: return *ba;
0
1710 -
1711 int oldsize = ba->size();
executed (the execution status of this line is deduced): int oldsize = ba->size();
-
1712 ba->resize(qMax(pos, oldsize) + len);
executed (the execution status of this line is deduced): ba->resize(qMax(pos, oldsize) + len);
-
1713 char *dst = ba->data();
executed (the execution status of this line is deduced): char *dst = ba->data();
-
1714 if (pos > oldsize)
evaluated: pos > oldsize
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:119323
2-119323
1715 ::memset(dst + oldsize, 0x20, pos - oldsize);
executed: ::memset(dst + oldsize, 0x20, pos - oldsize);
Execution Count:2
2
1716 else -
1717 ::memmove(dst + pos + len, dst + pos, oldsize - pos);
executed: ::memmove(dst + pos + len, dst + pos, oldsize - pos);
Execution Count:119323
119323
1718 memcpy(dst + pos, arr, len);
executed (the execution status of this line is deduced): memcpy(dst + pos, arr, len);
-
1719 return *ba;
executed: return *ba;
Execution Count:119325
119325
1720} -
1721 -
1722/*! -
1723 Inserts the byte array \a ba at index position \a i and returns a -
1724 reference to this byte array. -
1725 -
1726 Example: -
1727 \snippet code/src_corelib_tools_qbytearray.cpp 17 -
1728 -
1729 \sa append(), prepend(), replace(), remove() -
1730*/ -
1731 -
1732QByteArray &QByteArray::insert(int i, const QByteArray &ba) -
1733{ -
1734 QByteArray copy(ba);
executed (the execution status of this line is deduced): QByteArray copy(ba);
-
1735 return qbytearray_insert(this, i, copy.d->data(), copy.d->size);
executed: return qbytearray_insert(this, i, copy.d->data(), copy.d->size);
Execution Count:12
12
1736} -
1737 -
1738/*! -
1739 \fn QByteArray &QByteArray::insert(int i, const QString &str) -
1740 -
1741 \overload -
1742 -
1743 Inserts the string \a str at index position \a i in the byte -
1744 array. The Unicode data is converted into 8-bit characters using -
1745 QString::toUtf8(). -
1746 -
1747 If \a i is greater than size(), the array is first extended using -
1748 resize(). -
1749 -
1750 You can disable this function by defining \c QT_NO_CAST_TO_ASCII when you -
1751 compile your applications. You then need to call QString::toUtf8() (or -
1752 QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to -
1753 convert the data to \c{const char *}. -
1754*/ -
1755 -
1756/*! -
1757 \overload -
1758 -
1759 Inserts the string \a str at position \a i in the byte array. -
1760 -
1761 If \a i is greater than size(), the array is first extended using -
1762 resize(). -
1763*/ -
1764 -
1765QByteArray &QByteArray::insert(int i, const char *str) -
1766{ -
1767 return qbytearray_insert(this, i, str, qstrlen(str));
executed: return qbytearray_insert(this, i, str, qstrlen(str));
Execution Count:14
14
1768} -
1769 -
1770/*! -
1771 \overload -
1772 \since 4.6 -
1773 -
1774 Inserts \a len bytes of the string \a str at position -
1775 \a i in the byte array. -
1776 -
1777 If \a i is greater than size(), the array is first extended using -
1778 resize(). -
1779*/ -
1780 -
1781QByteArray &QByteArray::insert(int i, const char *str, int len) -
1782{ -
1783 return qbytearray_insert(this, i, str, len);
executed: return qbytearray_insert(this, i, str, len);
Execution Count:1
1
1784} -
1785 -
1786/*! -
1787 \overload -
1788 -
1789 Inserts character \a ch at index position \a i in the byte array. -
1790 If \a i is greater than size(), the array is first extended using -
1791 resize(). -
1792*/ -
1793 -
1794QByteArray &QByteArray::insert(int i, char ch) -
1795{ -
1796 return qbytearray_insert(this, i, &ch, 1);
executed: return qbytearray_insert(this, i, &ch, 1);
Execution Count:2356
2356
1797} -
1798 -
1799/*! -
1800 Removes \a len bytes from the array, starting at index position \a -
1801 pos, and returns a reference to the array. -
1802 -
1803 If \a pos is out of range, nothing happens. If \a pos is valid, -
1804 but \a pos + \a len is larger than the size of the array, the -
1805 array is truncated at position \a pos. -
1806 -
1807 Example: -
1808 \snippet code/src_corelib_tools_qbytearray.cpp 18 -
1809 -
1810 \sa insert(), replace() -
1811*/ -
1812 -
1813QByteArray &QByteArray::remove(int pos, int len) -
1814{ -
1815 if (len <= 0 || pos >= d->size || pos < 0)
evaluated: len <= 0
TRUEFALSE
yes
Evaluation Count:63
yes
Evaluation Count:263576
evaluated: pos >= d->size
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:263573
partially evaluated: pos < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:263573
0-263576
1816 return *this;
executed: return *this;
Execution Count:66
66
1817 detach();
executed (the execution status of this line is deduced): detach();
-
1818 if (pos + len >= d->size) {
evaluated: pos + len >= d->size
TRUEFALSE
yes
Evaluation Count:797
yes
Evaluation Count:262776
797-262776
1819 resize(pos);
executed (the execution status of this line is deduced): resize(pos);
-
1820 } else {
executed: }
Execution Count:797
797
1821 memmove(d->data() + pos, d->data() + pos + len, d->size - pos - len);
executed (the execution status of this line is deduced): memmove(d->data() + pos, d->data() + pos + len, d->size - pos - len);
-
1822 resize(d->size - len);
executed (the execution status of this line is deduced): resize(d->size - len);
-
1823 }
executed: }
Execution Count:262776
262776
1824 return *this;
executed: return *this;
Execution Count:263573
263573
1825} -
1826 -
1827/*! -
1828 Replaces \a len bytes from index position \a pos with the byte -
1829 array \a after, and returns a reference to this byte array. -
1830 -
1831 Example: -
1832 \snippet code/src_corelib_tools_qbytearray.cpp 19 -
1833 -
1834 \sa insert(), remove() -
1835*/ -
1836 -
1837QByteArray &QByteArray::replace(int pos, int len, const QByteArray &after) -
1838{ -
1839 if (len == after.d->size && (pos + len <= d->size)) {
evaluated: len == after.d->size
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:8
evaluated: (pos + len <= d->size)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
1-8
1840 detach();
executed (the execution status of this line is deduced): detach();
-
1841 memmove(d->data() + pos, after.d->data(), len*sizeof(char));
executed (the execution status of this line is deduced): memmove(d->data() + pos, after.d->data(), len*sizeof(char));
-
1842 return *this;
executed: return *this;
Execution Count:2
2
1843 } else { -
1844 QByteArray copy(after);
executed (the execution status of this line is deduced): QByteArray copy(after);
-
1845 // ### optimize me -
1846 remove(pos, len);
executed (the execution status of this line is deduced): remove(pos, len);
-
1847 return insert(pos, copy);
executed: return insert(pos, copy);
Execution Count:9
9
1848 } -
1849} -
1850 -
1851/*! \fn QByteArray &QByteArray::replace(int pos, int len, const char *after) -
1852 -
1853 \overload -
1854 -
1855 Replaces \a len bytes from index position \a pos with the zero terminated -
1856 string \a after. -
1857 -
1858 Notice: this can change the length of the byte array. -
1859*/ -
1860QByteArray &QByteArray::replace(int pos, int len, const char *after) -
1861{ -
1862 return replace(pos,len,after,qstrlen(after));
executed: return replace(pos,len,after,qstrlen(after));
Execution Count:116943
116943
1863} -
1864 -
1865/*! \fn QByteArray &QByteArray::replace(int pos, int len, const char *after, int alen) -
1866 -
1867 \overload -
1868 -
1869 Replaces \a len bytes from index position \a pos with \a alen bytes -
1870 from the string \a after. \a after is allowed to have '\\0' characters. -
1871 -
1872 \since 4.7 -
1873*/ -
1874QByteArray &QByteArray::replace(int pos, int len, const char *after, int alen) -
1875{ -
1876 if (len == alen && (pos + len <= d->size)) {
evaluated: len == alen
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:116941
evaluated: (pos + len <= d->size)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
1-116941
1877 detach();
executed (the execution status of this line is deduced): detach();
-
1878 memcpy(d->data() + pos, after, len*sizeof(char));
executed (the execution status of this line is deduced): memcpy(d->data() + pos, after, len*sizeof(char));
-
1879 return *this;
executed: return *this;
Execution Count:2
2
1880 } else { -
1881 remove(pos, len);
executed (the execution status of this line is deduced): remove(pos, len);
-
1882 return qbytearray_insert(this, pos, after, alen);
executed: return qbytearray_insert(this, pos, after, alen);
Execution Count:116942
116942
1883 } -
1884} -
1885 -
1886// ### optimize all other replace method, by offering -
1887// QByteArray::replace(const char *before, int blen, const char *after, int alen) -
1888 -
1889/*! -
1890 \overload -
1891 -
1892 Replaces every occurrence of the byte array \a before with the -
1893 byte array \a after. -
1894 -
1895 Example: -
1896 \snippet code/src_corelib_tools_qbytearray.cpp 20 -
1897*/ -
1898 -
1899QByteArray &QByteArray::replace(const QByteArray &before, const QByteArray &after) -
1900{ -
1901 if (isNull() || before.d == after.d)
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: before.d == after.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1902 return *this;
never executed: return *this;
0
1903 -
1904 QByteArray aft = after;
executed (the execution status of this line is deduced): QByteArray aft = after;
-
1905 if (after.d == d)
evaluated: after.d == d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
1-2
1906 aft.detach();
executed: aft.detach();
Execution Count:2
2
1907 -
1908 return replace(before.constData(), before.size(), aft.constData(), aft.size());
executed: return replace(before.constData(), before.size(), aft.constData(), aft.size());
Execution Count:3
3
1909} -
1910 -
1911/*! -
1912 \fn QByteArray &QByteArray::replace(const char *before, const QByteArray &after) -
1913 \overload -
1914 -
1915 Replaces every occurrence of the string \a before with the -
1916 byte array \a after. -
1917*/ -
1918 -
1919QByteArray &QByteArray::replace(const char *c, const QByteArray &after) -
1920{ -
1921 QByteArray aft = after;
never executed (the execution status of this line is deduced): QByteArray aft = after;
-
1922 if (after.d == d)
never evaluated: after.d == d
0
1923 aft.detach();
never executed: aft.detach();
0
1924 -
1925 return replace(c, qstrlen(c), aft.constData(), aft.size());
never executed: return replace(c, qstrlen(c), aft.constData(), aft.size());
0
1926} -
1927 -
1928/*! -
1929 \fn QByteArray &QByteArray::replace(const char *before, int bsize, const char *after, int asize) -
1930 \overload -
1931 -
1932 Replaces every occurrence of the string \a before with the string \a after. -
1933 Since the sizes of the strings are given by \a bsize and \a asize, they -
1934 may contain zero characters and do not need to be zero-terminated. -
1935*/ -
1936 -
1937QByteArray &QByteArray::replace(const char *before, int bsize, const char *after, int asize) -
1938{ -
1939 if (isNull() || (before == after && bsize == asize))
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:1778
partially evaluated: before == after
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1778
never evaluated: bsize == asize
0-1778
1940 return *this;
executed: return *this;
Execution Count:21
21
1941 -
1942 // protect against before or after being part of this -
1943 const char *a = after;
executed (the execution status of this line is deduced): const char *a = after;
-
1944 const char *b = before;
executed (the execution status of this line is deduced): const char *b = before;
-
1945 if (after >= d->data() && after < d->data() + d->size) {
evaluated: after >= d->data()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1777
partially evaluated: after < d->data() + d->size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1777
1946 char *copy = (char *)malloc(asize);
never executed (the execution status of this line is deduced): char *copy = (char *)malloc(asize);
-
1947 Q_CHECK_PTR(copy);
never executed: qBadAlloc();
never executed: }
never evaluated: !(copy)
never evaluated: 0
0
1948 memcpy(copy, after, asize);
never executed (the execution status of this line is deduced): memcpy(copy, after, asize);
-
1949 a = copy;
never executed (the execution status of this line is deduced): a = copy;
-
1950 }
never executed: }
0
1951 if (before >= d->data() && before < d->data() + d->size) {
partially evaluated: before >= d->data()
TRUEFALSE
yes
Evaluation Count:1778
no
Evaluation Count:0
evaluated: before < d->data() + d->size
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1776
0-1778
1952 char *copy = (char *)malloc(bsize);
executed (the execution status of this line is deduced): char *copy = (char *)malloc(bsize);
-
1953 Q_CHECK_PTR(copy);
never executed: qBadAlloc();
executed: }
Execution Count:2
partially evaluated: !(copy)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
1954 memcpy(copy, before, bsize);
executed (the execution status of this line is deduced): memcpy(copy, before, bsize);
-
1955 b = copy;
executed (the execution status of this line is deduced): b = copy;
-
1956 }
executed: }
Execution Count:2
2
1957 -
1958 QByteArrayMatcher matcher(before, bsize);
executed (the execution status of this line is deduced): QByteArrayMatcher matcher(before, bsize);
-
1959 int index = 0;
executed (the execution status of this line is deduced): int index = 0;
-
1960 int len = d->size;
executed (the execution status of this line is deduced): int len = d->size;
-
1961 char *d = data();
executed (the execution status of this line is deduced): char *d = data();
-
1962 -
1963 if (bsize == asize) {
evaluated: bsize == asize
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1777
1-1777
1964 if (bsize) {
partially evaluated: bsize
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1965 while ((index = matcher.indexIn(*this, index)) != -1) {
evaluated: (index = matcher.indexIn(*this, index)) != -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
1966 memcpy(d + index, after, asize);
executed (the execution status of this line is deduced): memcpy(d + index, after, asize);
-
1967 index += bsize;
executed (the execution status of this line is deduced): index += bsize;
-
1968 }
executed: }
Execution Count:1
1
1969 }
executed: }
Execution Count:1
1
1970 } else if (asize < bsize) {
executed: }
Execution Count:1
evaluated: asize < bsize
TRUEFALSE
yes
Evaluation Count:1775
yes
Evaluation Count:2
1-1775
1971 uint to = 0;
executed (the execution status of this line is deduced): uint to = 0;
-
1972 uint movestart = 0;
executed (the execution status of this line is deduced): uint movestart = 0;
-
1973 uint num = 0;
executed (the execution status of this line is deduced): uint num = 0;
-
1974 while ((index = matcher.indexIn(*this, index)) != -1) {
evaluated: (index = matcher.indexIn(*this, index)) != -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1775
1-1775
1975 if (num) {
partially evaluated: num
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1976 int msize = index - movestart;
never executed (the execution status of this line is deduced): int msize = index - movestart;
-
1977 if (msize > 0) {
never evaluated: msize > 0
0
1978 memmove(d + to, d + movestart, msize);
never executed (the execution status of this line is deduced): memmove(d + to, d + movestart, msize);
-
1979 to += msize;
never executed (the execution status of this line is deduced): to += msize;
-
1980 }
never executed: }
0
1981 } else {
never executed: }
0
1982 to = index;
executed (the execution status of this line is deduced): to = index;
-
1983 }
executed: }
Execution Count:1
1
1984 if (asize) {
partially evaluated: asize
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1985 memcpy(d + to, after, asize);
executed (the execution status of this line is deduced): memcpy(d + to, after, asize);
-
1986 to += asize;
executed (the execution status of this line is deduced): to += asize;
-
1987 }
executed: }
Execution Count:1
1
1988 index += bsize;
executed (the execution status of this line is deduced): index += bsize;
-
1989 movestart = index;
executed (the execution status of this line is deduced): movestart = index;
-
1990 num++;
executed (the execution status of this line is deduced): num++;
-
1991 }
executed: }
Execution Count:1
1
1992 if (num) {
evaluated: num
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1774
1-1774
1993 int msize = len - movestart;
executed (the execution status of this line is deduced): int msize = len - movestart;
-
1994 if (msize > 0)
partially evaluated: msize > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1995 memmove(d + to, d + movestart, msize);
never executed: memmove(d + to, d + movestart, msize);
0
1996 resize(len - num*(bsize-asize));
executed (the execution status of this line is deduced): resize(len - num*(bsize-asize));
-
1997 }
executed: }
Execution Count:1
1
1998 } else {
executed: }
Execution Count:1775
1775
1999 // the most complex case. We don't want to lose performance by doing repeated -
2000 // copies and reallocs of the string. -
2001 while (index != -1) {
evaluated: index != -1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
2002 uint indices[4096];
executed (the execution status of this line is deduced): uint indices[4096];
-
2003 uint pos = 0;
executed (the execution status of this line is deduced): uint pos = 0;
-
2004 while(pos < 4095) {
partially evaluated: pos < 4095
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
2005 index = matcher.indexIn(*this, index);
executed (the execution status of this line is deduced): index = matcher.indexIn(*this, index);
-
2006 if (index == -1)
evaluated: index == -1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:6
2-6
2007 break;
executed: break;
Execution Count:2
2
2008 indices[pos++] = index;
executed (the execution status of this line is deduced): indices[pos++] = index;
-
2009 index += bsize;
executed (the execution status of this line is deduced): index += bsize;
-
2010 // avoid infinite loop -
2011 if (!bsize)
partially evaluated: !bsize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
2012 index++;
never executed: index++;
0
2013 }
executed: }
Execution Count:6
6
2014 if (!pos)
partially evaluated: !pos
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
2015 break;
never executed: break;
0
2016 -
2017 // we have a table of replacement positions, use them for fast replacing -
2018 int adjust = pos*(asize-bsize);
executed (the execution status of this line is deduced): int adjust = pos*(asize-bsize);
-
2019 // index has to be adjusted in case we get back into the loop above. -
2020 if (index != -1)
partially evaluated: index != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
2021 index += adjust;
never executed: index += adjust;
0
2022 int newlen = len + adjust;
executed (the execution status of this line is deduced): int newlen = len + adjust;
-
2023 int moveend = len;
executed (the execution status of this line is deduced): int moveend = len;
-
2024 if (newlen > len) {
partially evaluated: newlen > len
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
2025 resize(newlen);
executed (the execution status of this line is deduced): resize(newlen);
-
2026 len = newlen;
executed (the execution status of this line is deduced): len = newlen;
-
2027 }
executed: }
Execution Count:2
2
2028 d = this->d->data();
executed (the execution status of this line is deduced): d = this->d->data();
-
2029 -
2030 while(pos) {
evaluated: pos
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:2
2-6
2031 pos--;
executed (the execution status of this line is deduced): pos--;
-
2032 int movestart = indices[pos] + bsize;
executed (the execution status of this line is deduced): int movestart = indices[pos] + bsize;
-
2033 int insertstart = indices[pos] + pos*(asize-bsize);
executed (the execution status of this line is deduced): int insertstart = indices[pos] + pos*(asize-bsize);
-
2034 int moveto = insertstart + asize;
executed (the execution status of this line is deduced): int moveto = insertstart + asize;
-
2035 memmove(d + moveto, d + movestart, (moveend - movestart));
executed (the execution status of this line is deduced): memmove(d + moveto, d + movestart, (moveend - movestart));
-
2036 if (asize)
partially evaluated: asize
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
2037 memcpy(d + insertstart, after, asize);
executed: memcpy(d + insertstart, after, asize);
Execution Count:6
6
2038 moveend = movestart - bsize;
executed (the execution status of this line is deduced): moveend = movestart - bsize;
-
2039 }
executed: }
Execution Count:6
6
2040 }
executed: }
Execution Count:2
2
2041 }
executed: }
Execution Count:2
2
2042 -
2043 if (a != after)
partially evaluated: a != after
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1778
0-1778
2044 ::free((char *)a);
never executed: ::free((char *)a);
0
2045 if (b != before)
evaluated: b != before
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1776
2-1776
2046 ::free((char *)b);
executed: ::free((char *)b);
Execution Count:2
2
2047 -
2048 -
2049 return *this;
executed: return *this;
Execution Count:1778
1778
2050} -
2051 -
2052 -
2053/*! -
2054 \fn QByteArray &QByteArray::replace(const QByteArray &before, const char *after) -
2055 \overload -
2056 -
2057 Replaces every occurrence of the byte array \a before with the -
2058 string \a after. -
2059*/ -
2060 -
2061/*! \fn QByteArray &QByteArray::replace(const QString &before, const QByteArray &after) -
2062 -
2063 \overload -
2064 -
2065 Replaces every occurrence of the string \a before with the byte -
2066 array \a after. The Unicode data is converted into 8-bit -
2067 characters using QString::toUtf8(). -
2068 -
2069 You can disable this function by defining \c QT_NO_CAST_TO_ASCII when you -
2070 compile your applications. You then need to call QString::toUtf8() (or -
2071 QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to -
2072 convert the data to \c{const char *}. -
2073*/ -
2074 -
2075/*! \fn QByteArray &QByteArray::replace(const QString &before, const char *after) -
2076 \overload -
2077 -
2078 Replaces every occurrence of the string \a before with the string -
2079 \a after. -
2080*/ -
2081 -
2082/*! \fn QByteArray &QByteArray::replace(const char *before, const char *after) -
2083 -
2084 \overload -
2085 -
2086 Replaces every occurrence of the string \a before with the string -
2087 \a after. -
2088*/ -
2089 -
2090/*! -
2091 \overload -
2092 -
2093 Replaces every occurrence of the character \a before with the -
2094 byte array \a after. -
2095*/ -
2096 -
2097QByteArray &QByteArray::replace(char before, const QByteArray &after) -
2098{ -
2099 char b[2] = { before, '\0' };
executed (the execution status of this line is deduced): char b[2] = { before, '\0' };
-
2100 QByteArray cb = fromRawData(b, 1);
executed (the execution status of this line is deduced): QByteArray cb = fromRawData(b, 1);
-
2101 return replace(cb, after);
executed: return replace(cb, after);
Execution Count:2
2
2102} -
2103 -
2104/*! \fn QByteArray &QByteArray::replace(char before, const QString &after) -
2105 -
2106 \overload -
2107 -
2108 Replaces every occurrence of the character \a before with the -
2109 string \a after. The Unicode data is converted into 8-bit -
2110 characters using QString::toUtf8(). -
2111 -
2112 If the QString contains non-ASCII Unicode characters, using this -
2113 function can lead to loss of information. You can disable this -
2114 function by defining \c QT_NO_CAST_TO_ASCII when you compile your -
2115 applications. You then need to call QString::toUtf8() (or -
2116 QString::toLatin1() or QString::toUtf8() or QString::toLocal8Bit()) -
2117 explicitly if you want to convert the data to \c{const char *}. -
2118*/ -
2119 -
2120/*! \fn QByteArray &QByteArray::replace(char before, const char *after) -
2121 -
2122 \overload -
2123 -
2124 Replaces every occurrence of the character \a before with the -
2125 string \a after. -
2126*/ -
2127 -
2128/*! -
2129 \overload -
2130 -
2131 Replaces every occurrence of the character \a before with the -
2132 character \a after. -
2133*/ -
2134 -
2135QByteArray &QByteArray::replace(char before, char after) -
2136{ -
2137 if (d->size) {
partially evaluated: d->size
TRUEFALSE
yes
Evaluation Count:15990379
no
Evaluation Count:0
0-15990379
2138 char *i = data();
executed (the execution status of this line is deduced): char *i = data();
-
2139 char *e = i + d->size;
executed (the execution status of this line is deduced): char *e = i + d->size;
-
2140 for (; i != e; ++i)
evaluated: i != e
TRUEFALSE
yes
Evaluation Count:18150180
yes
Evaluation Count:15990380
15990380-18150180
2141 if (*i == before)
evaluated: *i == before
TRUEFALSE
yes
Evaluation Count:1036
yes
Evaluation Count:18149145
1036-18149145
2142 * i = after;
executed: * i = after;
Execution Count:1036
1036
2143 }
executed: }
Execution Count:15990382
15990382
2144 return *this;
executed: return *this;
Execution Count:15990382
15990382
2145} -
2146 -
2147/*! -
2148 Splits the byte array into subarrays wherever \a sep occurs, and -
2149 returns the list of those arrays. If \a sep does not match -
2150 anywhere in the byte array, split() returns a single-element list -
2151 containing this byte array. -
2152*/ -
2153 -
2154QList<QByteArray> QByteArray::split(char sep) const -
2155{ -
2156 QList<QByteArray> list;
executed (the execution status of this line is deduced): QList<QByteArray> list;
-
2157 int start = 0;
executed (the execution status of this line is deduced): int start = 0;
-
2158 int end;
executed (the execution status of this line is deduced): int end;
-
2159 while ((end = indexOf(sep, start)) != -1) {
evaluated: (end = indexOf(sep, start)) != -1
TRUEFALSE
yes
Evaluation Count:588570
yes
Evaluation Count:225525
225525-588570
2160 list.append(mid(start, end - start));
executed (the execution status of this line is deduced): list.append(mid(start, end - start));
-
2161 start = end + 1;
executed (the execution status of this line is deduced): start = end + 1;
-
2162 }
executed: }
Execution Count:588570
588570
2163 list.append(mid(start));
executed (the execution status of this line is deduced): list.append(mid(start));
-
2164 return list;
executed: return list;
Execution Count:225525
225525
2165} -
2166 -
2167/*! -
2168 \since 4.5 -
2169 -
2170 Returns a copy of this byte array repeated the specified number of \a times. -
2171 -
2172 If \a times is less than 1, an empty byte array is returned. -
2173 -
2174 Example: -
2175 -
2176 \code -
2177 QByteArray ba("ab"); -
2178 ba.repeated(4); // returns "abababab" -
2179 \endcode -
2180*/ -
2181QByteArray QByteArray::repeated(int times) const -
2182{ -
2183 if (d->size == 0)
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:11
5-11
2184 return *this;
executed: return *this;
Execution Count:5
5
2185 -
2186 if (times <= 1) {
evaluated: times <= 1
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:7
4-7
2187 if (times == 1)
evaluated: times == 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
2188 return *this;
executed: return *this;
Execution Count:1
1
2189 return QByteArray();
executed: return QByteArray();
Execution Count:3
3
2190 } -
2191 -
2192 const int resultSize = times * d->size;
executed (the execution status of this line is deduced): const int resultSize = times * d->size;
-
2193 -
2194 QByteArray result;
executed (the execution status of this line is deduced): QByteArray result;
-
2195 result.reserve(resultSize);
executed (the execution status of this line is deduced): result.reserve(resultSize);
-
2196 if (result.d->alloc != uint(resultSize) + 1u)
partially evaluated: result.d->alloc != uint(resultSize) + 1u
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
2197 return QByteArray(); // not enough memory
never executed: return QByteArray();
0
2198 -
2199 memcpy(result.d->data(), d->data(), d->size);
executed (the execution status of this line is deduced): memcpy(result.d->data(), d->data(), d->size);
-
2200 -
2201 int sizeSoFar = d->size;
executed (the execution status of this line is deduced): int sizeSoFar = d->size;
-
2202 char *end = result.d->data() + sizeSoFar;
executed (the execution status of this line is deduced): char *end = result.d->data() + sizeSoFar;
-
2203 -
2204 const int halfResultSize = resultSize >> 1;
executed (the execution status of this line is deduced): const int halfResultSize = resultSize >> 1;
-
2205 while (sizeSoFar <= halfResultSize) {
evaluated: sizeSoFar <= halfResultSize
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:7
7-12
2206 memcpy(end, result.d->data(), sizeSoFar);
executed (the execution status of this line is deduced): memcpy(end, result.d->data(), sizeSoFar);
-
2207 end += sizeSoFar;
executed (the execution status of this line is deduced): end += sizeSoFar;
-
2208 sizeSoFar <<= 1;
executed (the execution status of this line is deduced): sizeSoFar <<= 1;
-
2209 }
executed: }
Execution Count:12
12
2210 memcpy(end, result.d->data(), resultSize - sizeSoFar);
executed (the execution status of this line is deduced): memcpy(end, result.d->data(), resultSize - sizeSoFar);
-
2211 result.d->data()[resultSize] = '\0';
executed (the execution status of this line is deduced): result.d->data()[resultSize] = '\0';
-
2212 result.d->size = resultSize;
executed (the execution status of this line is deduced): result.d->size = resultSize;
-
2213 return result;
executed: return result;
Execution Count:7
7
2214} -
2215 -
2216#define REHASH(a) \ -
2217 if (ol_minus_1 < sizeof(uint) * CHAR_BIT) \ -
2218 hashHaystack -= (a) << ol_minus_1; \ -
2219 hashHaystack <<= 1 -
2220 -
2221/*! -
2222 Returns the index position of the first occurrence of the byte -
2223 array \a ba in this byte array, searching forward from index -
2224 position \a from. Returns -1 if \a ba could not be found. -
2225 -
2226 Example: -
2227 \snippet code/src_corelib_tools_qbytearray.cpp 21 -
2228 -
2229 \sa lastIndexOf(), contains(), count() -
2230*/ -
2231 -
2232int QByteArray::indexOf(const QByteArray &ba, int from) const -
2233{ -
2234 const int ol = ba.d->size;
executed (the execution status of this line is deduced): const int ol = ba.d->size;
-
2235 if (ol == 0)
evaluated: ol == 0
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:1878
16-1878
2236 return from;
executed: return from;
Execution Count:16
16
2237 if (ol == 1)
evaluated: ol == 1
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:1806
72-1806
2238 return indexOf(*ba.d->data(), from);
executed: return indexOf(*ba.d->data(), from);
Execution Count:72
72
2239 -
2240 const int l = d->size;
executed (the execution status of this line is deduced): const int l = d->size;
-
2241 if (from > d->size || ol + from > l)
partially evaluated: from > d->size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1806
evaluated: ol + from > l
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:1796
0-1806
2242 return -1;
executed: return -1;
Execution Count:10
10
2243 -
2244 return qFindByteArray(d->data(), d->size, from, ba.d->data(), ol);
executed: return qFindByteArray(d->data(), d->size, from, ba.d->data(), ol);
Execution Count:1796
1796
2245} -
2246 -
2247/*! \fn int QByteArray::indexOf(const QString &str, int from) const -
2248 -
2249 \overload -
2250 -
2251 Returns the index position of the first occurrence of the string -
2252 \a str in the byte array, searching forward from index position -
2253 \a from. Returns -1 if \a str could not be found. -
2254 -
2255 The Unicode data is converted into 8-bit characters using -
2256 QString::toUtf8(). -
2257 -
2258 You can disable this function by defining \c QT_NO_CAST_TO_ASCII when you -
2259 compile your applications. You then need to call QString::toUtf8() (or -
2260 QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to -
2261 convert the data to \c{const char *}. -
2262*/ -
2263 -
2264/*! \fn int QByteArray::indexOf(const char *str, int from) const -
2265 -
2266 \overload -
2267 -
2268 Returns the index position of the first occurrence of the string -
2269 \a str in the byte array, searching forward from index position \a -
2270 from. Returns -1 if \a str could not be found. -
2271*/ -
2272int QByteArray::indexOf(const char *c, int from) const -
2273{ -
2274 const int ol = qstrlen(c);
executed (the execution status of this line is deduced): const int ol = qstrlen(c);
-
2275 if (ol == 1)
evaluated: ol == 1
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:678884
24-678884
2276 return indexOf(*c, from);
executed: return indexOf(*c, from);
Execution Count:24
24
2277 -
2278 const int l = d->size;
executed (the execution status of this line is deduced): const int l = d->size;
-
2279 if (from > d->size || ol + from > l)
partially evaluated: from > d->size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:678884
evaluated: ol + from > l
TRUEFALSE
yes
Evaluation Count:6052
yes
Evaluation Count:672832
0-678884
2280 return -1;
executed: return -1;
Execution Count:6052
6052
2281 if (ol == 0)
evaluated: ol == 0
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:672824
8-672824
2282 return from;
executed: return from;
Execution Count:8
8
2283 -
2284 return qFindByteArray(d->data(), d->size, from, c, ol);
executed: return qFindByteArray(d->data(), d->size, from, c, ol);
Execution Count:672824
672824
2285} -
2286 -
2287/*! -
2288 \overload -
2289 -
2290 Returns the index position of the first occurrence of the -
2291 character \a ch in the byte array, searching forward from index -
2292 position \a from. Returns -1 if \a ch could not be found. -
2293 -
2294 Example: -
2295 \snippet code/src_corelib_tools_qbytearray.cpp 22 -
2296 -
2297 \sa lastIndexOf(), contains() -
2298*/ -
2299 -
2300int QByteArray::indexOf(char ch, int from) const -
2301{ -
2302 if (from < 0)
evaluated: from < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:955461
1-955461
2303 from = qMax(from + d->size, 0);
executed: from = qMax(from + d->size, 0);
Execution Count:1
1
2304 if (from < d->size) {
evaluated: from < d->size
TRUEFALSE
yes
Evaluation Count:953182
yes
Evaluation Count:2280
2280-953182
2305 const char *n = d->data() + from - 1;
executed (the execution status of this line is deduced): const char *n = d->data() + from - 1;
-
2306 const char *e = d->data() + d->size;
executed (the execution status of this line is deduced): const char *e = d->data() + d->size;
-
2307 while (++n != e)
evaluated: ++n != e
TRUEFALSE
yes
Evaluation Count:15462496
yes
Evaluation Count:224664
224664-15462496
2308 if (*n == ch)
evaluated: *n == ch
TRUEFALSE
yes
Evaluation Count:728518
yes
Evaluation Count:14733978
728518-14733978
2309 return n - d->data();
executed: return n - d->data();
Execution Count:728518
728518
2310 }
executed: }
Execution Count:224664
224664
2311 return -1;
executed: return -1;
Execution Count:226944
226944
2312} -
2313 -
2314 -
2315static int lastIndexOfHelper(const char *haystack, int l, const char *needle, int ol, int from) -
2316{ -
2317 int delta = l - ol;
executed (the execution status of this line is deduced): int delta = l - ol;
-
2318 if (from < 0)
evaluated: from < 0
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:20
20-40
2319 from = delta;
executed: from = delta;
Execution Count:40
40
2320 if (from < 0 || from > l)
evaluated: from < 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:55
partially evaluated: from > l
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:55
0-55
2321 return -1;
executed: return -1;
Execution Count:5
5
2322 if (from > delta)
evaluated: from > delta
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:53
2-53
2323 from = delta;
executed: from = delta;
Execution Count:2
2
2324 -
2325 const char *end = haystack;
executed (the execution status of this line is deduced): const char *end = haystack;
-
2326 haystack += from;
executed (the execution status of this line is deduced): haystack += from;
-
2327 const uint ol_minus_1 = ol - 1;
executed (the execution status of this line is deduced): const uint ol_minus_1 = ol - 1;
-
2328 const char *n = needle + ol_minus_1;
executed (the execution status of this line is deduced): const char *n = needle + ol_minus_1;
-
2329 const char *h = haystack + ol_minus_1;
executed (the execution status of this line is deduced): const char *h = haystack + ol_minus_1;
-
2330 uint hashNeedle = 0, hashHaystack = 0;
executed (the execution status of this line is deduced): uint hashNeedle = 0, hashHaystack = 0;
-
2331 int idx;
executed (the execution status of this line is deduced): int idx;
-
2332 for (idx = 0; idx < ol; ++idx) {
evaluated: idx < ol
TRUEFALSE
yes
Evaluation Count:310
yes
Evaluation Count:55
55-310
2333 hashNeedle = ((hashNeedle<<1) + *(n-idx));
executed (the execution status of this line is deduced): hashNeedle = ((hashNeedle<<1) + *(n-idx));
-
2334 hashHaystack = ((hashHaystack<<1) + *(h-idx));
executed (the execution status of this line is deduced): hashHaystack = ((hashHaystack<<1) + *(h-idx));
-
2335 }
executed: }
Execution Count:310
310
2336 hashHaystack -= *haystack;
executed (the execution status of this line is deduced): hashHaystack -= *haystack;
-
2337 while (haystack >= end) {
evaluated: haystack >= end
TRUEFALSE
yes
Evaluation Count:285
yes
Evaluation Count:14
14-285
2338 hashHaystack += *haystack;
executed (the execution status of this line is deduced): hashHaystack += *haystack;
-
2339 if (hashHaystack == hashNeedle && memcmp(needle, haystack, ol) == 0)
evaluated: hashHaystack == hashNeedle
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:242
evaluated: memcmp(needle, haystack, ol) == 0
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:2
2-242
2340 return haystack - end;
executed: return haystack - end;
Execution Count:41
41
2341 --haystack;
executed (the execution status of this line is deduced): --haystack;
-
2342 REHASH(*(haystack + ol));
executed: hashHaystack -= (*(haystack + ol)) << ol_minus_1;
Execution Count:210
evaluated: ol_minus_1 < sizeof(uint) * 8
TRUEFALSE
yes
Evaluation Count:210
yes
Evaluation Count:34
34-210
2343 }
executed: }
Execution Count:244
244
2344 return -1;
executed: return -1;
Execution Count:14
14
2345 -
2346} -
2347 -
2348/*! -
2349 \fn int QByteArray::lastIndexOf(const QByteArray &ba, int from) const -
2350 -
2351 Returns the index position of the last occurrence of the byte -
2352 array \a ba in this byte array, searching backward from index -
2353 position \a from. If \a from is -1 (the default), the search -
2354 starts at the last byte. Returns -1 if \a ba could not be found. -
2355 -
2356 Example: -
2357 \snippet code/src_corelib_tools_qbytearray.cpp 23 -
2358 -
2359 \sa indexOf(), contains(), count() -
2360*/ -
2361 -
2362int QByteArray::lastIndexOf(const QByteArray &ba, int from) const -
2363{ -
2364 const int ol = ba.d->size;
executed (the execution status of this line is deduced): const int ol = ba.d->size;
-
2365 if (ol == 1)
evaluated: ol == 1
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:36
34-36
2366 return lastIndexOf(*ba.d->data(), from);
executed: return lastIndexOf(*ba.d->data(), from);
Execution Count:34
34
2367 -
2368 return lastIndexOfHelper(d->data(), d->size, ba.d->data(), ol, from);
executed: return lastIndexOfHelper(d->data(), d->size, ba.d->data(), ol, from);
Execution Count:36
36
2369} -
2370 -
2371/*! \fn int QByteArray::lastIndexOf(const QString &str, int from) const -
2372 -
2373 \overload -
2374 -
2375 Returns the index position of the last occurrence of the string \a -
2376 str in the byte array, searching backward from index position \a -
2377 from. If \a from is -1 (the default), the search starts at the -
2378 last (size() - 1) byte. Returns -1 if \a str could not be found. -
2379 -
2380 The Unicode data is converted into 8-bit characters using -
2381 QString::toUtf8(). -
2382 -
2383 You can disable this function by defining \c QT_NO_CAST_TO_ASCII when you -
2384 compile your applications. You then need to call QString::toUtf8() (or -
2385 QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to -
2386 convert the data to \c{const char *}. -
2387*/ -
2388 -
2389/*! \fn int QByteArray::lastIndexOf(const char *str, int from) const -
2390 \overload -
2391 -
2392 Returns the index position of the last occurrence of the string \a -
2393 str in the byte array, searching backward from index position \a -
2394 from. If \a from is -1 (the default), the search starts at the -
2395 last (size() - 1) byte. Returns -1 if \a str could not be found. -
2396*/ -
2397int QByteArray::lastIndexOf(const char *str, int from) const -
2398{ -
2399 const int ol = qstrlen(str);
executed (the execution status of this line is deduced): const int ol = qstrlen(str);
-
2400 if (ol == 1)
evaluated: ol == 1
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:24
24
2401 return lastIndexOf(*str, from);
executed: return lastIndexOf(*str, from);
Execution Count:24
24
2402 -
2403 return lastIndexOfHelper(d->data(), d->size, str, ol, from);
executed: return lastIndexOfHelper(d->data(), d->size, str, ol, from);
Execution Count:24
24
2404} -
2405 -
2406/*! -
2407 \overload -
2408 -
2409 Returns the index position of the last occurrence of character \a -
2410 ch in the byte array, searching backward from index position \a -
2411 from. If \a from is -1 (the default), the search starts at the -
2412 last (size() - 1) byte. Returns -1 if \a ch could not be found. -
2413 -
2414 Example: -
2415 \snippet code/src_corelib_tools_qbytearray.cpp 24 -
2416 -
2417 \sa indexOf(), contains() -
2418*/ -
2419 -
2420int QByteArray::lastIndexOf(char ch, int from) const -
2421{ -
2422 if (from < 0)
evaluated: from < 0
TRUEFALSE
yes
Evaluation Count:150
yes
Evaluation Count:42
42-150
2423 from += d->size;
executed: from += d->size;
Execution Count:150
150
2424 else if (from > d->size)
partially evaluated: from > d->size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:42
0-42
2425 from = d->size-1;
never executed: from = d->size-1;
0
2426 if (from >= 0) {
evaluated: from >= 0
TRUEFALSE
yes
Evaluation Count:178
yes
Evaluation Count:14
14-178
2427 const char *b = d->data();
executed (the execution status of this line is deduced): const char *b = d->data();
-
2428 const char *n = d->data() + from + 1;
executed (the execution status of this line is deduced): const char *n = d->data() + from + 1;
-
2429 while (n-- != b)
evaluated: n-- != b
TRUEFALSE
yes
Evaluation Count:383
yes
Evaluation Count:33
33-383
2430 if (*n == ch)
evaluated: *n == ch
TRUEFALSE
yes
Evaluation Count:145
yes
Evaluation Count:238
145-238
2431 return n - b;
executed: return n - b;
Execution Count:145
145
2432 }
executed: }
Execution Count:33
33
2433 return -1;
executed: return -1;
Execution Count:47
47
2434} -
2435 -
2436/*! -
2437 Returns the number of (potentially overlapping) occurrences of -
2438 byte array \a ba in this byte array. -
2439 -
2440 \sa contains(), indexOf() -
2441*/ -
2442 -
2443int QByteArray::count(const QByteArray &ba) const -
2444{ -
2445 int num = 0;
executed (the execution status of this line is deduced): int num = 0;
-
2446 int i = -1;
executed (the execution status of this line is deduced): int i = -1;
-
2447 if (d->size > 500 && ba.d->size > 5) {
partially evaluated: d->size > 500
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
never evaluated: ba.d->size > 5
0-4
2448 QByteArrayMatcher matcher(ba);
never executed (the execution status of this line is deduced): QByteArrayMatcher matcher(ba);
-
2449 while ((i = matcher.indexIn(*this, i + 1)) != -1)
never evaluated: (i = matcher.indexIn(*this, i + 1)) != -1
0
2450 ++num;
never executed: ++num;
0
2451 } else {
never executed: }
0
2452 while ((i = indexOf(ba, i + 1)) != -1)
evaluated: (i = indexOf(ba, i + 1)) != -1
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:4
4-33
2453 ++num;
executed: ++num;
Execution Count:33
33
2454 }
executed: }
Execution Count:4
4
2455 return num;
executed: return num;
Execution Count:4
4
2456} -
2457 -
2458/*! -
2459 \overload -
2460 -
2461 Returns the number of (potentially overlapping) occurrences of -
2462 string \a str in the byte array. -
2463*/ -
2464 -
2465int QByteArray::count(const char *str) const -
2466{ -
2467 return count(fromRawData(str, qstrlen(str)));
executed: return count(fromRawData(str, qstrlen(str)));
Execution Count:4
4
2468} -
2469 -
2470/*! -
2471 \overload -
2472 -
2473 Returns the number of occurrences of character \a ch in the byte -
2474 array. -
2475 -
2476 \sa contains(), indexOf() -
2477*/ -
2478 -
2479int QByteArray::count(char ch) const -
2480{ -
2481 int num = 0;
executed (the execution status of this line is deduced): int num = 0;
-
2482 const char *i = d->data() + d->size;
executed (the execution status of this line is deduced): const char *i = d->data() + d->size;
-
2483 const char *b = d->data();
executed (the execution status of this line is deduced): const char *b = d->data();
-
2484 while (i != b)
evaluated: i != b
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:4
4-80
2485 if (*--i == ch)
evaluated: *--i == ch
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:57
23-57
2486 ++num;
executed: ++num;
Execution Count:23
23
2487 return num;
executed: return num;
Execution Count:4
4
2488} -
2489 -
2490/*! \fn int QByteArray::count() const -
2491 -
2492 \overload -
2493 -
2494 Same as size(). -
2495*/ -
2496 -
2497/*! -
2498 Returns true if this byte array starts with byte array \a ba; -
2499 otherwise returns false. -
2500 -
2501 Example: -
2502 \snippet code/src_corelib_tools_qbytearray.cpp 25 -
2503 -
2504 \sa endsWith(), left() -
2505*/ -
2506bool QByteArray::startsWith(const QByteArray &ba) const -
2507{ -
2508 if (d == ba.d || ba.d->size == 0)
evaluated: d == ba.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:57
evaluated: ba.d->size == 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:53
2-57
2509 return true;
executed: return true;
Execution Count:6
6
2510 if (d->size < ba.d->size)
evaluated: d->size < ba.d->size
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:42
11-42
2511 return false;
executed: return false;
Execution Count:11
11
2512 return memcmp(d->data(), ba.d->data(), ba.d->size) == 0;
executed: return memcmp(d->data(), ba.d->data(), ba.d->size) == 0;
Execution Count:42
42
2513} -
2514 -
2515/*! \overload -
2516 -
2517 Returns true if this byte array starts with string \a str; -
2518 otherwise returns false. -
2519*/ -
2520bool QByteArray::startsWith(const char *str) const -
2521{ -
2522 if (!str || !*str)
evaluated: !str
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:508052
evaluated: !*str
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:508049
3-508052
2523 return true;
executed: return true;
Execution Count:6
6
2524 const int len = int(strlen(str));
executed (the execution status of this line is deduced): const int len = int(strlen(str));
-
2525 if (d->size < len)
evaluated: d->size < len
TRUEFALSE
yes
Evaluation Count:43047
yes
Evaluation Count:465002
43047-465002
2526 return false;
executed: return false;
Execution Count:43047
43047
2527 return qstrncmp(d->data(), str, len) == 0;
executed: return qstrncmp(d->data(), str, len) == 0;
Execution Count:465002
465002
2528} -
2529 -
2530/*! \overload -
2531 -
2532 Returns true if this byte array starts with character \a ch; -
2533 otherwise returns false. -
2534*/ -
2535bool QByteArray::startsWith(char ch) const -
2536{ -
2537 if (d->size == 0)
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:101625
51-101625
2538 return false;
executed: return false;
Execution Count:51
51
2539 return d->data()[0] == ch;
executed: return d->data()[0] == ch;
Execution Count:101626
101626
2540} -
2541 -
2542/*! -
2543 Returns true if this byte array ends with byte array \a ba; -
2544 otherwise returns false. -
2545 -
2546 Example: -
2547 \snippet code/src_corelib_tools_qbytearray.cpp 26 -
2548 -
2549 \sa startsWith(), right() -
2550*/ -
2551bool QByteArray::endsWith(const QByteArray &ba) const -
2552{ -
2553 if (d == ba.d || ba.d->size == 0)
evaluated: d == ba.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
evaluated: ba.d->size == 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:5
2-9
2554 return true;
executed: return true;
Execution Count:6
6
2555 if (d->size < ba.d->size)
evaluated: d->size < ba.d->size
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
2556 return false;
executed: return false;
Execution Count:3
3
2557 return memcmp(d->data() + d->size - ba.d->size, ba.d->data(), ba.d->size) == 0;
executed: return memcmp(d->data() + d->size - ba.d->size, ba.d->data(), ba.d->size) == 0;
Execution Count:2
2
2558} -
2559 -
2560/*! \overload -
2561 -
2562 Returns true if this byte array ends with string \a str; otherwise -
2563 returns false. -
2564*/ -
2565bool QByteArray::endsWith(const char *str) const -
2566{ -
2567 if (!str || !*str)
evaluated: !str
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:185628
evaluated: !*str
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:185625
3-185628
2568 return true;
executed: return true;
Execution Count:6
6
2569 const int len = int(strlen(str));
executed (the execution status of this line is deduced): const int len = int(strlen(str));
-
2570 if (d->size < len)
evaluated: d->size < len
TRUEFALSE
yes
Evaluation Count:48156
yes
Evaluation Count:137469
48156-137469
2571 return false;
executed: return false;
Execution Count:48156
48156
2572 return qstrncmp(d->data() + d->size - len, str, len) == 0;
executed: return qstrncmp(d->data() + d->size - len, str, len) == 0;
Execution Count:137469
137469
2573} -
2574 -
2575/*! \overload -
2576 -
2577 Returns true if this byte array ends with character \a ch; -
2578 otherwise returns false. -
2579*/ -
2580bool QByteArray::endsWith(char ch) const -
2581{ -
2582 if (d->size == 0)
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:36206
45-36206
2583 return false;
executed: return false;
Execution Count:45
45
2584 return d->data()[d->size - 1] == ch;
executed: return d->data()[d->size - 1] == ch;
Execution Count:36206
36206
2585} -
2586 -
2587/*! -
2588 Returns a byte array that contains the leftmost \a len bytes of -
2589 this byte array. -
2590 -
2591 The entire byte array is returned if \a len is greater than -
2592 size(). -
2593 -
2594 Example: -
2595 \snippet code/src_corelib_tools_qbytearray.cpp 27 -
2596 -
2597 \sa right(), mid(), startsWith(), truncate() -
2598*/ -
2599 -
2600QByteArray QByteArray::left(int len) const -
2601{ -
2602 if (len >= d->size)
evaluated: len >= d->size
TRUEFALSE
yes
Evaluation Count:77
yes
Evaluation Count:131588
77-131588
2603 return *this;
executed: return *this;
Execution Count:77
77
2604 if (len < 0)
partially evaluated: len < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:131588
0-131588
2605 len = 0;
never executed: len = 0;
0
2606 return QByteArray(d->data(), len);
executed: return QByteArray(d->data(), len);
Execution Count:131588
131588
2607} -
2608 -
2609/*! -
2610 Returns a byte array that contains the rightmost \a len bytes of -
2611 this byte array. -
2612 -
2613 The entire byte array is returned if \a len is greater than -
2614 size(). -
2615 -
2616 Example: -
2617 \snippet code/src_corelib_tools_qbytearray.cpp 28 -
2618 -
2619 \sa endsWith(), left(), mid() -
2620*/ -
2621 -
2622QByteArray QByteArray::right(int len) const -
2623{ -
2624 if (len >= d->size)
evaluated: len >= d->size
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:14
4-14
2625 return *this;
executed: return *this;
Execution Count:4
4
2626 if (len < 0)
partially evaluated: len < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:14
0-14
2627 len = 0;
never executed: len = 0;
0
2628 return QByteArray(d->data() + d->size - len, len);
executed: return QByteArray(d->data() + d->size - len, len);
Execution Count:14
14
2629} -
2630 -
2631/*! -
2632 Returns a byte array containing \a len bytes from this byte array, -
2633 starting at position \a pos. -
2634 -
2635 If \a len is -1 (the default), or \a pos + \a len >= size(), -
2636 returns a byte array containing all bytes starting at position \a -
2637 pos until the end of the byte array. -
2638 -
2639 Example: -
2640 \snippet code/src_corelib_tools_qbytearray.cpp 29 -
2641 -
2642 \sa left(), right() -
2643*/ -
2644 -
2645QByteArray QByteArray::mid(int pos, int len) const -
2646{ -
2647 if ((d->size == 0 && d->ref.isStatic()) || pos > d->size)
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:308
yes
Evaluation Count:949898
partially evaluated: d->ref.isStatic()
TRUEFALSE
yes
Evaluation Count:308
no
Evaluation Count:0
partially evaluated: pos > d->size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:949898
0-949898
2648 return QByteArray();
executed: return QByteArray();
Execution Count:308
308
2649 if (len < 0)
evaluated: len < 0
TRUEFALSE
yes
Evaluation Count:338342
yes
Evaluation Count:611556
338342-611556
2650 len = d->size - pos;
executed: len = d->size - pos;
Execution Count:338342
338342
2651 if (pos < 0) {
evaluated: pos < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:949897
1-949897
2652 len += pos;
executed (the execution status of this line is deduced): len += pos;
-
2653 pos = 0;
executed (the execution status of this line is deduced): pos = 0;
-
2654 }
executed: }
Execution Count:1
1
2655 if (len + pos > d->size)
evaluated: len + pos > d->size
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:949894
4-949894
2656 len = d->size - pos;
executed: len = d->size - pos;
Execution Count:4
4
2657 if (pos == 0 && len == d->size)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:227429
yes
Evaluation Count:722469
evaluated: len == d->size
TRUEFALSE
yes
Evaluation Count:58584
yes
Evaluation Count:168845
58584-722469
2658 return *this;
executed: return *this;
Execution Count:58584
58584
2659 return QByteArray(d->data() + pos, len);
executed: return QByteArray(d->data() + pos, len);
Execution Count:891314
891314
2660} -
2661 -
2662/*! -
2663 Returns a lowercase copy of the byte array. The bytearray is -
2664 interpreted as a Latin-1 encoded string. -
2665 -
2666 Example: -
2667 \snippet code/src_corelib_tools_qbytearray.cpp 30 -
2668 -
2669 \sa toUpper(), {8-bit Character Comparisons} -
2670*/ -
2671QByteArray QByteArray::toLower() const -
2672{ -
2673 QByteArray s(*this);
executed (the execution status of this line is deduced): QByteArray s(*this);
-
2674 register uchar *p = reinterpret_cast<uchar *>(s.data());
executed (the execution status of this line is deduced): register uchar *p = reinterpret_cast<uchar *>(s.data());
-
2675 if (p) {
partially evaluated: p
TRUEFALSE
yes
Evaluation Count:124573
no
Evaluation Count:0
0-124573
2676 while (*p) {
evaluated: *p
TRUEFALSE
yes
Evaluation Count:1110653
yes
Evaluation Count:124573
124573-1110653
2677 *p = QChar::toLower((ushort)*p);
executed (the execution status of this line is deduced): *p = QChar::toLower((ushort)*p);
-
2678 p++;
executed (the execution status of this line is deduced): p++;
-
2679 }
executed: }
Execution Count:1110653
1110653
2680 }
executed: }
Execution Count:124573
124573
2681 return s;
executed: return s;
Execution Count:124573
124573
2682} -
2683 -
2684/*! -
2685 Returns an uppercase copy of the byte array. The bytearray is -
2686 interpreted as a Latin-1 encoded string. -
2687 -
2688 Example: -
2689 \snippet code/src_corelib_tools_qbytearray.cpp 31 -
2690 -
2691 \sa toLower(), {8-bit Character Comparisons} -
2692*/ -
2693 -
2694QByteArray QByteArray::toUpper() const -
2695{ -
2696 QByteArray s(*this);
executed (the execution status of this line is deduced): QByteArray s(*this);
-
2697 register uchar *p = reinterpret_cast<uchar *>(s.data());
executed (the execution status of this line is deduced): register uchar *p = reinterpret_cast<uchar *>(s.data());
-
2698 if (p) {
partially evaluated: p
TRUEFALSE
yes
Evaluation Count:189
no
Evaluation Count:0
0-189
2699 while (*p) {
evaluated: *p
TRUEFALSE
yes
Evaluation Count:675
yes
Evaluation Count:189
189-675
2700 *p = QChar::toUpper((ushort)*p);
executed (the execution status of this line is deduced): *p = QChar::toUpper((ushort)*p);
-
2701 p++;
executed (the execution status of this line is deduced): p++;
-
2702 }
executed: }
Execution Count:675
675
2703 }
executed: }
Execution Count:189
189
2704 return s;
executed: return s;
Execution Count:189
189
2705} -
2706 -
2707/*! \fn void QByteArray::clear() -
2708 -
2709 Clears the contents of the byte array and makes it empty. -
2710 -
2711 \sa resize(), isEmpty() -
2712*/ -
2713 -
2714void QByteArray::clear() -
2715{ -
2716 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:5905
yes
Evaluation Count:621701
5905-621701
2717 Data::deallocate(d);
executed: Data::deallocate(d);
Execution Count:5905
5905
2718 d = Data::sharedNull();
executed (the execution status of this line is deduced): d = Data::sharedNull();
-
2719}
executed: }
Execution Count:627606
627606
2720 -
2721#if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) -
2722 -
2723/*! \relates QByteArray -
2724 -
2725 Writes byte array \a ba to the stream \a out and returns a reference -
2726 to the stream. -
2727 -
2728 \sa {Serializing Qt Data Types} -
2729*/ -
2730 -
2731QDataStream &operator<<(QDataStream &out, const QByteArray &ba) -
2732{ -
2733 if (ba.isNull() && out.version() >= 6) {
evaluated: ba.isNull()
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:1548
partially evaluated: out.version() >= 6
TRUEFALSE
yes
Evaluation Count:19
no
Evaluation Count:0
0-1548
2734 out << (quint32)0xffffffff;
executed (the execution status of this line is deduced): out << (quint32)0xffffffff;
-
2735 return out;
executed: return out;
Execution Count:19
19
2736 } -
2737 return out.writeBytes(ba.constData(), ba.size());
executed: return out.writeBytes(ba.constData(), ba.size());
Execution Count:1548
1548
2738} -
2739 -
2740/*! \relates QByteArray -
2741 -
2742 Reads a byte array into \a ba from the stream \a in and returns a -
2743 reference to the stream. -
2744 -
2745 \sa {Serializing Qt Data Types} -
2746*/ -
2747 -
2748QDataStream &operator>>(QDataStream &in, QByteArray &ba) -
2749{ -
2750 ba.clear();
executed (the execution status of this line is deduced): ba.clear();
-
2751 quint32 len;
executed (the execution status of this line is deduced): quint32 len;
-
2752 in >> len;
executed (the execution status of this line is deduced): in >> len;
-
2753 if (len == 0xffffffff)
evaluated: len == 0xffffffff
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:1329
24-1329
2754 return in;
executed: return in;
Execution Count:24
24
2755 -
2756 const quint32 Step = 1024 * 1024;
executed (the execution status of this line is deduced): const quint32 Step = 1024 * 1024;
-
2757 quint32 allocated = 0;
executed (the execution status of this line is deduced): quint32 allocated = 0;
-
2758 -
2759 do { -
2760 int blockSize = qMin(Step, len - allocated);
executed (the execution status of this line is deduced): int blockSize = qMin(Step, len - allocated);
-
2761 ba.resize(allocated + blockSize);
executed (the execution status of this line is deduced): ba.resize(allocated + blockSize);
-
2762 if (in.readRawData(ba.data() + allocated, blockSize) != blockSize) {
evaluated: in.readRawData(ba.data() + allocated, blockSize) != blockSize
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:1332
11-1332
2763 ba.clear();
executed (the execution status of this line is deduced): ba.clear();
-
2764 in.setStatus(QDataStream::ReadPastEnd);
executed (the execution status of this line is deduced): in.setStatus(QDataStream::ReadPastEnd);
-
2765 return in;
executed: return in;
Execution Count:11
11
2766 } -
2767 allocated += blockSize;
executed (the execution status of this line is deduced): allocated += blockSize;
-
2768 } while (allocated < len);
executed: }
Execution Count:1332
evaluated: allocated < len
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:1318
14-1332
2769 -
2770 return in;
executed: return in;
Execution Count:1318
1318
2771} -
2772#endif // QT_NO_DATASTREAM -
2773 -
2774/*! \fn bool QByteArray::operator==(const QString &str) const -
2775 -
2776 Returns true if this byte array is equal to string \a str; -
2777 otherwise returns false. -
2778 -
2779 The Unicode data is converted into 8-bit characters using -
2780 QString::toUtf8(). -
2781 -
2782 The comparison is case sensitive. -
2783 -
2784 You can disable this operator by defining \c -
2785 QT_NO_CAST_FROM_ASCII when you compile your applications. You -
2786 then need to call QString::fromUtf8(), QString::fromLatin1(), -
2787 or QString::fromLocal8Bit() explicitly if you want to convert the byte -
2788 array to a QString before doing the comparison. -
2789*/ -
2790 -
2791/*! \fn bool QByteArray::operator!=(const QString &str) const -
2792 -
2793 Returns true if this byte array is not equal to string \a str; -
2794 otherwise returns false. -
2795 -
2796 The Unicode data is converted into 8-bit characters using -
2797 QString::toUtf8(). -
2798 -
2799 The comparison is case sensitive. -
2800 -
2801 You can disable this operator by defining \c -
2802 QT_NO_CAST_FROM_ASCII when you compile your applications. You -
2803 then need to call QString::fromUtf8(), QString::fromLatin1(), -
2804 or QString::fromLocal8Bit() explicitly if you want to convert the byte -
2805 array to a QString before doing the comparison. -
2806*/ -
2807 -
2808/*! \fn bool QByteArray::operator<(const QString &str) const -
2809 -
2810 Returns true if this byte array is lexically less than string \a -
2811 str; otherwise returns false. -
2812 -
2813 The Unicode data is converted into 8-bit characters using -
2814 QString::toUtf8(). -
2815 -
2816 The comparison is case sensitive. -
2817 -
2818 You can disable this operator by defining \c -
2819 QT_NO_CAST_FROM_ASCII when you compile your applications. You -
2820 then need to call QString::fromUtf8(), QString::fromLatin1(), -
2821 or QString::fromLocal8Bit() explicitly if you want to convert the byte -
2822 array to a QString before doing the comparison. -
2823*/ -
2824 -
2825/*! \fn bool QByteArray::operator>(const QString &str) const -
2826 -
2827 Returns true if this byte array is lexically greater than string -
2828 \a str; otherwise returns false. -
2829 -
2830 The Unicode data is converted into 8-bit characters using -
2831 QString::toUtf8(). -
2832 -
2833 The comparison is case sensitive. -
2834 -
2835 You can disable this operator by defining \c -
2836 QT_NO_CAST_FROM_ASCII when you compile your applications. You -
2837 then need to call QString::fromUtf8(), QString::fromLatin1(), -
2838 or QString::fromLocal8Bit() explicitly if you want to convert the byte -
2839 array to a QString before doing the comparison. -
2840*/ -
2841 -
2842/*! \fn bool QByteArray::operator<=(const QString &str) const -
2843 -
2844 Returns true if this byte array is lexically less than or equal -
2845 to string \a str; otherwise returns false. -
2846 -
2847 The Unicode data is converted into 8-bit characters using -
2848 QString::toUtf8(). -
2849 -
2850 The comparison is case sensitive. -
2851 -
2852 You can disable this operator by defining \c -
2853 QT_NO_CAST_FROM_ASCII when you compile your applications. You -
2854 then need to call QString::fromUtf8(), QString::fromLatin1(), -
2855 or QString::fromLocal8Bit() explicitly if you want to convert the byte -
2856 array to a QString before doing the comparison. -
2857*/ -
2858 -
2859/*! \fn bool QByteArray::operator>=(const QString &str) const -
2860 -
2861 Returns true if this byte array is greater than or equal to string -
2862 \a str; otherwise returns false. -
2863 -
2864 The Unicode data is converted into 8-bit characters using -
2865 QString::toUtf8(). -
2866 -
2867 The comparison is case sensitive. -
2868 -
2869 You can disable this operator by defining \c -
2870 QT_NO_CAST_FROM_ASCII when you compile your applications. You -
2871 then need to call QString::fromUtf8(), QString::fromLatin1(), -
2872 or QString::fromLocal8Bit() explicitly if you want to convert the byte -
2873 array to a QString before doing the comparison. -
2874*/ -
2875 -
2876/*! \fn bool operator==(const QByteArray &a1, const QByteArray &a2) -
2877 \relates QByteArray -
2878 -
2879 \overload -
2880 -
2881 Returns true if byte array \a a1 is equal to byte array \a a2; -
2882 otherwise returns false. -
2883*/ -
2884 -
2885/*! \fn bool operator==(const QByteArray &a1, const char *a2) -
2886 \relates QByteArray -
2887 -
2888 \overload -
2889 -
2890 Returns true if byte array \a a1 is equal to string \a a2; -
2891 otherwise returns false. -
2892*/ -
2893 -
2894/*! \fn bool operator==(const char *a1, const QByteArray &a2) -
2895 \relates QByteArray -
2896 -
2897 \overload -
2898 -
2899 Returns true if string \a a1 is equal to byte array \a a2; -
2900 otherwise returns false. -
2901*/ -
2902 -
2903/*! \fn bool operator!=(const QByteArray &a1, const QByteArray &a2) -
2904 \relates QByteArray -
2905 -
2906 \overload -
2907 -
2908 Returns true if byte array \a a1 is not equal to byte array \a a2; -
2909 otherwise returns false. -
2910*/ -
2911 -
2912/*! \fn bool operator!=(const QByteArray &a1, const char *a2) -
2913 \relates QByteArray -
2914 -
2915 \overload -
2916 -
2917 Returns true if byte array \a a1 is not equal to string \a a2; -
2918 otherwise returns false. -
2919*/ -
2920 -
2921/*! \fn bool operator!=(const char *a1, const QByteArray &a2) -
2922 \relates QByteArray -
2923 -
2924 \overload -
2925 -
2926 Returns true if string \a a1 is not equal to byte array \a a2; -
2927 otherwise returns false. -
2928*/ -
2929 -
2930/*! \fn bool operator<(const QByteArray &a1, const QByteArray &a2) -
2931 \relates QByteArray -
2932 -
2933 \overload -
2934 -
2935 Returns true if byte array \a a1 is lexically less than byte array -
2936 \a a2; otherwise returns false. -
2937*/ -
2938 -
2939/*! \fn inline bool operator<(const QByteArray &a1, const char *a2) -
2940 \relates QByteArray -
2941 -
2942 \overload -
2943 -
2944 Returns true if byte array \a a1 is lexically less than string -
2945 \a a2; otherwise returns false. -
2946*/ -
2947 -
2948/*! \fn bool operator<(const char *a1, const QByteArray &a2) -
2949 \relates QByteArray -
2950 -
2951 \overload -
2952 -
2953 Returns true if string \a a1 is lexically less than byte array -
2954 \a a2; otherwise returns false. -
2955*/ -
2956 -
2957/*! \fn bool operator<=(const QByteArray &a1, const QByteArray &a2) -
2958 \relates QByteArray -
2959 -
2960 \overload -
2961 -
2962 Returns true if byte array \a a1 is lexically less than or equal -
2963 to byte array \a a2; otherwise returns false. -
2964*/ -
2965 -
2966/*! \fn bool operator<=(const QByteArray &a1, const char *a2) -
2967 \relates QByteArray -
2968 -
2969 \overload -
2970 -
2971 Returns true if byte array \a a1 is lexically less than or equal -
2972 to string \a a2; otherwise returns false. -
2973*/ -
2974 -
2975/*! \fn bool operator<=(const char *a1, const QByteArray &a2) -
2976 \relates QByteArray -
2977 -
2978 \overload -
2979 -
2980 Returns true if string \a a1 is lexically less than or equal -
2981 to byte array \a a2; otherwise returns false. -
2982*/ -
2983 -
2984/*! \fn bool operator>(const QByteArray &a1, const QByteArray &a2) -
2985 \relates QByteArray -
2986 -
2987 \overload -
2988 -
2989 Returns true if byte array \a a1 is lexically greater than byte -
2990 array \a a2; otherwise returns false. -
2991*/ -
2992 -
2993/*! \fn bool operator>(const QByteArray &a1, const char *a2) -
2994 \relates QByteArray -
2995 -
2996 \overload -
2997 -
2998 Returns true if byte array \a a1 is lexically greater than string -
2999 \a a2; otherwise returns false. -
3000*/ -
3001 -
3002/*! \fn bool operator>(const char *a1, const QByteArray &a2) -
3003 \relates QByteArray -
3004 -
3005 \overload -
3006 -
3007 Returns true if string \a a1 is lexically greater than byte array -
3008 \a a2; otherwise returns false. -
3009*/ -
3010 -
3011/*! \fn bool operator>=(const QByteArray &a1, const QByteArray &a2) -
3012 \relates QByteArray -
3013 -
3014 \overload -
3015 -
3016 Returns true if byte array \a a1 is lexically greater than or -
3017 equal to byte array \a a2; otherwise returns false. -
3018*/ -
3019 -
3020/*! \fn bool operator>=(const QByteArray &a1, const char *a2) -
3021 \relates QByteArray -
3022 -
3023 \overload -
3024 -
3025 Returns true if byte array \a a1 is lexically greater than or -
3026 equal to string \a a2; otherwise returns false. -
3027*/ -
3028 -
3029/*! \fn bool operator>=(const char *a1, const QByteArray &a2) -
3030 \relates QByteArray -
3031 -
3032 \overload -
3033 -
3034 Returns true if string \a a1 is lexically greater than or -
3035 equal to byte array \a a2; otherwise returns false. -
3036*/ -
3037 -
3038/*! \fn const QByteArray operator+(const QByteArray &a1, const QByteArray &a2) -
3039 \relates QByteArray -
3040 -
3041 Returns a byte array that is the result of concatenating byte -
3042 array \a a1 and byte array \a a2. -
3043 -
3044 \sa QByteArray::operator+=() -
3045*/ -
3046 -
3047/*! \fn const QByteArray operator+(const QByteArray &a1, const char *a2) -
3048 \relates QByteArray -
3049 -
3050 \overload -
3051 -
3052 Returns a byte array that is the result of concatenating byte -
3053 array \a a1 and string \a a2. -
3054*/ -
3055 -
3056/*! \fn const QByteArray operator+(const QByteArray &a1, char a2) -
3057 \relates QByteArray -
3058 -
3059 \overload -
3060 -
3061 Returns a byte array that is the result of concatenating byte -
3062 array \a a1 and character \a a2. -
3063*/ -
3064 -
3065/*! \fn const QByteArray operator+(const char *a1, const QByteArray &a2) -
3066 \relates QByteArray -
3067 -
3068 \overload -
3069 -
3070 Returns a byte array that is the result of concatenating string -
3071 \a a1 and byte array \a a2. -
3072*/ -
3073 -
3074/*! \fn const QByteArray operator+(char a1, const QByteArray &a2) -
3075 \relates QByteArray -
3076 -
3077 \overload -
3078 -
3079 Returns a byte array that is the result of concatenating character -
3080 \a a1 and byte array \a a2. -
3081*/ -
3082 -
3083/*! -
3084 Returns a byte array that has whitespace removed from the start -
3085 and the end, and which has each sequence of internal whitespace -
3086 replaced with a single space. -
3087 -
3088 Whitespace means any character for which the standard C++ -
3089 isspace() function returns true. This includes the ASCII -
3090 characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '. -
3091 -
3092 Example: -
3093 \snippet code/src_corelib_tools_qbytearray.cpp 32 -
3094 -
3095 \sa trimmed() -
3096*/ -
3097QByteArray QByteArray::simplified() const -
3098{ -
3099 if (d->size == 0)
partially evaluated: d->size == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:112388
0-112388
3100 return *this;
never executed: return *this;
0
3101 QByteArray result(d->size, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray result(d->size, Qt::Uninitialized);
-
3102 const char *from = d->data();
executed (the execution status of this line is deduced): const char *from = d->data();
-
3103 const char *fromend = from + d->size;
executed (the execution status of this line is deduced): const char *fromend = from + d->size;
-
3104 int outc=0;
executed (the execution status of this line is deduced): int outc=0;
-
3105 char *to = result.d->data();
executed (the execution status of this line is deduced): char *to = result.d->data();
-
3106 for (;;) {
executed (the execution status of this line is deduced): for (;;) {
-
3107 while (from!=fromend && isspace(uchar(*from)))
evaluated: from!=fromend
TRUEFALSE
yes
Evaluation Count:457095
yes
Evaluation Count:228
evaluated: isspace(uchar(*from))
TRUEFALSE
yes
Evaluation Count:230624
yes
Evaluation Count:226471
228-457095
3108 from++;
executed: from++;
Execution Count:230624
230624
3109 while (from!=fromend && !isspace(uchar(*from)))
evaluated: from!=fromend
TRUEFALSE
yes
Evaluation Count:999970
yes
Evaluation Count:112388
evaluated: !isspace(uchar(*from))
TRUEFALSE
yes
Evaluation Count:885659
yes
Evaluation Count:114311
112388-999970
3110 to[outc++] = *from++;
executed: to[outc++] = *from++;
Execution Count:885659
885659
3111 if (from!=fromend)
evaluated: from!=fromend
TRUEFALSE
yes
Evaluation Count:114311
yes
Evaluation Count:112388
112388-114311
3112 to[outc++] = ' ';
executed: to[outc++] = ' ';
Execution Count:114311
114311
3113 else -
3114 break;
executed: break;
Execution Count:112388
112388
3115 } -
3116 if (outc > 0 && to[outc-1] == ' ')
partially evaluated: outc > 0
TRUEFALSE
yes
Evaluation Count:112388
no
Evaluation Count:0
evaluated: to[outc-1] == ' '
TRUEFALSE
yes
Evaluation Count:228
yes
Evaluation Count:112160
0-112388
3117 outc--;
executed: outc--;
Execution Count:228
228
3118 result.resize(outc);
executed (the execution status of this line is deduced): result.resize(outc);
-
3119 return result;
executed: return result;
Execution Count:112388
112388
3120} -
3121 -
3122/*! -
3123 Returns a byte array that has whitespace removed from the start -
3124 and the end. -
3125 -
3126 Whitespace means any character for which the standard C++ -
3127 isspace() function returns true. This includes the ASCII -
3128 characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '. -
3129 -
3130 Example: -
3131 \snippet code/src_corelib_tools_qbytearray.cpp 33 -
3132 -
3133 Unlike simplified(), trimmed() leaves internal whitespace alone. -
3134 -
3135 \sa simplified() -
3136*/ -
3137QByteArray QByteArray::trimmed() const -
3138{ -
3139 if (d->size == 0)
evaluated: d->size == 0
TRUEFALSE
yes
Evaluation Count:103
yes
Evaluation Count:147023
103-147023
3140 return *this;
executed: return *this;
Execution Count:103
103
3141 const char *s = d->data();
executed (the execution status of this line is deduced): const char *s = d->data();
-
3142 if (!isspace(uchar(*s)) && !isspace(uchar(s[d->size-1])))
evaluated: !isspace(uchar(*s))
TRUEFALSE
yes
Evaluation Count:141427
yes
Evaluation Count:5596
evaluated: !isspace(uchar(s[d->size-1]))
TRUEFALSE
yes
Evaluation Count:122835
yes
Evaluation Count:18592
5596-141427
3143 return *this;
executed: return *this;
Execution Count:122835
122835
3144 int start = 0;
executed (the execution status of this line is deduced): int start = 0;
-
3145 int end = d->size - 1;
executed (the execution status of this line is deduced): int end = d->size - 1;
-
3146 while (start<=end && isspace(uchar(s[start]))) // skip white space from start
evaluated: start<=end
TRUEFALSE
yes
Evaluation Count:29815
yes
Evaluation Count:6
evaluated: isspace(uchar(s[start]))
TRUEFALSE
yes
Evaluation Count:5633
yes
Evaluation Count:24182
6-29815
3147 start++;
executed: start++;
Execution Count:5633
5633
3148 if (start <= end) { // only white space
evaluated: start <= end
TRUEFALSE
yes
Evaluation Count:24182
yes
Evaluation Count:6
6-24182
3149 while (end && isspace(uchar(s[end]))) // skip white space from end
evaluated: end
TRUEFALSE
yes
Evaluation Count:42814
yes
Evaluation Count:35
evaluated: isspace(uchar(s[end]))
TRUEFALSE
yes
Evaluation Count:18667
yes
Evaluation Count:24147
35-42814
3150 end--;
executed: end--;
Execution Count:18667
18667
3151 }
executed: }
Execution Count:24182
24182
3152 int l = end - start + 1;
executed (the execution status of this line is deduced): int l = end - start + 1;
-
3153 if (l <= 0) {
evaluated: l <= 0
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:24182
6-24182
3154 QByteArrayDataPtr empty = { reinterpret_cast<QByteArrayData *>(Data::allocate(0)) };
executed (the execution status of this line is deduced): QByteArrayDataPtr empty = { reinterpret_cast<QByteArrayData *>(Data::allocate(0)) };
-
3155 return QByteArray(empty);
executed: return QByteArray(empty);
Execution Count:6
6
3156 } -
3157 return QByteArray(s+start, l);
executed: return QByteArray(s+start, l);
Execution Count:24182
24182
3158} -
3159 -
3160/*! -
3161 Returns a byte array of size \a width that contains this byte -
3162 array padded by the \a fill character. -
3163 -
3164 If \a truncate is false and the size() of the byte array is more -
3165 than \a width, then the returned byte array is a copy of this byte -
3166 array. -
3167 -
3168 If \a truncate is true and the size() of the byte array is more -
3169 than \a width, then any bytes in a copy of the byte array -
3170 after position \a width are removed, and the copy is returned. -
3171 -
3172 Example: -
3173 \snippet code/src_corelib_tools_qbytearray.cpp 34 -
3174 -
3175 \sa rightJustified() -
3176*/ -
3177 -
3178QByteArray QByteArray::leftJustified(int width, char fill, bool truncate) const -
3179{ -
3180 QByteArray result;
executed (the execution status of this line is deduced): QByteArray result;
-
3181 int len = d->size;
executed (the execution status of this line is deduced): int len = d->size;
-
3182 int padlen = width - len;
executed (the execution status of this line is deduced): int padlen = width - len;
-
3183 if (padlen > 0) {
evaluated: padlen > 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:8
5-8
3184 result.resize(len+padlen);
executed (the execution status of this line is deduced): result.resize(len+padlen);
-
3185 if (len)
evaluated: len
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1
1-4
3186 memcpy(result.d->data(), d->data(), len);
executed: memcpy(result.d->data(), d->data(), len);
Execution Count:4
4
3187 memset(result.d->data()+len, fill, padlen);
executed (the execution status of this line is deduced): memset(result.d->data()+len, fill, padlen);
-
3188 } else {
executed: }
Execution Count:5
5
3189 if (truncate)
evaluated: truncate
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:4
4
3190 result = left(width);
executed: result = left(width);
Execution Count:4
4
3191 else -
3192 result = *this;
executed: result = *this;
Execution Count:4
4
3193 } -
3194 return result;
executed: return result;
Execution Count:13
13
3195} -
3196 -
3197/*! -
3198 Returns a byte array of size \a width that contains the \a fill -
3199 character followed by this byte array. -
3200 -
3201 If \a truncate is false and the size of the byte array is more -
3202 than \a width, then the returned byte array is a copy of this byte -
3203 array. -
3204 -
3205 If \a truncate is true and the size of the byte array is more -
3206 than \a width, then the resulting byte array is truncated at -
3207 position \a width. -
3208 -
3209 Example: -
3210 \snippet code/src_corelib_tools_qbytearray.cpp 35 -
3211 -
3212 \sa leftJustified() -
3213*/ -
3214 -
3215QByteArray QByteArray::rightJustified(int width, char fill, bool truncate) const -
3216{ -
3217 QByteArray result;
executed (the execution status of this line is deduced): QByteArray result;
-
3218 int len = d->size;
executed (the execution status of this line is deduced): int len = d->size;
-
3219 int padlen = width - len;
executed (the execution status of this line is deduced): int padlen = width - len;
-
3220 if (padlen > 0) {
evaluated: padlen > 0
TRUEFALSE
yes
Evaluation Count:191
yes
Evaluation Count:678
191-678
3221 result.resize(len+padlen);
executed (the execution status of this line is deduced): result.resize(len+padlen);
-
3222 if (len)
evaluated: len
TRUEFALSE
yes
Evaluation Count:190
yes
Evaluation Count:1
1-190
3223 memcpy(result.d->data()+padlen, data(), len);
executed: memcpy(result.d->data()+padlen, data(), len);
Execution Count:190
190
3224 memset(result.d->data(), fill, padlen);
executed (the execution status of this line is deduced): memset(result.d->data(), fill, padlen);
-
3225 } else {
executed: }
Execution Count:191
191
3226 if (truncate)
evaluated: truncate
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:674
4-674
3227 result = left(width);
executed: result = left(width);
Execution Count:4
4
3228 else -
3229 result = *this;
executed: result = *this;
Execution Count:674
674
3230 } -
3231 return result;
executed: return result;
Execution Count:869
869
3232} -
3233 -
3234bool QByteArray::isNull() const { return d == QArrayData::sharedNull(); }
executed: return d == QArrayData::sharedNull();
Execution Count:12685
12685
3235 -
3236 -
3237/*! -
3238 Returns the byte array converted to a \c {long long} using base \a -
3239 base, which is 10 by default and must be between 2 and 36, or 0. -
3240 -
3241 If \a base is 0, the base is determined automatically using the -
3242 following rules: If the byte array begins with "0x", it is assumed to -
3243 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3244 otherwise it is assumed to be decimal. -
3245 -
3246 Returns 0 if the conversion fails. -
3247 -
3248 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3249 false; otherwise *\a{ok} is set to true. -
3250 -
3251 \note The conversion of the number is performed in the default C locale, -
3252 irrespective of the user's locale. -
3253 -
3254 \sa number() -
3255*/ -
3256 -
3257qlonglong QByteArray::toLongLong(bool *ok, int base) const -
3258{ -
3259#if defined(QT_CHECK_RANGE) -
3260 if (base != 0 && (base < 2 || base > 36)) { -
3261 qWarning("QByteArray::toLongLong: Invalid base %d", base); -
3262 base = 10; -
3263 } -
3264#endif -
3265 -
3266 return QLocalePrivate::bytearrayToLongLong(nulTerminated().constData(), base, ok);
executed: return QLocalePrivate::bytearrayToLongLong(nulTerminated().constData(), base, ok);
Execution Count:180620
180620
3267} -
3268 -
3269/*! -
3270 Returns the byte array converted to an \c {unsigned long long} -
3271 using base \a base, which is 10 by default and must be between 2 -
3272 and 36, or 0. -
3273 -
3274 If \a base is 0, the base is determined automatically using the -
3275 following rules: If the byte array begins with "0x", it is assumed to -
3276 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3277 otherwise it is assumed to be decimal. -
3278 -
3279 Returns 0 if the conversion fails. -
3280 -
3281 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3282 false; otherwise *\a{ok} is set to true. -
3283 -
3284 \note The conversion of the number is performed in the default C locale, -
3285 irrespective of the user's locale. -
3286 -
3287 \sa number() -
3288*/ -
3289 -
3290qulonglong QByteArray::toULongLong(bool *ok, int base) const -
3291{ -
3292#if defined(QT_CHECK_RANGE) -
3293 if (base != 0 && (base < 2 || base > 36)) { -
3294 qWarning("QByteArray::toULongLong: Invalid base %d", base); -
3295 base = 10; -
3296 } -
3297#endif -
3298 -
3299 return QLocalePrivate::bytearrayToUnsLongLong(nulTerminated().constData(), base, ok);
executed: return QLocalePrivate::bytearrayToUnsLongLong(nulTerminated().constData(), base, ok);
Execution Count:3506
3506
3300} -
3301 -
3302 -
3303/*! -
3304 Returns the byte array converted to an \c int using base \a -
3305 base, which is 10 by default and must be between 2 and 36, or 0. -
3306 -
3307 If \a base is 0, the base is determined automatically using the -
3308 following rules: If the byte array begins with "0x", it is assumed to -
3309 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3310 otherwise it is assumed to be decimal. -
3311 -
3312 Returns 0 if the conversion fails. -
3313 -
3314 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3315 false; otherwise *\a{ok} is set to true. -
3316 -
3317 \snippet code/src_corelib_tools_qbytearray.cpp 36 -
3318 -
3319 \note The conversion of the number is performed in the default C locale, -
3320 irrespective of the user's locale. -
3321 -
3322 \sa number() -
3323*/ -
3324 -
3325int QByteArray::toInt(bool *ok, int base) const -
3326{ -
3327 qlonglong v = toLongLong(ok, base);
executed (the execution status of this line is deduced): qlonglong v = toLongLong(ok, base);
-
3328 if (v < INT_MIN || v > INT_MAX) {
partially evaluated: v < (-2147483647 - 1)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:179820
evaluated: v > 2147483647
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:179724
0-179820
3329 if (ok)
partially evaluated: ok
TRUEFALSE
yes
Evaluation Count:96
no
Evaluation Count:0
0-96
3330 *ok = false;
executed: *ok = false;
Execution Count:96
96
3331 v = 0;
executed (the execution status of this line is deduced): v = 0;
-
3332 }
executed: }
Execution Count:96
96
3333 return int(v);
executed: return int(v);
Execution Count:179820
179820
3334} -
3335 -
3336/*! -
3337 Returns the byte array converted to an \c {unsigned int} using base \a -
3338 base, which is 10 by default and must be between 2 and 36, or 0. -
3339 -
3340 If \a base is 0, the base is determined automatically using the -
3341 following rules: If the byte array begins with "0x", it is assumed to -
3342 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3343 otherwise it is assumed to be decimal. -
3344 -
3345 Returns 0 if the conversion fails. -
3346 -
3347 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3348 false; otherwise *\a{ok} is set to true. -
3349 -
3350 \note The conversion of the number is performed in the default C locale, -
3351 irrespective of the user's locale. -
3352 -
3353 \sa number() -
3354*/ -
3355 -
3356uint QByteArray::toUInt(bool *ok, int base) const -
3357{ -
3358 qulonglong v = toULongLong(ok, base);
never executed (the execution status of this line is deduced): qulonglong v = toULongLong(ok, base);
-
3359 if (v > UINT_MAX) {
never evaluated: v > (2147483647 * 2U + 1U)
0
3360 if (ok)
never evaluated: ok
0
3361 *ok = false;
never executed: *ok = false;
0
3362 v = 0;
never executed (the execution status of this line is deduced): v = 0;
-
3363 }
never executed: }
0
3364 return uint(v);
never executed: return uint(v);
0
3365} -
3366 -
3367/*! -
3368 \since 4.1 -
3369 -
3370 Returns the byte array converted to a \c long int using base \a -
3371 base, which is 10 by default and must be between 2 and 36, or 0. -
3372 -
3373 If \a base is 0, the base is determined automatically using the -
3374 following rules: If the byte array begins with "0x", it is assumed to -
3375 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3376 otherwise it is assumed to be decimal. -
3377 -
3378 Returns 0 if the conversion fails. -
3379 -
3380 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3381 false; otherwise *\a{ok} is set to true. -
3382 -
3383 \snippet code/src_corelib_tools_qbytearray.cpp 37 -
3384 -
3385 \note The conversion of the number is performed in the default C locale, -
3386 irrespective of the user's locale. -
3387 -
3388 \sa number() -
3389*/ -
3390long QByteArray::toLong(bool *ok, int base) const -
3391{ -
3392 qlonglong v = toLongLong(ok, base);
executed (the execution status of this line is deduced): qlonglong v = toLongLong(ok, base);
-
3393 if (v < LONG_MIN || v > LONG_MAX) {
partially evaluated: v < (-9223372036854775807L - 1L)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:238
partially evaluated: v > 9223372036854775807L
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:238
0-238
3394 if (ok)
never evaluated: ok
0
3395 *ok = false;
never executed: *ok = false;
0
3396 v = 0;
never executed (the execution status of this line is deduced): v = 0;
-
3397 }
never executed: }
0
3398 return long(v);
executed: return long(v);
Execution Count:238
238
3399} -
3400 -
3401/*! -
3402 \since 4.1 -
3403 -
3404 Returns the byte array converted to an \c {unsigned long int} using base \a -
3405 base, which is 10 by default and must be between 2 and 36, or 0. -
3406 -
3407 If \a base is 0, the base is determined automatically using the -
3408 following rules: If the byte array begins with "0x", it is assumed to -
3409 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3410 otherwise it is assumed to be decimal. -
3411 -
3412 Returns 0 if the conversion fails. -
3413 -
3414 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3415 false; otherwise *\a{ok} is set to true. -
3416 -
3417 \note The conversion of the number is performed in the default C locale, -
3418 irrespective of the user's locale. -
3419 -
3420 \sa number() -
3421*/ -
3422ulong QByteArray::toULong(bool *ok, int base) const -
3423{ -
3424 qulonglong v = toULongLong(ok, base);
executed (the execution status of this line is deduced): qulonglong v = toULongLong(ok, base);
-
3425 if (v > ULONG_MAX) {
partially evaluated: v > (9223372036854775807L * 2UL + 1UL)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
3426 if (ok)
never evaluated: ok
0
3427 *ok = false;
never executed: *ok = false;
0
3428 v = 0;
never executed (the execution status of this line is deduced): v = 0;
-
3429 }
never executed: }
0
3430 return ulong(v);
executed: return ulong(v);
Execution Count:10
10
3431} -
3432 -
3433/*! -
3434 Returns the byte array converted to a \c short using base \a -
3435 base, which is 10 by default and must be between 2 and 36, or 0. -
3436 -
3437 If \a base is 0, the base is determined automatically using the -
3438 following rules: If the byte array begins with "0x", it is assumed to -
3439 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3440 otherwise it is assumed to be decimal. -
3441 -
3442 Returns 0 if the conversion fails. -
3443 -
3444 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3445 false; otherwise *\a{ok} is set to true. -
3446 -
3447 \note The conversion of the number is performed in the default C locale, -
3448 irrespective of the user's locale. -
3449 -
3450 \sa number() -
3451*/ -
3452 -
3453short QByteArray::toShort(bool *ok, int base) const -
3454{ -
3455 qlonglong v = toLongLong(ok, base);
never executed (the execution status of this line is deduced): qlonglong v = toLongLong(ok, base);
-
3456 if (v < SHRT_MIN || v > SHRT_MAX) {
never evaluated: v < (-32767 - 1)
never evaluated: v > 32767
0
3457 if (ok)
never evaluated: ok
0
3458 *ok = false;
never executed: *ok = false;
0
3459 v = 0;
never executed (the execution status of this line is deduced): v = 0;
-
3460 }
never executed: }
0
3461 return short(v);
never executed: return short(v);
0
3462} -
3463 -
3464/*! -
3465 Returns the byte array converted to an \c {unsigned short} using base \a -
3466 base, which is 10 by default and must be between 2 and 36, or 0. -
3467 -
3468 If \a base is 0, the base is determined automatically using the -
3469 following rules: If the byte array begins with "0x", it is assumed to -
3470 be hexadecimal; if it begins with "0", it is assumed to be octal; -
3471 otherwise it is assumed to be decimal. -
3472 -
3473 Returns 0 if the conversion fails. -
3474 -
3475 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3476 false; otherwise *\a{ok} is set to true. -
3477 -
3478 \note The conversion of the number is performed in the default C locale, -
3479 irrespective of the user's locale. -
3480 -
3481 \sa number() -
3482*/ -
3483 -
3484ushort QByteArray::toUShort(bool *ok, int base) const -
3485{ -
3486 qulonglong v = toULongLong(ok, base);
never executed (the execution status of this line is deduced): qulonglong v = toULongLong(ok, base);
-
3487 if (v > USHRT_MAX) {
never evaluated: v > (32767 * 2 + 1)
0
3488 if (ok)
never evaluated: ok
0
3489 *ok = false;
never executed: *ok = false;
0
3490 v = 0;
never executed (the execution status of this line is deduced): v = 0;
-
3491 }
never executed: }
0
3492 return ushort(v);
never executed: return ushort(v);
0
3493} -
3494 -
3495 -
3496/*! -
3497 Returns the byte array converted to a \c double value. -
3498 -
3499 Returns 0.0 if the conversion fails. -
3500 -
3501 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3502 false; otherwise *\a{ok} is set to true. -
3503 -
3504 \snippet code/src_corelib_tools_qbytearray.cpp 38 -
3505 -
3506 \note The conversion of the number is performed in the default C locale, -
3507 irrespective of the user's locale. -
3508 -
3509 \sa number() -
3510*/ -
3511 -
3512double QByteArray::toDouble(bool *ok) const -
3513{ -
3514 return QLocalePrivate::bytearrayToDouble(nulTerminated().constData(), ok);
executed: return QLocalePrivate::bytearrayToDouble(nulTerminated().constData(), ok);
Execution Count:395
395
3515} -
3516 -
3517/*! -
3518 Returns the byte array converted to a \c float value. -
3519 -
3520 Returns 0.0 if the conversion fails. -
3521 -
3522 If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to -
3523 false; otherwise *\a{ok} is set to true. -
3524 -
3525 \note The conversion of the number is performed in the default C locale, -
3526 irrespective of the user's locale. -
3527 -
3528 \sa number() -
3529*/ -
3530 -
3531float QByteArray::toFloat(bool *ok) const -
3532{ -
3533 return float(toDouble(ok));
executed: return float(toDouble(ok));
Execution Count:1
1
3534} -
3535 -
3536/*! -
3537 Returns a copy of the byte array, encoded as Base64. -
3538 -
3539 \snippet code/src_corelib_tools_qbytearray.cpp 39 -
3540 -
3541 The algorithm used to encode Base64-encoded data is defined in \l{RFC 2045}. -
3542 -
3543 \sa fromBase64() -
3544*/ -
3545QByteArray QByteArray::toBase64() const -
3546{ -
3547 const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef"
executed (the execution status of this line is deduced): const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef"
-
3548 "ghijklmn" "opqrstuv" "wxyz0123" "456789+/";
executed (the execution status of this line is deduced): "ghijklmn" "opqrstuv" "wxyz0123" "456789+/";
-
3549 const char padchar = '=';
executed (the execution status of this line is deduced): const char padchar = '=';
-
3550 int padlen = 0;
executed (the execution status of this line is deduced): int padlen = 0;
-
3551 -
3552 QByteArray tmp((d->size * 4) / 3 + 3, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray tmp((d->size * 4) / 3 + 3, Qt::Uninitialized);
-
3553 -
3554 int i = 0;
executed (the execution status of this line is deduced): int i = 0;
-
3555 char *out = tmp.data();
executed (the execution status of this line is deduced): char *out = tmp.data();
-
3556 while (i < d->size) {
evaluated: i < d->size
TRUEFALSE
yes
Evaluation Count:756025
yes
Evaluation Count:596
596-756025
3557 int chunk = 0;
executed (the execution status of this line is deduced): int chunk = 0;
-
3558 chunk |= int(uchar(d->data()[i++])) << 16;
executed (the execution status of this line is deduced): chunk |= int(uchar(d->data()[i++])) << 16;
-
3559 if (i == d->size) {
evaluated: i == d->size
TRUEFALSE
yes
Evaluation Count:234
yes
Evaluation Count:755791
234-755791
3560 padlen = 2;
executed (the execution status of this line is deduced): padlen = 2;
-
3561 } else {
executed: }
Execution Count:234
234
3562 chunk |= int(uchar(d->data()[i++])) << 8;
executed (the execution status of this line is deduced): chunk |= int(uchar(d->data()[i++])) << 8;
-
3563 if (i == d->size) padlen = 1;
executed: padlen = 1;
Execution Count:191
evaluated: i == d->size
TRUEFALSE
yes
Evaluation Count:191
yes
Evaluation Count:755600
191-755600
3564 else chunk |= int(uchar(d->data()[i++]));
executed: chunk |= int(uchar(d->data()[i++]));
Execution Count:755600
755600
3565 } -
3566 -
3567 int j = (chunk & 0x00fc0000) >> 18;
executed (the execution status of this line is deduced): int j = (chunk & 0x00fc0000) >> 18;
-
3568 int k = (chunk & 0x0003f000) >> 12;
executed (the execution status of this line is deduced): int k = (chunk & 0x0003f000) >> 12;
-
3569 int l = (chunk & 0x00000fc0) >> 6;
executed (the execution status of this line is deduced): int l = (chunk & 0x00000fc0) >> 6;
-
3570 int m = (chunk & 0x0000003f);
executed (the execution status of this line is deduced): int m = (chunk & 0x0000003f);
-
3571 *out++ = alphabet[j];
executed (the execution status of this line is deduced): *out++ = alphabet[j];
-
3572 *out++ = alphabet[k];
executed (the execution status of this line is deduced): *out++ = alphabet[k];
-
3573 if (padlen > 1) *out++ = padchar;
executed: *out++ = padchar;
Execution Count:234
evaluated: padlen > 1
TRUEFALSE
yes
Evaluation Count:234
yes
Evaluation Count:755791
234-755791
3574 else *out++ = alphabet[l];
executed: *out++ = alphabet[l];
Execution Count:755791
755791
3575 if (padlen > 0) *out++ = padchar;
executed: *out++ = padchar;
Execution Count:425
evaluated: padlen > 0
TRUEFALSE
yes
Evaluation Count:425
yes
Evaluation Count:755600
425-755600
3576 else *out++ = alphabet[m];
executed: *out++ = alphabet[m];
Execution Count:755600
755600
3577 } -
3578 -
3579 tmp.truncate(out - tmp.data());
executed (the execution status of this line is deduced): tmp.truncate(out - tmp.data());
-
3580 return tmp;
executed: return tmp;
Execution Count:596
596
3581} -
3582 -
3583/*! -
3584 \fn QByteArray &QByteArray::setNum(int n, int base) -
3585 -
3586 Sets the byte array to the printed value of \a n in base \a base (10 -
3587 by default) and returns a reference to the byte array. The \a base can -
3588 be any value between 2 and 36. For bases other than 10, n is treated -
3589 as an unsigned integer. -
3590 -
3591 Example: -
3592 \snippet code/src_corelib_tools_qbytearray.cpp 40 -
3593 -
3594 \note The format of the number is not localized; the default C locale -
3595 is used irrespective of the user's locale. -
3596 -
3597 \sa number(), toInt() -
3598*/ -
3599 -
3600/*! -
3601 \fn QByteArray &QByteArray::setNum(uint n, int base) -
3602 \overload -
3603 -
3604 \sa toUInt() -
3605*/ -
3606 -
3607/*! -
3608 \fn QByteArray &QByteArray::setNum(short n, int base) -
3609 \overload -
3610 -
3611 \sa toShort() -
3612*/ -
3613 -
3614/*! -
3615 \fn QByteArray &QByteArray::setNum(ushort n, int base) -
3616 \overload -
3617 -
3618 \sa toUShort() -
3619*/ -
3620 -
3621/*! -
3622 \overload -
3623 -
3624 \sa toLongLong() -
3625*/ -
3626 -
3627static char *qulltoa2(char *p, qulonglong n, int base) -
3628{ -
3629#if defined(QT_CHECK_RANGE) -
3630 if (base < 2 || base > 36) { -
3631 qWarning("QByteArray::setNum: Invalid base %d", base); -
3632 base = 10; -
3633 } -
3634#endif -
3635 const char b = 'a' - 10;
executed (the execution status of this line is deduced): const char b = 'a' - 10;
-
3636 do { -
3637 const int c = n % base;
executed (the execution status of this line is deduced): const int c = n % base;
-
3638 n /= base;
executed (the execution status of this line is deduced): n /= base;
-
3639 *--p = c + (c < 10 ? '0' : b);
evaluated: c < 10
TRUEFALSE
yes
Evaluation Count:2271121
yes
Evaluation Count:20957
20957-2271121
3640 } while (n);
executed: }
Execution Count:2292078
evaluated: n
TRUEFALSE
yes
Evaluation Count:1850073
yes
Evaluation Count:442005
442005-2292078
3641 -
3642 return p;
executed: return p;
Execution Count:442005
442005
3643} -
3644 -
3645QByteArray &QByteArray::setNum(qlonglong n, int base) -
3646{ -
3647 const int buffsize = 66; // big enough for MAX_ULLONG in base 2
executed (the execution status of this line is deduced): const int buffsize = 66;
-
3648 char buff[buffsize];
executed (the execution status of this line is deduced): char buff[buffsize];
-
3649 char *p;
executed (the execution status of this line is deduced): char *p;
-
3650 -
3651 if (n < 0 && base == 10) {
evaluated: n < 0
TRUEFALSE
yes
Evaluation Count:148
yes
Evaluation Count:417137
evaluated: base == 10
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:136
12-417137
3652 p = qulltoa2(buff + buffsize, qulonglong(-(1 + n)) + 1, base);
executed (the execution status of this line is deduced): p = qulltoa2(buff + buffsize, qulonglong(-(1 + n)) + 1, base);
-
3653 *--p = '-';
executed (the execution status of this line is deduced): *--p = '-';
-
3654 } else {
executed: }
Execution Count:12
12
3655 p = qulltoa2(buff + buffsize, qulonglong(n), base);
executed (the execution status of this line is deduced): p = qulltoa2(buff + buffsize, qulonglong(n), base);
-
3656 }
executed: }
Execution Count:417273
417273
3657 -
3658 clear();
executed (the execution status of this line is deduced): clear();
-
3659 append(p, buffsize - (p - buff));
executed (the execution status of this line is deduced): append(p, buffsize - (p - buff));
-
3660 return *this;
executed: return *this;
Execution Count:417285
417285
3661} -
3662 -
3663/*! -
3664 \overload -
3665 -
3666 \sa toULongLong() -
3667*/ -
3668 -
3669QByteArray &QByteArray::setNum(qulonglong n, int base) -
3670{ -
3671 const int buffsize = 66; // big enough for MAX_ULLONG in base 2
executed (the execution status of this line is deduced): const int buffsize = 66;
-
3672 char buff[buffsize];
executed (the execution status of this line is deduced): char buff[buffsize];
-
3673 char *p = qulltoa2(buff + buffsize, n, base);
executed (the execution status of this line is deduced): char *p = qulltoa2(buff + buffsize, n, base);
-
3674 -
3675 clear();
executed (the execution status of this line is deduced): clear();
-
3676 append(p, buffsize - (p - buff));
executed (the execution status of this line is deduced): append(p, buffsize - (p - buff));
-
3677 return *this;
executed: return *this;
Execution Count:24720
24720
3678} -
3679 -
3680/*! -
3681 \overload -
3682 -
3683 Sets the byte array to the printed value of \a n, formatted in format -
3684 \a f with precision \a prec, and returns a reference to the -
3685 byte array. -
3686 -
3687 The format \a f can be any of the following: -
3688 -
3689 \table -
3690 \header \li Format \li Meaning -
3691 \row \li \c e \li format as [-]9.9e[+|-]999 -
3692 \row \li \c E \li format as [-]9.9E[+|-]999 -
3693 \row \li \c f \li format as [-]9.9 -
3694 \row \li \c g \li use \c e or \c f format, whichever is the most concise -
3695 \row \li \c G \li use \c E or \c f format, whichever is the most concise -
3696 \endtable -
3697 -
3698 With 'e', 'E', and 'f', \a prec is the number of digits after the -
3699 decimal point. With 'g' and 'G', \a prec is the maximum number of -
3700 significant digits (trailing zeroes are omitted). -
3701 -
3702 \note The format of the number is not localized; the default C locale -
3703 is used irrespective of the user's locale. -
3704 -
3705 \sa toDouble() -
3706*/ -
3707 -
3708QByteArray &QByteArray::setNum(double n, char f, int prec) -
3709{ -
3710 QLocalePrivate::DoubleForm form = QLocalePrivate::DFDecimal;
executed (the execution status of this line is deduced): QLocalePrivate::DoubleForm form = QLocalePrivate::DFDecimal;
-
3711 uint flags = 0;
executed (the execution status of this line is deduced): uint flags = 0;
-
3712 -
3713 if (qIsUpper(f))
partially evaluated: qIsUpper(f)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:450222
0-450222
3714 flags = QLocalePrivate::CapitalEorX;
never executed: flags = QLocalePrivate::CapitalEorX;
0
3715 f = qToLower(f);
executed (the execution status of this line is deduced): f = qToLower(f);
-
3716 -
3717 switch (f) { -
3718 case 'f': -
3719 form = QLocalePrivate::DFDecimal;
never executed (the execution status of this line is deduced): form = QLocalePrivate::DFDecimal;
-
3720 break;
never executed: break;
0
3721 case 'e': -
3722 form = QLocalePrivate::DFExponent;
never executed (the execution status of this line is deduced): form = QLocalePrivate::DFExponent;
-
3723 break;
never executed: break;
0
3724 case 'g': -
3725 form = QLocalePrivate::DFSignificantDigits;
executed (the execution status of this line is deduced): form = QLocalePrivate::DFSignificantDigits;
-
3726 break;
executed: break;
Execution Count:450222
450222
3727 default: -
3728#if defined(QT_CHECK_RANGE) -
3729 qWarning("QByteArray::setNum: Invalid format char '%c'", f); -
3730#endif -
3731 break;
never executed: break;
0
3732 } -
3733 -
3734 QLocale locale(QLocale::C);
executed (the execution status of this line is deduced): QLocale locale(QLocale::C);
-
3735 *this = locale.d->doubleToString(n, prec, form, -1, flags).toLatin1();
executed (the execution status of this line is deduced): *this = locale.d->doubleToString(n, prec, form, -1, flags).toLatin1();
-
3736 return *this;
executed: return *this;
Execution Count:450222
450222
3737} -
3738 -
3739/*! -
3740 \fn QByteArray &QByteArray::setNum(float n, char f, int prec) -
3741 \overload -
3742 -
3743 Sets the byte array to the printed value of \a n, formatted in format -
3744 \a f with precision \a prec, and returns a reference to the -
3745 byte array. -
3746 -
3747 \note The format of the number is not localized; the default C locale -
3748 is used irrespective of the user's locale. -
3749 -
3750 \sa toFloat() -
3751*/ -
3752 -
3753/*! -
3754 Returns a byte array containing the string equivalent of the -
3755 number \a n to base \a base (10 by default). The \a base can be -
3756 any value between 2 and 36. -
3757 -
3758 Example: -
3759 \snippet code/src_corelib_tools_qbytearray.cpp 41 -
3760 -
3761 \note The format of the number is not localized; the default C locale -
3762 is used irrespective of the user's locale. -
3763 -
3764 \sa setNum(), toInt() -
3765*/ -
3766QByteArray QByteArray::number(int n, int base) -
3767{ -
3768 QByteArray s;
executed (the execution status of this line is deduced): QByteArray s;
-
3769 s.setNum(n, base);
executed (the execution status of this line is deduced): s.setNum(n, base);
-
3770 return s;
executed: return s;
Execution Count:420949
420949
3771} -
3772 -
3773/*! -
3774 \overload -
3775 -
3776 \sa toUInt() -
3777*/ -
3778QByteArray QByteArray::number(uint n, int base) -
3779{ -
3780 QByteArray s;
executed (the execution status of this line is deduced): QByteArray s;
-
3781 s.setNum(n, base);
executed (the execution status of this line is deduced): s.setNum(n, base);
-
3782 return s;
executed: return s;
Execution Count:20316
20316
3783} -
3784 -
3785/*! -
3786 \overload -
3787 -
3788 \sa toLongLong() -
3789*/ -
3790QByteArray QByteArray::number(qlonglong n, int base) -
3791{ -
3792 QByteArray s;
executed (the execution status of this line is deduced): QByteArray s;
-
3793 s.setNum(n, base);
executed (the execution status of this line is deduced): s.setNum(n, base);
-
3794 return s;
executed: return s;
Execution Count:711
711
3795} -
3796 -
3797/*! -
3798 \overload -
3799 -
3800 \sa toULongLong() -
3801*/ -
3802QByteArray QByteArray::number(qulonglong n, int base) -
3803{ -
3804 QByteArray s;
executed (the execution status of this line is deduced): QByteArray s;
-
3805 s.setNum(n, base);
executed (the execution status of this line is deduced): s.setNum(n, base);
-
3806 return s;
executed: return s;
Execution Count:6
6
3807} -
3808 -
3809/*! -
3810 \overload -
3811 -
3812 Returns a byte array that contains the printed value of \a n, -
3813 formatted in format \a f with precision \a prec. -
3814 -
3815 Argument \a n is formatted according to the \a f format specified, -
3816 which is \c g by default, and can be any of the following: -
3817 -
3818 \table -
3819 \header \li Format \li Meaning -
3820 \row \li \c e \li format as [-]9.9e[+|-]999 -
3821 \row \li \c E \li format as [-]9.9E[+|-]999 -
3822 \row \li \c f \li format as [-]9.9 -
3823 \row \li \c g \li use \c e or \c f format, whichever is the most concise -
3824 \row \li \c G \li use \c E or \c f format, whichever is the most concise -
3825 \endtable -
3826 -
3827 With 'e', 'E', and 'f', \a prec is the number of digits after the -
3828 decimal point. With 'g' and 'G', \a prec is the maximum number of -
3829 significant digits (trailing zeroes are omitted). -
3830 -
3831 \snippet code/src_corelib_tools_qbytearray.cpp 42 -
3832 -
3833 \note The format of the number is not localized; the default C locale -
3834 is used irrespective of the user's locale. -
3835 -
3836 \sa toDouble() -
3837*/ -
3838QByteArray QByteArray::number(double n, char f, int prec) -
3839{ -
3840 QByteArray s;
executed (the execution status of this line is deduced): QByteArray s;
-
3841 s.setNum(n, f, prec);
executed (the execution status of this line is deduced): s.setNum(n, f, prec);
-
3842 return s;
executed: return s;
Execution Count:450219
450219
3843} -
3844 -
3845/*! -
3846 Constructs a QByteArray that uses the first \a size bytes of the -
3847 \a data array. The bytes are \e not copied. The QByteArray will -
3848 contain the \a data pointer. The caller guarantees that \a data -
3849 will not be deleted or modified as long as this QByteArray and any -
3850 copies of it exist that have not been modified. In other words, -
3851 because QByteArray is an \l{implicitly shared} class and the -
3852 instance returned by this function contains the \a data pointer, -
3853 the caller must not delete \a data or modify it directly as long -
3854 as the returned QByteArray and any copies exist. However, -
3855 QByteArray does not take ownership of \a data, so the QByteArray -
3856 destructor will never delete the raw \a data, even when the -
3857 last QByteArray referring to \a data is destroyed. -
3858 -
3859 A subsequent attempt to modify the contents of the returned -
3860 QByteArray or any copy made from it will cause it to create a deep -
3861 copy of the \a data array before doing the modification. This -
3862 ensures that the raw \a data array itself will never be modified -
3863 by QByteArray. -
3864 -
3865 Here is an example of how to read data using a QDataStream on raw -
3866 data in memory without copying the raw data into a QByteArray: -
3867 -
3868 \snippet code/src_corelib_tools_qbytearray.cpp 43 -
3869 -
3870 \warning A byte array created with fromRawData() is \e not -
3871 null-terminated, unless the raw data contains a 0 character at -
3872 position \a size. While that does not matter for QDataStream or -
3873 functions like indexOf(), passing the byte array to a function -
3874 accepting a \c{const char *} expected to be '\\0'-terminated will -
3875 fail. -
3876 -
3877 \sa setRawData(), data(), constData() -
3878*/ -
3879 -
3880QByteArray QByteArray::fromRawData(const char *data, int size) -
3881{ -
3882 Data *x;
executed (the execution status of this line is deduced): Data *x;
-
3883 if (!data) {
partially evaluated: !data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1888933
0-1888933
3884 x = Data::sharedNull();
never executed (the execution status of this line is deduced): x = Data::sharedNull();
-
3885 } else if (!size) {
never executed: }
evaluated: !size
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:1888900
0-1888900
3886 x = Data::allocate(0);
executed (the execution status of this line is deduced): x = Data::allocate(0);
-
3887 } else {
executed: }
Execution Count:34
34
3888 x = Data::fromRawData(data, size);
executed (the execution status of this line is deduced): x = Data::fromRawData(data, size);
-
3889 Q_CHECK_PTR(x);
never executed: qBadAlloc();
executed: }
Execution Count:1888894
partially evaluated: !(x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1888896
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1888895
0-1888896
3890 }
executed: }
Execution Count:1888895
1888895
3891 QByteArrayDataPtr dataPtr = { reinterpret_cast<QByteArrayData *>(x) };
executed (the execution status of this line is deduced): QByteArrayDataPtr dataPtr = { reinterpret_cast<QByteArrayData *>(x) };
-
3892 return QByteArray(dataPtr);
executed: return QByteArray(dataPtr);
Execution Count:1888931
1888931
3893} -
3894 -
3895/*! -
3896 \since 4.7 -
3897 -
3898 Resets the QByteArray to use the first \a size bytes of the -
3899 \a data array. The bytes are \e not copied. The QByteArray will -
3900 contain the \a data pointer. The caller guarantees that \a data -
3901 will not be deleted or modified as long as this QByteArray and any -
3902 copies of it exist that have not been modified. -
3903 -
3904 This function can be used instead of fromRawData() to re-use -
3905 existings QByteArray objects to save memory re-allocations. -
3906 -
3907 \sa fromRawData(), data(), constData() -
3908*/ -
3909QByteArray &QByteArray::setRawData(const char *data, uint size) -
3910{ -
3911 if (d->ref.isShared() || d->alloc) {
never evaluated: d->ref.isShared()
never evaluated: d->alloc
0
3912 *this = fromRawData(data, size);
never executed (the execution status of this line is deduced): *this = fromRawData(data, size);
-
3913 } else {
never executed: }
0
3914 if (data) {
never evaluated: data
0
3915 d->size = size;
never executed (the execution status of this line is deduced): d->size = size;
-
3916 d->offset = data - reinterpret_cast<char *>(d);
never executed (the execution status of this line is deduced): d->offset = data - reinterpret_cast<char *>(d);
-
3917 } else {
never executed: }
0
3918 d->offset = sizeof(QByteArrayData);
never executed (the execution status of this line is deduced): d->offset = sizeof(QByteArrayData);
-
3919 d->size = 0;
never executed (the execution status of this line is deduced): d->size = 0;
-
3920 *d->data() = 0;
never executed (the execution status of this line is deduced): *d->data() = 0;
-
3921 }
never executed: }
0
3922 } -
3923 return *this;
never executed: return *this;
0
3924} -
3925 -
3926/*! -
3927 Returns a decoded copy of the Base64 array \a base64. Input is not checked -
3928 for validity; invalid characters in the input are skipped, enabling the -
3929 decoding process to continue with subsequent characters. -
3930 -
3931 For example: -
3932 -
3933 \snippet code/src_corelib_tools_qbytearray.cpp 44 -
3934 -
3935 The algorithm used to decode Base64-encoded data is defined in \l{RFC 2045}. -
3936 -
3937 \sa toBase64() -
3938*/ -
3939QByteArray QByteArray::fromBase64(const QByteArray &base64) -
3940{ -
3941 unsigned int buf = 0;
executed (the execution status of this line is deduced): unsigned int buf = 0;
-
3942 int nbits = 0;
executed (the execution status of this line is deduced): int nbits = 0;
-
3943 QByteArray tmp((base64.size() * 3) / 4, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray tmp((base64.size() * 3) / 4, Qt::Uninitialized);
-
3944 -
3945 int offset = 0;
executed (the execution status of this line is deduced): int offset = 0;
-
3946 for (int i = 0; i < base64.size(); ++i) {
evaluated: i < base64.size()
TRUEFALSE
yes
Evaluation Count:3804163
yes
Evaluation Count:1315
1315-3804163
3947 int ch = base64.at(i);
executed (the execution status of this line is deduced): int ch = base64.at(i);
-
3948 int d;
executed (the execution status of this line is deduced): int d;
-
3949 -
3950 if (ch >= 'A' && ch <= 'Z')
evaluated: ch >= 'A'
TRUEFALSE
yes
Evaluation Count:3323384
yes
Evaluation Count:480779
evaluated: ch <= 'Z'
TRUEFALSE
yes
Evaluation Count:2079472
yes
Evaluation Count:1243912
480779-3323384
3951 d = ch - 'A';
executed: d = ch - 'A';
Execution Count:2079472
2079472
3952 else if (ch >= 'a' && ch <= 'z')
evaluated: ch >= 'a'
TRUEFALSE
yes
Evaluation Count:1243912
yes
Evaluation Count:480779
partially evaluated: ch <= 'z'
TRUEFALSE
yes
Evaluation Count:1243912
no
Evaluation Count:0
0-1243912
3953 d = ch - 'a' + 26;
executed: d = ch - 'a' + 26;
Execution Count:1243912
1243912
3954 else if (ch >= '0' && ch <= '9')
evaluated: ch >= '0'
TRUEFALSE
yes
Evaluation Count:416525
yes
Evaluation Count:64254
evaluated: ch <= '9'
TRUEFALSE
yes
Evaluation Count:414982
yes
Evaluation Count:1543
1543-416525
3955 d = ch - '0' + 52;
executed: d = ch - '0' + 52;
Execution Count:414982
414982
3956 else if (ch == '+')
evaluated: ch == '+'
TRUEFALSE
yes
Evaluation Count:22115
yes
Evaluation Count:43682
22115-43682
3957 d = 62;
executed: d = 62;
Execution Count:22115
22115
3958 else if (ch == '/')
evaluated: ch == '/'
TRUEFALSE
yes
Evaluation Count:26051
yes
Evaluation Count:17631
17631-26051
3959 d = 63;
executed: d = 63;
Execution Count:26051
26051
3960 else -
3961 d = -1;
executed: d = -1;
Execution Count:17631
17631
3962 -
3963 if (d != -1) {
evaluated: d != -1
TRUEFALSE
yes
Evaluation Count:3786532
yes
Evaluation Count:17631
17631-3786532
3964 buf = (buf << 6) | d;
executed (the execution status of this line is deduced): buf = (buf << 6) | d;
-
3965 nbits += 6;
executed (the execution status of this line is deduced): nbits += 6;
-
3966 if (nbits >= 8) {
evaluated: nbits >= 8
TRUEFALSE
yes
Evaluation Count:2839534
yes
Evaluation Count:946998
946998-2839534
3967 nbits -= 8;
executed (the execution status of this line is deduced): nbits -= 8;
-
3968 tmp[offset++] = buf >> nbits;
executed (the execution status of this line is deduced): tmp[offset++] = buf >> nbits;
-
3969 buf &= (1 << nbits) - 1;
executed (the execution status of this line is deduced): buf &= (1 << nbits) - 1;
-
3970 }
executed: }
Execution Count:2839534
2839534
3971 }
executed: }
Execution Count:3786532
3786532
3972 }
executed: }
Execution Count:3804163
3804163
3973 -
3974 tmp.truncate(offset);
executed (the execution status of this line is deduced): tmp.truncate(offset);
-
3975 return tmp;
executed: return tmp;
Execution Count:1315
1315
3976} -
3977 -
3978/*! -
3979 Returns a decoded copy of the hex encoded array \a hexEncoded. Input is not checked -
3980 for validity; invalid characters in the input are skipped, enabling the -
3981 decoding process to continue with subsequent characters. -
3982 -
3983 For example: -
3984 -
3985 \snippet code/src_corelib_tools_qbytearray.cpp 45 -
3986 -
3987 \sa toHex() -
3988*/ -
3989QByteArray QByteArray::fromHex(const QByteArray &hexEncoded) -
3990{ -
3991 QByteArray res((hexEncoded.size() + 1)/ 2, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray res((hexEncoded.size() + 1)/ 2, Qt::Uninitialized);
-
3992 uchar *result = (uchar *)res.data() + res.size();
executed (the execution status of this line is deduced): uchar *result = (uchar *)res.data() + res.size();
-
3993 -
3994 bool odd_digit = true;
executed (the execution status of this line is deduced): bool odd_digit = true;
-
3995 for (int i = hexEncoded.size() - 1; i >= 0; --i) {
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:5648
yes
Evaluation Count:66
66-5648
3996 int ch = hexEncoded.at(i);
executed (the execution status of this line is deduced): int ch = hexEncoded.at(i);
-
3997 int tmp;
executed (the execution status of this line is deduced): int tmp;
-
3998 if (ch >= '0' && ch <= '9')
evaluated: ch >= '0'
TRUEFALSE
yes
Evaluation Count:5615
yes
Evaluation Count:33
evaluated: ch <= '9'
TRUEFALSE
yes
Evaluation Count:3170
yes
Evaluation Count:2445
33-5615
3999 tmp = ch - '0';
executed: tmp = ch - '0';
Execution Count:3170
3170
4000 else if (ch >= 'a' && ch <= 'f')
evaluated: ch >= 'a'
TRUEFALSE
yes
Evaluation Count:631
yes
Evaluation Count:1847
evaluated: ch <= 'f'
TRUEFALSE
yes
Evaluation Count:609
yes
Evaluation Count:22
22-1847
4001 tmp = ch - 'a' + 10;
executed: tmp = ch - 'a' + 10;
Execution Count:609
609
4002 else if (ch >= 'A' && ch <= 'F')
evaluated: ch >= 'A'
TRUEFALSE
yes
Evaluation Count:860
yes
Evaluation Count:1009
evaluated: ch <= 'F'
TRUEFALSE
yes
Evaluation Count:838
yes
Evaluation Count:22
22-1009
4003 tmp = ch - 'A' + 10;
executed: tmp = ch - 'A' + 10;
Execution Count:838
838
4004 else -
4005 continue;
executed: continue;
Execution Count:1031
1031
4006 if (odd_digit) {
evaluated: odd_digit
TRUEFALSE
yes
Evaluation Count:2311
yes
Evaluation Count:2306
2306-2311
4007 --result;
executed (the execution status of this line is deduced): --result;
-
4008 *result = tmp;
executed (the execution status of this line is deduced): *result = tmp;
-
4009 odd_digit = false;
executed (the execution status of this line is deduced): odd_digit = false;
-
4010 } else {
executed: }
Execution Count:2311
2311
4011 *result |= tmp << 4;
executed (the execution status of this line is deduced): *result |= tmp << 4;
-
4012 odd_digit = true;
executed (the execution status of this line is deduced): odd_digit = true;
-
4013 }
executed: }
Execution Count:2306
2306
4014 } -
4015 -
4016 res.remove(0, result - (const uchar *)res.constData());
executed (the execution status of this line is deduced): res.remove(0, result - (const uchar *)res.constData());
-
4017 return res;
executed: return res;
Execution Count:66
66
4018} -
4019 -
4020/*! -
4021 Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and -
4022 the letters a-f. -
4023 -
4024 \sa fromHex() -
4025*/ -
4026QByteArray QByteArray::toHex() const -
4027{ -
4028 QByteArray hex(d->size * 2, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray hex(d->size * 2, Qt::Uninitialized);
-
4029 char *hexData = hex.data();
executed (the execution status of this line is deduced): char *hexData = hex.data();
-
4030 const uchar *data = (const uchar *)d->data();
executed (the execution status of this line is deduced): const uchar *data = (const uchar *)d->data();
-
4031 for (int i = 0; i < d->size; ++i) {
evaluated: i < d->size
TRUEFALSE
yes
Evaluation Count:35977
yes
Evaluation Count:2007
2007-35977
4032 int j = (data[i] >> 4) & 0xf;
executed (the execution status of this line is deduced): int j = (data[i] >> 4) & 0xf;
-
4033 if (j <= 9)
evaluated: j <= 9
TRUEFALSE
yes
Evaluation Count:26259
yes
Evaluation Count:9718
9718-26259
4034 hexData[i*2] = (j + '0');
executed: hexData[i*2] = (j + '0');
Execution Count:26259
26259
4035 else -
4036 hexData[i*2] = (j + 'a' - 10);
executed: hexData[i*2] = (j + 'a' - 10);
Execution Count:9718
9718
4037 j = data[i] & 0xf;
executed (the execution status of this line is deduced): j = data[i] & 0xf;
-
4038 if (j <= 9)
evaluated: j <= 9
TRUEFALSE
yes
Evaluation Count:21656
yes
Evaluation Count:14321
14321-21656
4039 hexData[i*2+1] = (j + '0');
executed: hexData[i*2+1] = (j + '0');
Execution Count:21656
21656
4040 else -
4041 hexData[i*2+1] = (j + 'a' - 10);
executed: hexData[i*2+1] = (j + 'a' - 10);
Execution Count:14321
14321
4042 } -
4043 return hex;
executed: return hex;
Execution Count:2007
2007
4044} -
4045 -
4046static void q_fromPercentEncoding(QByteArray *ba, char percent) -
4047{ -
4048 if (ba->isEmpty())
partially evaluated: ba->isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:60
0-60
4049 return;
never executed: return;
0
4050 -
4051 char *data = ba->data();
executed (the execution status of this line is deduced): char *data = ba->data();
-
4052 const char *inputPtr = data;
executed (the execution status of this line is deduced): const char *inputPtr = data;
-
4053 -
4054 int i = 0;
executed (the execution status of this line is deduced): int i = 0;
-
4055 int len = ba->count();
executed (the execution status of this line is deduced): int len = ba->count();
-
4056 int outlen = 0;
executed (the execution status of this line is deduced): int outlen = 0;
-
4057 int a, b;
executed (the execution status of this line is deduced): int a, b;
-
4058 char c;
executed (the execution status of this line is deduced): char c;
-
4059 while (i < len) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:1853
yes
Evaluation Count:60
60-1853
4060 c = inputPtr[i];
executed (the execution status of this line is deduced): c = inputPtr[i];
-
4061 if (c == percent && i + 2 < len) {
evaluated: c == percent
TRUEFALSE
yes
Evaluation Count:143
yes
Evaluation Count:1710
partially evaluated: i + 2 < len
TRUEFALSE
yes
Evaluation Count:143
no
Evaluation Count:0
0-1710
4062 a = inputPtr[++i];
executed (the execution status of this line is deduced): a = inputPtr[++i];
-
4063 b = inputPtr[++i];
executed (the execution status of this line is deduced): b = inputPtr[++i];
-
4064 -
4065 if (a >= '0' && a <= '9') a -= '0';
executed: a -= '0';
Execution Count:136
partially evaluated: a >= '0'
TRUEFALSE
yes
Evaluation Count:143
no
Evaluation Count:0
evaluated: a <= '9'
TRUEFALSE
yes
Evaluation Count:136
yes
Evaluation Count:7
0-143
4066 else if (a >= 'a' && a <= 'f') a = a - 'a' + 10;
never executed: a = a - 'a' + 10;
partially evaluated: a >= 'a'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
never evaluated: a <= 'f'
0-7
4067 else if (a >= 'A' && a <= 'F') a = a - 'A' + 10;
executed: a = a - 'A' + 10;
Execution Count:7
partially evaluated: a >= 'A'
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
partially evaluated: a <= 'F'
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
4068 -
4069 if (b >= '0' && b <= '9') b -= '0';
executed: b -= '0';
Execution Count:76
partially evaluated: b >= '0'
TRUEFALSE
yes
Evaluation Count:143
no
Evaluation Count:0
evaluated: b <= '9'
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:67
0-143
4070 else if (b >= 'a' && b <= 'f') b = b - 'a' + 10;
never executed: b = b - 'a' + 10;
partially evaluated: b >= 'a'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67
never evaluated: b <= 'f'
0-67
4071 else if (b >= 'A' && b <= 'F') b = b - 'A' + 10;
executed: b = b - 'A' + 10;
Execution Count:67
partially evaluated: b >= 'A'
TRUEFALSE
yes
Evaluation Count:67
no
Evaluation Count:0
partially evaluated: b <= 'F'
TRUEFALSE
yes
Evaluation Count:67
no
Evaluation Count:0
0-67
4072 -
4073 *data++ = (char)((a << 4) | b);
executed (the execution status of this line is deduced): *data++ = (char)((a << 4) | b);
-
4074 } else {
executed: }
Execution Count:143
143
4075 *data++ = c;
executed (the execution status of this line is deduced): *data++ = c;
-
4076 }
executed: }
Execution Count:1710
1710
4077 -
4078 ++i;
executed (the execution status of this line is deduced): ++i;
-
4079 ++outlen;
executed (the execution status of this line is deduced): ++outlen;
-
4080 }
executed: }
Execution Count:1853
1853
4081 -
4082 if (outlen != len)
evaluated: outlen != len
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:26
26-34
4083 ba->truncate(outlen);
executed: ba->truncate(outlen);
Execution Count:34
34
4084}
executed: }
Execution Count:60
60
4085 -
4086void q_fromPercentEncoding(QByteArray *ba) -
4087{ -
4088 q_fromPercentEncoding(ba, '%');
never executed (the execution status of this line is deduced): q_fromPercentEncoding(ba, '%');
-
4089}
never executed: }
0
4090 -
4091/*! -
4092 \since 4.4 -
4093 -
4094 Returns a decoded copy of the URI/URL-style percent-encoded \a input. -
4095 The \a percent parameter allows you to replace the '%' character for -
4096 another (for instance, '_' or '='). -
4097 -
4098 For example: -
4099 \code -
4100 QByteArray text = QByteArray::fromPercentEncoding("Qt%20is%20great%33"); -
4101 text.data(); // returns "Qt is great!" -
4102 \endcode -
4103 -
4104 \sa toPercentEncoding(), QUrl::fromPercentEncoding() -
4105*/ -
4106QByteArray QByteArray::fromPercentEncoding(const QByteArray &input, char percent) -
4107{ -
4108 if (input.isNull())
evaluated: input.isNull()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:64
2-64
4109 return QByteArray(); // preserve null
executed: return QByteArray();
Execution Count:2
2
4110 if (input.isEmpty())
evaluated: input.isEmpty()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:60
4-60
4111 return QByteArray(input.data(), 0);
executed: return QByteArray(input.data(), 0);
Execution Count:4
4
4112 -
4113 QByteArray tmp = input;
executed (the execution status of this line is deduced): QByteArray tmp = input;
-
4114 q_fromPercentEncoding(&tmp, percent);
executed (the execution status of this line is deduced): q_fromPercentEncoding(&tmp, percent);
-
4115 return tmp;
executed: return tmp;
Execution Count:60
60
4116} -
4117 -
4118static inline bool q_strchr(const char str[], char chr) -
4119{ -
4120 if (!str) return false;
never executed: return false;
partially evaluated: !str
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:446
0-446
4121 -
4122 const char *ptr = str;
executed (the execution status of this line is deduced): const char *ptr = str;
-
4123 char c;
executed (the execution status of this line is deduced): char c;
-
4124 while ((c = *ptr++))
evaluated: (c = *ptr++)
TRUEFALSE
yes
Evaluation Count:516
yes
Evaluation Count:397
397-516
4125 if (c == chr)
evaluated: c == chr
TRUEFALSE
yes
Evaluation Count:49
yes
Evaluation Count:467
49-467
4126 return true;
executed: return true;
Execution Count:49
49
4127 return false;
executed: return false;
Execution Count:397
397
4128} -
4129 -
4130static inline char toHexHelper(char c) -
4131{ -
4132 static const char hexnumbers[] = "0123456789ABCDEF"; -
4133 return hexnumbers[c & 0xf];
executed: return hexnumbers[c & 0xf];
Execution Count:212
212
4134} -
4135 -
4136static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const char *alsoEncode, char percent) -
4137{ -
4138 if (ba->isEmpty())
partially evaluated: ba->isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:26
0-26
4139 return;
never executed: return;
0
4140 -
4141 QByteArray input = *ba;
executed (the execution status of this line is deduced): QByteArray input = *ba;
-
4142 int len = input.count();
executed (the execution status of this line is deduced): int len = input.count();
-
4143 const char *inputData = input.constData();
executed (the execution status of this line is deduced): const char *inputData = input.constData();
-
4144 char *output = 0;
executed (the execution status of this line is deduced): char *output = 0;
-
4145 int length = 0;
executed (the execution status of this line is deduced): int length = 0;
-
4146 -
4147 for (int i = 0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:413
yes
Evaluation Count:26
26-413
4148 unsigned char c = *inputData++;
executed (the execution status of this line is deduced): unsigned char c = *inputData++;
-
4149 if (((c >= 0x61 && c <= 0x7A) // ALPHA
evaluated: c >= 0x61
TRUEFALSE
yes
Evaluation Count:210
yes
Evaluation Count:203
evaluated: c <= 0x7A
TRUEFALSE
yes
Evaluation Count:200
yes
Evaluation Count:10
10-210
4150 || (c >= 0x41 && c <= 0x5A) // ALPHA
evaluated: c >= 0x41
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:133
evaluated: c <= 0x5A
TRUEFALSE
yes
Evaluation Count:58
yes
Evaluation Count:22
22-133
4151 || (c >= 0x30 && c <= 0x39) // DIGIT
evaluated: c >= 0x30
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:91
evaluated: c <= 0x39
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:46
18-91
4152 || c == 0x2D // -
evaluated: c == 0x2D
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:131
6-131
4153 || c == 0x2E // .
evaluated: c == 0x2E
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:127
4-127
4154 || c == 0x5F // _
evaluated: c == 0x5F
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:125
2-125
4155 || c == 0x7E // ~
evaluated: c == 0x7E
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:123
2-123
4156 || q_strchr(dontEncode, c))
evaluated: q_strchr(dontEncode, c)
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:90
33-90
4157 && !q_strchr(alsoEncode, c)) {
evaluated: !q_strchr(alsoEncode, c)
TRUEFALSE
yes
Evaluation Count:307
yes
Evaluation Count:16
16-307
4158 if (output)
evaluated: output
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:183
124-183
4159 output[length] = c;
executed: output[length] = c;
Execution Count:124
124
4160 ++length;
executed (the execution status of this line is deduced): ++length;
-
4161 } else {
executed: }
Execution Count:307
307
4162 if (!output) {
evaluated: !output
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:84
22-84
4163 // detach now -
4164 ba->resize(len*3); // worst case
executed (the execution status of this line is deduced): ba->resize(len*3);
-
4165 output = ba->data();
executed (the execution status of this line is deduced): output = ba->data();
-
4166 }
executed: }
Execution Count:22
22
4167 output[length++] = percent;
executed (the execution status of this line is deduced): output[length++] = percent;
-
4168 output[length++] = toHexHelper((c & 0xf0) >> 4);
executed (the execution status of this line is deduced): output[length++] = toHexHelper((c & 0xf0) >> 4);
-
4169 output[length++] = toHexHelper(c & 0xf);
executed (the execution status of this line is deduced): output[length++] = toHexHelper(c & 0xf);
-
4170 }
executed: }
Execution Count:106
106
4171 } -
4172 if (output)
evaluated: output
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:4
4-22
4173 ba->truncate(length);
executed: ba->truncate(length);
Execution Count:22
22
4174}
executed: }
Execution Count:26
26
4175 -
4176void q_toPercentEncoding(QByteArray *ba, const char *exclude, const char *include) -
4177{ -
4178 q_toPercentEncoding(ba, exclude, include, '%');
never executed (the execution status of this line is deduced): q_toPercentEncoding(ba, exclude, include, '%');
-
4179}
never executed: }
0
4180 -
4181void q_normalizePercentEncoding(QByteArray *ba, const char *exclude) -
4182{ -
4183 q_fromPercentEncoding(ba, '%');
never executed (the execution status of this line is deduced): q_fromPercentEncoding(ba, '%');
-
4184 q_toPercentEncoding(ba, exclude, 0, '%');
never executed (the execution status of this line is deduced): q_toPercentEncoding(ba, exclude, 0, '%');
-
4185}
never executed: }
0
4186 -
4187/*! -
4188 \since 4.4 -
4189 -
4190 Returns a URI/URL-style percent-encoded copy of this byte array. The -
4191 \a percent parameter allows you to override the default '%' -
4192 character for another. -
4193 -
4194 By default, this function will encode all characters that are not -
4195 one of the following: -
4196 -
4197 ALPHA ("a" to "z" and "A" to "Z") / DIGIT (0 to 9) / "-" / "." / "_" / "~" -
4198 -
4199 To prevent characters from being encoded pass them to \a -
4200 exclude. To force characters to be encoded pass them to \a -
4201 include. The \a percent character is always encoded. -
4202 -
4203 Example: -
4204 -
4205 \code -
4206 QByteArray text = "{a fishy string?}"; -
4207 QByteArray ba = text.toPercentEncoding("{}", "s"); -
4208 qDebug(ba.constData()); -
4209 // prints "{a fi%73hy %73tring%3F}" -
4210 \endcode -
4211 -
4212 The hex encoding uses the numbers 0-9 and the uppercase letters A-F. -
4213 -
4214 \sa fromPercentEncoding(), QUrl::toPercentEncoding() -
4215*/ -
4216QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteArray &include, -
4217 char percent) const -
4218{ -
4219 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:30
2-30
4220 return QByteArray(); // preserve null
executed: return QByteArray();
Execution Count:2
2
4221 if (isEmpty())
evaluated: isEmpty()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:26
4-26
4222 return QByteArray(data(), 0);
executed: return QByteArray(data(), 0);
Execution Count:4
4
4223 -
4224 QByteArray include2 = include;
executed (the execution status of this line is deduced): QByteArray include2 = include;
-
4225 if (percent != '%') // the default
evaluated: percent != '%'
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:25
1-25
4226 if ((percent >= 0x61 && percent <= 0x7A) // ALPHA
partially evaluated: percent >= 0x61
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never evaluated: percent <= 0x7A
0-1
4227 || (percent >= 0x41 && percent <= 0x5A) // ALPHA
partially evaluated: percent >= 0x41
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: percent <= 0x5A
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
4228 || (percent >= 0x30 && percent <= 0x39) // DIGIT
never evaluated: percent >= 0x30
never evaluated: percent <= 0x39
0
4229 || percent == 0x2D // -
never evaluated: percent == 0x2D
0
4230 || percent == 0x2E // .
never evaluated: percent == 0x2E
0
4231 || percent == 0x5F // _
never evaluated: percent == 0x5F
0
4232 || percent == 0x7E) // ~
never evaluated: percent == 0x7E
0
4233 include2 += percent;
executed: include2 += percent;
Execution Count:1
1
4234 -
4235 QByteArray result = *this;
executed (the execution status of this line is deduced): QByteArray result = *this;
-
4236 q_toPercentEncoding(&result, exclude.nulTerminated().constData(), include2.nulTerminated().constData(), percent);
executed (the execution status of this line is deduced): q_toPercentEncoding(&result, exclude.nulTerminated().constData(), include2.nulTerminated().constData(), percent);
-
4237 -
4238 return result;
executed: return result;
Execution Count:26
26
4239} -
4240 -
4241/*! \typedef QByteArray::ConstIterator -
4242 \internal -
4243*/ -
4244 -
4245/*! \typedef QByteArray::Iterator -
4246 \internal -
4247*/ -
4248 -
4249/*! \typedef QByteArray::const_iterator -
4250 \internal -
4251*/ -
4252 -
4253/*! \typedef QByteArray::iterator -
4254 \internal -
4255*/ -
4256 -
4257/*! \typedef QByteArray::const_reference -
4258 \internal -
4259*/ -
4260 -
4261/*! \typedef QByteArray::reference -
4262 \internal -
4263*/ -
4264 -
4265/*! \typedef QByteArray::value_type -
4266 \internal -
4267 */ -
4268 -
4269/*! -
4270 \fn DataPtr &QByteArray::data_ptr() -
4271 \internal -
4272*/ -
4273 -
4274/*! -
4275 \typedef QByteArray::DataPtr -
4276 \internal -
4277*/ -
4278 -
4279QT_END_NAMESPACE -
4280 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial