source: trunk/src/corelib/tools/qbytearray.h@ 986

Last change on this file since 986 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 23.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QBYTEARRAY_H
43#define QBYTEARRAY_H
44
45#include <QtCore/qatomic.h>
46#include <QtCore/qnamespace.h>
47
48#include <string.h>
49#include <stdarg.h>
50
51#ifdef truncate
52#error qbytearray.h must be included before any header file that defines truncate
53#endif
54
55QT_BEGIN_HEADER
56
57QT_BEGIN_NAMESPACE
58
59QT_MODULE(Core)
60
61/*****************************************************************************
62 Safe and portable C string functions; extensions to standard string.h
63 *****************************************************************************/
64
65Q_CORE_EXPORT char *qstrdup(const char *);
66
67inline uint qstrlen(const char *str)
68{ return str ? uint(strlen(str)) : 0; }
69
70inline uint qstrnlen(const char *str, uint maxlen)
71{
72 uint length = 0;
73 if (str) {
74 while (length < maxlen && *str++)
75 length++;
76 }
77 return length;
78}
79
80Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src);
81Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, uint len);
82
83Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2);
84Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const QByteArray &str2);
85Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const char *str2);
86static inline int qstrcmp(const char *str1, const QByteArray &str2)
87{ return -qstrcmp(str2, str1); }
88
89inline int qstrncmp(const char *str1, const char *str2, uint len)
90{
91 return (str1 && str2) ? strncmp(str1, str2, len)
92 : (str1 ? 1 : (str2 ? -1 : 0));
93}
94Q_CORE_EXPORT int qstricmp(const char *, const char *);
95Q_CORE_EXPORT int qstrnicmp(const char *, const char *, uint len);
96
97// implemented in qvsnprintf.cpp
98Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
99Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
100
101#ifdef QT3_SUPPORT
102inline QT3_SUPPORT void *qmemmove(void *dst, const void *src, uint len)
103{ return memmove(dst, src, len); }
104inline QT3_SUPPORT uint cstrlen(const char *str)
105{ return uint(strlen(str)); }
106inline QT3_SUPPORT char *cstrcpy(char *dst, const char *src)
107{ return qstrcpy(dst,src); }
108inline QT3_SUPPORT int cstrcmp(const char *str1, const char *str2)
109{ return strcmp(str1,str2); }
110inline QT3_SUPPORT int cstrncmp(const char *str1, const char *str2, uint len)
111{ return strncmp(str1,str2,len); }
112#endif
113
114// qChecksum: Internet checksum
115
116Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len);
117
118class QByteRef;
119class QString;
120class QDataStream;
121template <typename T> class QList;
122
123class Q_CORE_EXPORT QByteArray
124{
125private:
126 struct Data {
127 QBasicAtomicInt ref;
128 int alloc, size;
129 // ### Qt 5.0: We need to add the missing capacity bit
130 // (like other tool classes have), to maintain the
131 // reserved memory on resize.
132 char *data;
133 char array[1];
134 };
135
136public:
137 inline QByteArray();
138 QByteArray(const char *);
139 QByteArray(const char *, int size);
140 QByteArray(int size, char c);
141 QByteArray(int size, Qt::Initialization);
142 inline QByteArray(const QByteArray &);
143 inline ~QByteArray();
144
145 QByteArray &operator=(const QByteArray &);
146 QByteArray &operator=(const char *str);
147
148 inline int size() const;
149 bool isEmpty() const;
150 void resize(int size);
151
152 QByteArray &fill(char c, int size = -1);
153
154 int capacity() const;
155 void reserve(int size);
156 void squeeze();
157
158#ifndef QT_NO_CAST_FROM_BYTEARRAY
159 operator const char *() const;
160 operator const void *() const;
161#endif
162 char *data();
163 const char *data() const;
164 inline const char *constData() const;
165 inline void detach();
166 bool isDetached() const;
167 inline bool isSharedWith(const QByteArray &other) const { return d == other.d; }
168 void clear();
169
170#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
171 const char at(int i) const;
172 const char operator[](int i) const;
173 const char operator[](uint i) const;
174#else
175 char at(int i) const;
176 char operator[](int i) const;
177 char operator[](uint i) const;
178#endif
179 QByteRef operator[](int i);
180 QByteRef operator[](uint i);
181
182 int indexOf(char c, int from = 0) const;
183 int indexOf(const char *c, int from = 0) const;
184 int indexOf(const QByteArray &a, int from = 0) const;
185 int lastIndexOf(char c, int from = -1) const;
186 int lastIndexOf(const char *c, int from = -1) const;
187 int lastIndexOf(const QByteArray &a, int from = -1) const;
188
189 QBool contains(char c) const;
190 QBool contains(const char *a) const;
191 QBool contains(const QByteArray &a) const;
192 int count(char c) const;
193 int count(const char *a) const;
194 int count(const QByteArray &a) const;
195
196 QByteArray left(int len) const;
197 QByteArray right(int len) const;
198 QByteArray mid(int index, int len = -1) const;
199
200 bool startsWith(const QByteArray &a) const;
201 bool startsWith(char c) const;
202 bool startsWith(const char *c) const;
203
204 bool endsWith(const QByteArray &a) const;
205 bool endsWith(char c) const;
206 bool endsWith(const char *c) const;
207
208 void truncate(int pos);
209 void chop(int n);
210
211 QByteArray toLower() const;
212 QByteArray toUpper() const;
213
214 QByteArray trimmed() const;
215 QByteArray simplified() const;
216 QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const;
217 QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const;
218
219#ifdef QT3_SUPPORT
220 inline QT3_SUPPORT QByteArray leftJustify(uint width, char aFill = ' ', bool aTruncate = false) const
221 { return leftJustified(int(width), aFill, aTruncate); }
222 inline QT3_SUPPORT QByteArray rightJustify(uint width, char aFill = ' ', bool aTruncate = false) const
223 { return rightJustified(int(width), aFill, aTruncate); }
224#endif
225
226 QByteArray &prepend(char c);
227 QByteArray &prepend(const char *s);
228 QByteArray &prepend(const char *s, int len);
229 QByteArray &prepend(const QByteArray &a);
230 QByteArray &append(char c);
231 QByteArray &append(const char *s);
232 QByteArray &append(const char *s, int len);
233 QByteArray &append(const QByteArray &a);
234 QByteArray &insert(int i, char c);
235 QByteArray &insert(int i, const char *s);
236 QByteArray &insert(int i, const char *s, int len);
237 QByteArray &insert(int i, const QByteArray &a);
238 QByteArray &remove(int index, int len);
239 QByteArray &replace(int index, int len, const char *s);
240 QByteArray &replace(int index, int len, const char *s, int alen);
241 QByteArray &replace(int index, int len, const QByteArray &s);
242 QByteArray &replace(char before, const char *after);
243 QByteArray &replace(char before, const QByteArray &after);
244 QByteArray &replace(const char *before, const char *after);
245 QByteArray &replace(const char *before, int bsize, const char *after, int asize);
246 QByteArray &replace(const QByteArray &before, const QByteArray &after);
247 QByteArray &replace(const QByteArray &before, const char *after);
248 QByteArray &replace(const char *before, const QByteArray &after);
249 QByteArray &replace(char before, char after);
250 QByteArray &operator+=(char c);
251 QByteArray &operator+=(const char *s);
252 QByteArray &operator+=(const QByteArray &a);
253
254 QList<QByteArray> split(char sep) const;
255
256 QByteArray repeated(int times) const;
257
258#ifndef QT_NO_CAST_TO_ASCII
259 QT_ASCII_CAST_WARN QByteArray &append(const QString &s);
260 QT_ASCII_CAST_WARN QByteArray &insert(int i, const QString &s);
261 QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const char *after);
262 QT_ASCII_CAST_WARN QByteArray &replace(char c, const QString &after);
263 QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const QByteArray &after);
264
265 QT_ASCII_CAST_WARN QByteArray &operator+=(const QString &s);
266 QT_ASCII_CAST_WARN int indexOf(const QString &s, int from = 0) const;
267 QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int from = -1) const;
268#endif
269#ifndef QT_NO_CAST_FROM_ASCII
270 inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const;
271 inline QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const;
272 inline QT_ASCII_CAST_WARN bool operator<(const QString &s2) const;
273 inline QT_ASCII_CAST_WARN bool operator>(const QString &s2) const;
274 inline QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const;
275 inline QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const;
276#endif
277
278 short toShort(bool *ok = 0, int base = 10) const;
279 ushort toUShort(bool *ok = 0, int base = 10) const;
280 int toInt(bool *ok = 0, int base = 10) const;
281 uint toUInt(bool *ok = 0, int base = 10) const;
282 long toLong(bool *ok = 0, int base = 10) const;
283 ulong toULong(bool *ok = 0, int base = 10) const;
284 qlonglong toLongLong(bool *ok = 0, int base = 10) const;
285 qulonglong toULongLong(bool *ok = 0, int base = 10) const;
286 float toFloat(bool *ok = 0) const;
287 double toDouble(bool *ok = 0) const;
288 QByteArray toBase64() const;
289 QByteArray toHex() const;
290 QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(),
291 const QByteArray &include = QByteArray(),
292 char percent = '%') const;
293
294 QByteArray &setNum(short, int base = 10);
295 QByteArray &setNum(ushort, int base = 10);
296 QByteArray &setNum(int, int base = 10);
297 QByteArray &setNum(uint, int base = 10);
298 QByteArray &setNum(qlonglong, int base = 10);
299 QByteArray &setNum(qulonglong, int base = 10);
300 QByteArray &setNum(float, char f = 'g', int prec = 6);
301 QByteArray &setNum(double, char f = 'g', int prec = 6);
302 QByteArray &setRawData(const char *a, uint n); // ### Qt 5: use an int
303
304 static QByteArray number(int, int base = 10);
305 static QByteArray number(uint, int base = 10);
306 static QByteArray number(qlonglong, int base = 10);
307 static QByteArray number(qulonglong, int base = 10);
308 static QByteArray number(double, char f = 'g', int prec = 6);
309 static QByteArray fromRawData(const char *, int size);
310 static QByteArray fromBase64(const QByteArray &base64);
311 static QByteArray fromHex(const QByteArray &hexEncoded);
312 static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%');
313
314
315 typedef char *iterator;
316 typedef const char *const_iterator;
317 typedef iterator Iterator;
318 typedef const_iterator ConstIterator;
319 iterator begin();
320 const_iterator begin() const;
321 const_iterator constBegin() const;
322 iterator end();
323 const_iterator end() const;
324 const_iterator constEnd() const;
325
326 // stl compatibility
327 typedef const char & const_reference;
328 typedef char & reference;
329 typedef char value_type;
330 void push_back(char c);
331 void push_back(const char *c);
332 void push_back(const QByteArray &a);
333 void push_front(char c);
334 void push_front(const char *c);
335 void push_front(const QByteArray &a);
336
337 inline int count() const { return d->size; }
338 int length() const { return d->size; }
339 bool isNull() const;
340
341 // compatibility
342#ifdef QT3_SUPPORT
343 QT3_SUPPORT_CONSTRUCTOR QByteArray(int size);
344 inline QT3_SUPPORT QByteArray& duplicate(const QByteArray& a) { *this = a; return *this; }
345 inline QT3_SUPPORT QByteArray& duplicate(const char *a, uint n)
346 { *this = QByteArray(a, n); return *this; }
347 inline QT3_SUPPORT void resetRawData(const char *, uint) { clear(); }
348 inline QT3_SUPPORT QByteArray lower() const { return toLower(); }
349 inline QT3_SUPPORT QByteArray upper() const { return toUpper(); }
350 inline QT3_SUPPORT QByteArray stripWhiteSpace() const { return trimmed(); }
351 inline QT3_SUPPORT QByteArray simplifyWhiteSpace() const { return simplified(); }
352 inline QT3_SUPPORT int find(char c, int from = 0) const { return indexOf(c, from); }
353 inline QT3_SUPPORT int find(const char *c, int from = 0) const { return indexOf(c, from); }
354 inline QT3_SUPPORT int find(const QByteArray &ba, int from = 0) const { return indexOf(ba, from); }
355 inline QT3_SUPPORT int findRev(char c, int from = -1) const { return lastIndexOf(c, from); }
356 inline QT3_SUPPORT int findRev(const char *c, int from = -1) const { return lastIndexOf(c, from); }
357 inline QT3_SUPPORT int findRev(const QByteArray &ba, int from = -1) const { return lastIndexOf(ba, from); }
358#ifndef QT_NO_CAST_TO_ASCII
359 QT3_SUPPORT int find(const QString &s, int from = 0) const;
360 QT3_SUPPORT int findRev(const QString &s, int from = -1) const;
361#endif
362#endif
363
364private:
365 operator QNoImplicitBoolCast() const;
366 static Data shared_null;
367 static Data shared_empty;
368 Data *d;
369 QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {}
370 void realloc(int alloc);
371 void expand(int i);
372 QByteArray nulTerminated() const;
373
374 friend class QByteRef;
375 friend class QString;
376 friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
377public:
378 typedef Data * DataPtr;
379 inline DataPtr &data_ptr() { return d; }
380};
381
382inline QByteArray::QByteArray(): d(&shared_null) { d->ref.ref(); }
383inline QByteArray::~QByteArray() { if (!d->ref.deref()) qFree(d); }
384inline int QByteArray::size() const
385{ return d->size; }
386
387#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
388inline const char QByteArray::at(int i) const
389{ Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
390inline const char QByteArray::operator[](int i) const
391{ Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
392inline const char QByteArray::operator[](uint i) const
393{ Q_ASSERT(i < uint(size())); return d->data[i]; }
394#else
395inline char QByteArray::at(int i) const
396{ Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
397inline char QByteArray::operator[](int i) const
398{ Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
399inline char QByteArray::operator[](uint i) const
400{ Q_ASSERT(i < uint(size())); return d->data[i]; }
401#endif
402
403inline bool QByteArray::isEmpty() const
404{ return d->size == 0; }
405#ifndef QT_NO_CAST_FROM_BYTEARRAY
406inline QByteArray::operator const char *() const
407{ return d->data; }
408inline QByteArray::operator const void *() const
409{ return d->data; }
410#endif
411inline char *QByteArray::data()
412{ detach(); return d->data; }
413inline const char *QByteArray::data() const
414{ return d->data; }
415inline const char *QByteArray::constData() const
416{ return d->data; }
417inline void QByteArray::detach()
418{ if (d->ref != 1 || d->data != d->array) realloc(d->size); }
419inline bool QByteArray::isDetached() const
420{ return d->ref == 1; }
421inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
422{ d->ref.ref(); }
423#ifdef QT3_SUPPORT
424inline QByteArray::QByteArray(int aSize) : d(&shared_null)
425{ d->ref.ref(); if (aSize > 0) fill('\0', aSize); }
426#endif
427
428inline int QByteArray::capacity() const
429{ return d->alloc; }
430
431inline void QByteArray::reserve(int asize)
432{ if (d->ref != 1 || asize > d->alloc) realloc(asize); }
433
434inline void QByteArray::squeeze()
435{ if (d->size < d->alloc) realloc(d->size); }
436
437class Q_CORE_EXPORT QByteRef {
438 QByteArray &a;
439 int i;
440 inline QByteRef(QByteArray &array, int idx)
441 : a(array),i(idx) {}
442 friend class QByteArray;
443public:
444#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
445 inline operator const char() const
446 { return i < a.d->size ? a.d->data[i] : char(0); }
447#else
448 inline operator char() const
449 { return i < a.d->size ? a.d->data[i] : char(0); }
450#endif
451 inline QByteRef &operator=(char c)
452 { if (i >= a.d->size) a.expand(i); else a.detach();
453 a.d->data[i] = c; return *this; }
454 inline QByteRef &operator=(const QByteRef &c)
455 { if (i >= a.d->size) a.expand(i); else a.detach();
456 a.d->data[i] = c.a.d->data[c.i]; return *this; }
457 inline bool operator==(char c) const
458 { return a.d->data[i] == c; }
459 inline bool operator!=(char c) const
460 { return a.d->data[i] != c; }
461 inline bool operator>(char c) const
462 { return a.d->data[i] > c; }
463 inline bool operator>=(char c) const
464 { return a.d->data[i] >= c; }
465 inline bool operator<(char c) const
466 { return a.d->data[i] < c; }
467 inline bool operator<=(char c) const
468 { return a.d->data[i] <= c; }
469};
470
471inline QByteRef QByteArray::operator[](int i)
472{ Q_ASSERT(i >= 0); return QByteRef(*this, i); }
473inline QByteRef QByteArray::operator[](uint i)
474{ return QByteRef(*this, i); }
475inline QByteArray::iterator QByteArray::begin()
476{ detach(); return d->data; }
477inline QByteArray::const_iterator QByteArray::begin() const
478{ return d->data; }
479inline QByteArray::const_iterator QByteArray::constBegin() const
480{ return d->data; }
481inline QByteArray::iterator QByteArray::end()
482{ detach(); return d->data + d->size; }
483inline QByteArray::const_iterator QByteArray::end() const
484{ return d->data + d->size; }
485inline QByteArray::const_iterator QByteArray::constEnd() const
486{ return d->data + d->size; }
487inline QByteArray &QByteArray::operator+=(char c)
488{ return append(c); }
489inline QByteArray &QByteArray::operator+=(const char *s)
490{ return append(s); }
491inline QByteArray &QByteArray::operator+=(const QByteArray &a)
492{ return append(a); }
493inline void QByteArray::push_back(char c)
494{ append(c); }
495inline void QByteArray::push_back(const char *c)
496{ append(c); }
497inline void QByteArray::push_back(const QByteArray &a)
498{ append(a); }
499inline void QByteArray::push_front(char c)
500{ prepend(c); }
501inline void QByteArray::push_front(const char *c)
502{ prepend(c); }
503inline void QByteArray::push_front(const QByteArray &a)
504{ prepend(a); }
505inline QBool QByteArray::contains(const QByteArray &a) const
506{ return QBool(indexOf(a) != -1); }
507inline QBool QByteArray::contains(char c) const
508{ return QBool(indexOf(c) != -1); }
509inline bool operator==(const QByteArray &a1, const QByteArray &a2)
510{ return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); }
511inline bool operator==(const QByteArray &a1, const char *a2)
512{ return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); }
513inline bool operator==(const char *a1, const QByteArray &a2)
514{ return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); }
515inline bool operator!=(const QByteArray &a1, const QByteArray &a2)
516{ return !(a1==a2); }
517inline bool operator!=(const QByteArray &a1, const char *a2)
518{ return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); }
519inline bool operator!=(const char *a1, const QByteArray &a2)
520{ return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); }
521inline bool operator<(const QByteArray &a1, const QByteArray &a2)
522{ return qstrcmp(a1, a2) < 0; }
523 inline bool operator<(const QByteArray &a1, const char *a2)
524{ return qstrcmp(a1, a2) < 0; }
525inline bool operator<(const char *a1, const QByteArray &a2)
526{ return qstrcmp(a1, a2) < 0; }
527inline bool operator<=(const QByteArray &a1, const QByteArray &a2)
528{ return qstrcmp(a1, a2) <= 0; }
529inline bool operator<=(const QByteArray &a1, const char *a2)
530{ return qstrcmp(a1, a2) <= 0; }
531inline bool operator<=(const char *a1, const QByteArray &a2)
532{ return qstrcmp(a1, a2) <= 0; }
533inline bool operator>(const QByteArray &a1, const QByteArray &a2)
534{ return qstrcmp(a1, a2) > 0; }
535inline bool operator>(const QByteArray &a1, const char *a2)
536{ return qstrcmp(a1, a2) > 0; }
537inline bool operator>(const char *a1, const QByteArray &a2)
538{ return qstrcmp(a1, a2) > 0; }
539inline bool operator>=(const QByteArray &a1, const QByteArray &a2)
540{ return qstrcmp(a1, a2) >= 0; }
541inline bool operator>=(const QByteArray &a1, const char *a2)
542{ return qstrcmp(a1, a2) >= 0; }
543inline bool operator>=(const char *a1, const QByteArray &a2)
544{ return qstrcmp(a1, a2) >= 0; }
545inline const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
546{ return QByteArray(a1) += a2; }
547inline const QByteArray operator+(const QByteArray &a1, const char *a2)
548{ return QByteArray(a1) += a2; }
549inline const QByteArray operator+(const QByteArray &a1, char a2)
550{ return QByteArray(a1) += a2; }
551inline const QByteArray operator+(const char *a1, const QByteArray &a2)
552{ return QByteArray(a1) += a2; }
553inline const QByteArray operator+(char a1, const QByteArray &a2)
554{ return QByteArray(&a1, 1) += a2; }
555inline QBool QByteArray::contains(const char *c) const
556{ return QBool(indexOf(c) != -1); }
557inline QByteArray &QByteArray::replace(char before, const char *c)
558{ return replace(&before, 1, c, qstrlen(c)); }
559inline QByteArray &QByteArray::replace(const QByteArray &before, const char *c)
560{ return replace(before.constData(), before.size(), c, qstrlen(c)); }
561inline QByteArray &QByteArray::replace(const char *before, const char *after)
562{ return replace(before, qstrlen(before), after, qstrlen(after)); }
563
564inline QByteArray &QByteArray::setNum(short n, int base)
565{ return setNum(qlonglong(n), base); }
566inline QByteArray &QByteArray::setNum(ushort n, int base)