1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 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 | #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 | |
55 | #if defined(Q_CC_GNU) && (__GNUC__ == 4 && __GNUC_MINOR__ == 0) |
56 | //There is a bug in GCC 4.0 that tries to instantiate template of annonymous enum |
57 | # ifdef QT_USE_FAST_OPERATOR_PLUS |
58 | # undef QT_USE_FAST_OPERATOR_PLUS |
59 | # endif |
60 | # ifdef QT_USE_QSTRINGBUILDER |
61 | # undef QT_USE_QSTRINGBUILDER |
62 | # endif |
63 | |
64 | #endif |
65 | |
66 | |
67 | QT_BEGIN_HEADER |
68 | |
69 | QT_BEGIN_NAMESPACE |
70 | |
71 | QT_MODULE(Core) |
72 | |
73 | /***************************************************************************** |
74 | Safe and portable C string functions; extensions to standard string.h |
75 | *****************************************************************************/ |
76 | |
77 | Q_CORE_EXPORT char *qstrdup(const char *); |
78 | |
79 | inline uint qstrlen(const char *str) |
80 | { return str ? uint(strlen(str)) : 0; } |
81 | |
82 | inline uint qstrnlen(const char *str, uint maxlen) |
83 | { |
84 | uint length = 0; |
85 | if (str) { |
86 | while (length < maxlen && *str++) |
87 | length++; |
88 | } |
89 | return length; |
90 | } |
91 | |
92 | Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src); |
93 | Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, uint len); |
94 | |
95 | Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2); |
96 | Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const QByteArray &str2); |
97 | Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const char *str2); |
98 | static inline int qstrcmp(const char *str1, const QByteArray &str2) |
99 | { return -qstrcmp(str2, str1); } |
100 | |
101 | inline int qstrncmp(const char *str1, const char *str2, uint len) |
102 | { |
103 | return (str1 && str2) ? strncmp(str1, str2, len) |
104 | : (str1 ? 1 : (str2 ? -1 : 0)); |
105 | } |
106 | Q_CORE_EXPORT int qstricmp(const char *, const char *); |
107 | Q_CORE_EXPORT int qstrnicmp(const char *, const char *, uint len); |
108 | |
109 | // implemented in qvsnprintf.cpp |
110 | Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap); |
111 | Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...); |
112 | |
113 | #ifdef QT3_SUPPORT |
114 | inline QT3_SUPPORT void *qmemmove(void *dst, const void *src, uint len) |
115 | { return memmove(dst, src, len); } |
116 | inline QT3_SUPPORT uint cstrlen(const char *str) |
117 | { return uint(strlen(str)); } |
118 | inline QT3_SUPPORT char *cstrcpy(char *dst, const char *src) |
119 | { return qstrcpy(dst,src); } |
120 | inline QT3_SUPPORT int cstrcmp(const char *str1, const char *str2) |
121 | { return strcmp(str1,str2); } |
122 | inline QT3_SUPPORT int cstrncmp(const char *str1, const char *str2, uint len) |
123 | { return strncmp(str1,str2,len); } |
124 | #endif |
125 | |
126 | // qChecksum: Internet checksum |
127 | |
128 | Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len); |
129 | |
130 | class QByteRef; |
131 | class QString; |
132 | class QDataStream; |
133 | template <typename T> class QList; |
134 | |
135 | class Q_CORE_EXPORT QByteArray |
136 | { |
137 | private: |
138 | struct Data { |
139 | QBasicAtomicInt ref; |
140 | int alloc, size; |
141 | // ### Qt 5.0: We need to add the missing capacity bit |
142 | // (like other tool classes have), to maintain the |
143 | // reserved memory on resize. |
144 | char *data; |
145 | char array[1]; |
146 | }; |
147 | |
148 | public: |
149 | inline QByteArray(); |
150 | QByteArray(const char *); |
151 | QByteArray(const char *, int size); |
152 | QByteArray(int size, char c); |
153 | QByteArray(int size, Qt::Initialization); |
154 | inline QByteArray(const QByteArray &); |
155 | inline ~QByteArray(); |
156 | |
157 | QByteArray &operator=(const QByteArray &); |
158 | QByteArray &operator=(const char *str); |
159 | #ifdef Q_COMPILER_RVALUE_REFS |
160 | inline QByteArray &operator=(QByteArray &&other) |
161 | { qSwap(d, other.d); return *this; } |
162 | #endif |
163 | |
164 | inline void swap(QByteArray &other) { qSwap(d, other.d); } |
165 | |
166 | inline int size() const; |
167 | bool isEmpty() const; |
168 | void resize(int size); |
169 | |
170 | QByteArray &fill(char c, int size = -1); |
171 | |
172 | int capacity() const; |
173 | void reserve(int size); |
174 | void squeeze(); |
175 | |
176 | #ifndef QT_NO_CAST_FROM_BYTEARRAY |
177 | operator const char *() const; |
178 | operator const void *() const; |
179 | #endif |
180 | char *data(); |
181 | const char *data() const; |
182 | inline const char *constData() const; |
183 | inline void detach(); |
184 | bool isDetached() const; |
185 | inline bool isSharedWith(const QByteArray &other) const { return d == other.d; } |
186 | void clear(); |
187 | |
188 | #ifdef Q_COMPILER_MANGLES_RETURN_TYPE |
189 | const char at(int i) const; |
190 | const char operator[](int i) const; |
191 | const char operator[](uint i) const; |
192 | #else |
193 | char at(int i) const; |
194 | char operator[](int i) const; |
195 | char operator[](uint i) const; |
196 | #endif |
197 | QByteRef operator[](int i); |
198 | QByteRef operator[](uint i); |
199 | |
200 | int indexOf(char c, int from = 0) const; |
201 | int indexOf(const char *c, int from = 0) const; |
202 | int indexOf(const QByteArray &a, int from = 0) const; |
203 | int lastIndexOf(char c, int from = -1) const; |
204 | int lastIndexOf(const char *c, int from = -1) const; |
205 | int lastIndexOf(const QByteArray &a, int from = -1) const; |
206 | |
207 | QBool contains(char c) const; |
208 | QBool contains(const char *a) const; |
209 | QBool contains(const QByteArray &a) const; |
210 | int count(char c) const; |
211 | int count(const char *a) const; |
212 | int count(const QByteArray &a) const; |
213 | |
214 | QByteArray left(int len) const; |
215 | QByteArray right(int len) const; |
216 | QByteArray mid(int index, int len = -1) const; |
217 | |
218 | bool startsWith(const QByteArray &a) const; |
219 | bool startsWith(char c) const; |
220 | bool startsWith(const char *c) const; |
221 | |
222 | bool endsWith(const QByteArray &a) const; |
223 | bool endsWith(char c) const; |
224 | bool endsWith(const char *c) const; |
225 | |
226 | void truncate(int pos); |
227 | void chop(int n); |
228 | |
229 | QByteArray toLower() const; |
230 | QByteArray toUpper() const; |
231 | |
232 | QByteArray trimmed() const; |
233 | QByteArray simplified() const; |
234 | QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const; |
235 | QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const; |
236 | |
237 | #ifdef QT3_SUPPORT |
238 | inline QT3_SUPPORT QByteArray leftJustify(uint width, char aFill = ' ', bool aTruncate = false) const |
239 | { return leftJustified(int(width), aFill, aTruncate); } |
240 | inline QT3_SUPPORT QByteArray rightJustify(uint width, char aFill = ' ', bool aTruncate = false) const |
241 | { return rightJustified(int(width), aFill, aTruncate); } |
242 | #endif |
243 | |
244 | QByteArray &prepend(char c); |
245 | QByteArray &prepend(const char *s); |
246 | QByteArray &prepend(const char *s, int len); |
247 | QByteArray &prepend(const QByteArray &a); |
248 | QByteArray &append(char c); |
249 | QByteArray &append(const char *s); |
250 | QByteArray &append(const char *s, int len); |
251 | QByteArray &append(const QByteArray &a); |
252 | QByteArray &insert(int i, char c); |
253 | QByteArray &insert(int i, const char *s); |
254 | QByteArray &insert(int i, const char *s, int len); |
255 | QByteArray &insert(int i, const QByteArray &a); |
256 | QByteArray &remove(int index, int len); |
257 | QByteArray &replace(int index, int len, const char *s); |
258 | QByteArray &replace(int index, int len, const char *s, int alen); |
259 | QByteArray &replace(int index, int len, const QByteArray &s); |
260 | QByteArray &replace(char before, const char *after); |
261 | QByteArray &replace(char before, const QByteArray &after); |
262 | QByteArray &replace(const char *before, const char *after); |
263 | QByteArray &replace(const char *before, int bsize, const char *after, int asize); |
264 | QByteArray &replace(const QByteArray &before, const QByteArray &after); |
265 | QByteArray &replace(const QByteArray &before, const char *after); |
266 | QByteArray &replace(const char *before, const QByteArray &after); |
267 | QByteArray &replace(char before, char after); |
268 | QByteArray &operator+=(char c); |
269 | QByteArray &operator+=(const char *s); |
270 | QByteArray &operator+=(const QByteArray &a); |
271 | |
272 | QList<QByteArray> split(char sep) const; |
273 | |
274 | QByteArray repeated(int times) const; |
275 | |
276 | #ifndef QT_NO_CAST_TO_ASCII |
277 | QT_ASCII_CAST_WARN QByteArray &append(const QString &s); |
278 | QT_ASCII_CAST_WARN QByteArray &insert(int i, const QString &s); |
279 | QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const char *after); |
280 | QT_ASCII_CAST_WARN QByteArray &replace(char c, const QString &after); |
281 | QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const QByteArray &after); |
282 | |
283 | QT_ASCII_CAST_WARN QByteArray &operator+=(const QString &s); |
284 | QT_ASCII_CAST_WARN int indexOf(const QString &s, int from = 0) const; |
285 | QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int from = -1) const; |
286 | #endif |
287 | #ifndef QT_NO_CAST_FROM_ASCII |
288 | inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const; |
289 | inline QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const; |
290 | inline QT_ASCII_CAST_WARN bool operator<(const QString &s2) const; |
291 | inline QT_ASCII_CAST_WARN bool operator>(const QString &s2) const; |
292 | inline QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const; |
293 | inline QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const; |
294 | #endif |
295 | |
296 | short toShort(bool *ok = 0, int base = 10) const; |
297 | ushort toUShort(bool *ok = 0, int base = 10) const; |
298 | int toInt(bool *ok = 0, int base = 10) const; |
299 | uint toUInt(bool *ok = 0, int base = 10) const; |
300 | long toLong(bool *ok = 0, int base = 10) const; |
301 | ulong toULong(bool *ok = 0, int base = 10) const; |
302 | qlonglong toLongLong(bool *ok = 0, int base = 10) const; |
303 | qulonglong toULongLong(bool *ok = 0, int base = 10) const; |
304 | float toFloat(bool *ok = 0) const; |
305 | double toDouble(bool *ok = 0) const; |
306 | QByteArray toBase64() const; |
307 | QByteArray toHex() const; |
308 | QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(), |
309 | const QByteArray &include = QByteArray(), |
310 | char percent = '%') const; |
311 | |
312 | QByteArray &setNum(short, int base = 10); |
313 | QByteArray &setNum(ushort, int base = 10); |
314 | QByteArray &setNum(int, int base = 10); |
315 | QByteArray &setNum(uint, int base = 10); |
316 | QByteArray &setNum(qlonglong, int base = 10); |
317 | QByteArray &setNum(qulonglong, int base = 10); |
318 | QByteArray &setNum(float, char f = 'g', int prec = 6); |
319 | QByteArray &setNum(double, char f = 'g', int prec = 6); |
320 | QByteArray &setRawData(const char *a, uint n); // ### Qt 5: use an int |
321 | |
322 | static QByteArray number(int, int base = 10); |
323 | static QByteArray number(uint, int base = 10); |
324 | static QByteArray number(qlonglong, int base = 10); |
325 | static QByteArray number(qulonglong, int base = 10); |
326 | static QByteArray number(double, char f = 'g', int prec = 6); |
327 | static QByteArray fromRawData(const char *, int size); |
328 | static QByteArray fromBase64(const QByteArray &base64); |
329 | static QByteArray fromHex(const QByteArray &hexEncoded); |
330 | static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); |
331 | |
332 | |
333 | typedef char *iterator; |
334 | typedef const char *const_iterator; |
335 | typedef iterator Iterator; |
336 | typedef const_iterator ConstIterator; |
337 | iterator begin(); |
338 | const_iterator begin() const; |
339 | const_iterator constBegin() const; |
340 | iterator end(); |
341 | const_iterator end() const; |
342 | const_iterator constEnd() const; |
343 | |
344 | // stl compatibility |
345 | typedef const char & const_reference; |
346 | typedef char & reference; |
347 | typedef char value_type; |
348 | void push_back(char c); |
349 | void push_back(const char *c); |
350 | void push_back(const QByteArray &a); |
351 | void push_front(char c); |
352 | void push_front(const char *c); |
353 | void push_front(const QByteArray &a); |
354 | |
355 | inline int count() const { return d->size; } |
356 | int length() const { return d->size; } |
357 | bool isNull() const; |
358 | |
359 | // compatibility |
360 | #ifdef QT3_SUPPORT |
361 | QT3_SUPPORT_CONSTRUCTOR QByteArray(int size); |
362 | inline QT3_SUPPORT QByteArray& duplicate(const QByteArray& a) { *this = a; return *this; } |
363 | inline QT3_SUPPORT QByteArray& duplicate(const char *a, uint n) |
364 | { *this = QByteArray(a, n); return *this; } |
365 | inline QT3_SUPPORT void resetRawData(const char *, uint) { clear(); } |
366 | inline QT3_SUPPORT QByteArray lower() const { return toLower(); } |
367 | inline QT3_SUPPORT QByteArray upper() const { return toUpper(); } |
368 | inline QT3_SUPPORT QByteArray stripWhiteSpace() const { return trimmed(); } |
369 | inline QT3_SUPPORT QByteArray simplifyWhiteSpace() const { return simplified(); } |
370 | inline QT3_SUPPORT int find(char c, int from = 0) const { return indexOf(c, from); } |
371 | inline QT3_SUPPORT int find(const char *c, int from = 0) const { return indexOf(c, from); } |
372 | inline QT3_SUPPORT int find(const QByteArray &ba, int from = 0) const { return indexOf(ba, from); } |
373 | inline QT3_SUPPORT int findRev(char c, int from = -1) const { return lastIndexOf(c, from); } |
374 | inline QT3_SUPPORT int findRev(const char *c, int from = -1) const { return lastIndexOf(c, from); } |
375 | inline QT3_SUPPORT int findRev(const QByteArray &ba, int from = -1) const { return lastIndexOf(ba, from); } |
376 | #ifndef QT_NO_CAST_TO_ASCII |
377 | QT3_SUPPORT int find(const QString &s, int from = 0) const; |
378 | QT3_SUPPORT int findRev(const QString &s, int from = -1) const; |
379 | #endif |
380 | #endif |
381 | |
382 | private: |
383 | operator QNoImplicitBoolCast() const; |
384 | static Data shared_null; |
385 | static Data shared_empty; |
386 | Data *d; |
387 | QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {} |
388 | void realloc(int alloc); |
389 | void expand(int i); |
390 | QByteArray nulTerminated() const; |
391 | |
392 | friend class QByteRef; |
393 | friend class QString; |
394 | friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes); |
395 | public: |
396 | typedef Data * DataPtr; |
397 | inline DataPtr &data_ptr() { return d; } |
398 | }; |
399 | |
400 | inline QByteArray::QByteArray(): d(&shared_null) { d->ref.ref(); } |
401 | inline QByteArray::~QByteArray() { if (!d->ref.deref()) qFree(d); } |
402 | inline int QByteArray::size() const |
403 | { return d->size; } |
404 | |
405 | #ifdef Q_COMPILER_MANGLES_RETURN_TYPE |
406 | inline const char QByteArray::at(int i) const |
407 | { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; } |
408 | inline const char QByteArray::operator[](int i) const |
409 | { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; } |
410 | inline const char QByteArray::operator[](uint i) const |
411 | { Q_ASSERT(i < uint(size())); return d->data[i]; } |
412 | #else |
413 | inline char QByteArray::at(int i) const |
414 | { Q_ASSERT(uint(i) < uint(size())); return d->data[i]; } |
415 | inline char QByteArray::operator[](int i) const |
416 | { Q_ASSERT(uint(i) < uint(size())); return d->data[i]; } |
417 | inline char QByteArray::operator[](uint i) const |
418 | { Q_ASSERT(i < uint(size())); return d->data[i]; } |
419 | #endif |
420 | |
421 | inline bool QByteArray::isEmpty() const |
422 | { return d->size == 0; } |
423 | #ifndef QT_NO_CAST_FROM_BYTEARRAY |
424 | inline QByteArray::operator const char *() const |
425 | { return d->data; } |
426 | inline QByteArray::operator const void *() const |
427 | { return d->data; } |
428 | #endif |
429 | inline char *QByteArray::data() |
430 | { detach(); return d->data; } |
431 | inline const char *QByteArray::data() const |
432 | { return d->data; } |
433 | inline const char *QByteArray::constData() const |
434 | { return d->data; } |
435 | inline void QByteArray::detach() |
436 | { if (d->ref != 1 || d->data != d->array) realloc(d->size); } |
437 | inline bool QByteArray::isDetached() const |
438 | { return d->ref == 1; } |
439 | inline QByteArray::QByteArray(const QByteArray &a) : d(a.d) |
440 | { d->ref.ref(); } |
441 | #ifdef QT3_SUPPORT |
442 | inline QByteArray::QByteArray(int aSize) : d(&shared_null) |
443 | { d->ref.ref(); if (aSize > 0) fill('\0', aSize); } |
444 | #endif |
445 | |
446 | inline int QByteArray::capacity() const |
447 | { return d->alloc; } |
448 | |
449 | inline void QByteArray::reserve(int asize) |
450 | { if (d->ref != 1 || asize > d->alloc) realloc(asize); } |
451 | |
452 | inline void QByteArray::squeeze() |
453 | { if (d->size < d->alloc) realloc(d->size); } |
454 | |
455 | class Q_CORE_EXPORT QByteRef { |
456 | QByteArray &a; |
457 | int i; |
458 | inline QByteRef(QByteArray &array, int idx) |
459 | : a(array),i(idx) {} |
460 | friend class QByteArray; |
461 | public: |
462 | #ifdef Q_COMPILER_MANGLES_RETURN_TYPE |
463 | inline operator const char() const |
464 | { return i < a.d->size ? a.d->data[i] : char(0); } |
465 | #else |
466 | inline operator char() const |
467 | { return i < a.d->size ? a.d->data[i] : char(0); } |
468 | #endif |
469 | inline QByteRef &operator=(char c) |
470 | { if (i >= a.d->size) a.expand(i); else a.detach(); |
471 | a.d->data[i] = c; return *this; } |
472 | inline QByteRef &operator=(const QByteRef &c) |
473 | { if (i >= a.d->size) a.expand(i); else a.detach(); |
474 | a.d->data[i] = c.a.d->data[c.i]; return *this; } |
475 | inline bool operator==(char c) const |
476 | { return a.d->data[i] == c; } |
477 | inline bool operator!=(char c) const |
478 | { return a.d->data[i] != c; } |
479 | inline bool operator>(char c) const |
480 | { return a.d->data[i] > c; } |
481 | inline bool operator>=(char c) const |
482 | { return a.d->data[i] >= c; } |
483 | inline bool operator<(char c) const |
484 | { return a.d->data[i] < c; } |
485 | inline bool operator<=(char c) const |
486 | { return a.d->data[i] <= c; } |
487 | }; |
488 | |
489 | inline QByteRef QByteArray::operator[](int i) |
490 | { Q_ASSERT(i >= 0); return QByteRef(*this, i); } |
491 | inline QByteRef QByteArray::operator[](uint i) |
492 | { return QByteRef(*this, i); } |
493 | inline QByteArray::iterator QByteArray::begin() |
494 | { detach(); return d->data; } |
495 | inline QByteArray::const_iterator QByteArray::begin() const |
496 | { return d->data; } |
497 | inline QByteArray::const_iterator QByteArray::constBegin() const |
498 | { return d->data; } |
499 | inline QByteArray::iterator QByteArray::end() |
500 | { detach(); return d->data + d->size; } |
501 | inline QByteArray::const_iterator QByteArray::end() const |
502 | { return d->data + d->size; } |
503 | inline QByteArray::const_iterator QByteArray::constEnd() const |
504 | { return d->data + d->size; } |
505 | inline QByteArray &QByteArray::operator+=(char c) |
506 | { return append(c); } |
507 | inline QByteArray &QByteArray::operator+=(const char *s) |
508 | { return append(s); } |
509 | inline QByteArray &QByteArray::operator+=(const QByteArray &a) |
510 | { return append(a); } |
511 | inline void QByteArray::push_back(char c) |
512 | { append(c); } |
513 | inline void QByteArray::push_back(const char *c) |
514 | { append(c); } |
515 | inline void QByteArray::push_back(const QByteArray &a) |
516 | { append(a); } |
517 | inline void QByteArray::push_front(char c) |
518 | { prepend(c); } |
519 | inline void QByteArray::push_front(const char *c) |
520 | { prepend(c); } |
521 | inline void QByteArray::push_front(const QByteArray &a) |
522 | { prepend(a); } |
523 | inline QBool QByteArray::contains(const QByteArray &a) const |
524 | { return QBool(indexOf(a) != -1); } |
525 | inline QBool QByteArray::contains(char c) const |
526 | { return QBool(indexOf(c) != -1); } |
527 | inline bool operator==(const QByteArray &a1, const QByteArray &a2) |
528 | { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); } |
529 | inline bool operator==(const QByteArray &a1, const char *a2) |
530 | { return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); } |
531 | inline bool operator==(const char *a1, const QByteArray &a2) |
532 | { return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); } |
533 | inline bool operator!=(const QByteArray &a1, const QByteArray &a2) |
534 | { return !(a1==a2); } |
535 | inline bool operator!=(const QByteArray &a1, const char *a2) |
536 | { return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); } |
537 | inline bool operator!=(const char *a1, const QByteArray &a2) |
538 | { return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); } |
539 | inline bool operator<(const QByteArray &a1, const QByteArray &a2) |
540 | { return qstrcmp(a1, a2) < 0; } |
541 | inline bool operator<(const QByteArray &a1, const char *a2) |
542 | { return qstrcmp(a1, a2) < 0; } |
543 | inline bool operator<(const char *a1, const QByteArray &a2) |
544 | { return qstrcmp(a1, a2) < 0; } |
545 | inline bool operator<=(const QByteArray &a1, const QByteArray &a2) |
546 | { return qstrcmp(a1, a2) <= 0; } |
547 | inline bool operator<=(const QByteArray &a1, const char *a2) |
548 | { return qstrcmp(a1, a2) <= 0; } |
549 | inline bool operator<=(const char *a1, const QByteArray &a2) |
550 | { return qstrcmp(a1, a2) <= 0; } |
551 | inline bool operator>(const QByteArray &a1, const QByteArray &a2) |
552 | { return qstrcmp(a1, a2) > 0; } |
553 | inline bool operator>(const QByteArray &a1, const char *a2) |
554 | { return qstrcmp(a1, a2) > 0; } |
555 | inline bool operator>(const char *a1, const QByteArray &a2) |
556 | { return qstrcmp(a1, a2) > 0; } |
557 | inline bool operator>=(const QByteArray &a1, const QByteArray &a2) |
558 | { return qstrcmp(a1, a2) >= 0; } |
559 | inline bool operator>=(const QByteArray &a1, const char *a2) |
560 | { return qstrcmp(a1, a2) >= 0; } |
561 | inline bool operator>=(const char *a1, const QByteArray &a2) |
562 | { return qstrcmp(a1, a2) >= 0; } |
563 | #if !defined(QT_USE_QSTRINGBUILDER) |
564 | inline const QByteArray operator+(const QByteArray &a1, const QByteArray &a2) |
565 | { return QByteArray(a1) += a2; } |
566 | inline const QByteArray operator+(const QByteArray &a1, const char *a2) |
567 | { return QByteArray(a1) += a2; } |
568 | inline const QByteArray operator+(const QByteArray &a1, char a2) |
569 | { return QByteArray(a1) += a2; } |
570 | inline const QByteArray operator+(const char *a1, const QByteArray &a2) |
571 | { return QByteArray(a1) += a2; } |
572 | inline const QByteArray operator+(char a1, const QByteArray &a2) |
573 | { return QByteArray(&a1, 1) += a2; } |
574 | #endif // QT_USE_QSTRINGBUILDER |
575 | inline QBool QByteArray::contains(const char *c) const |
576 | { return QBool(indexOf(c) != -1); } |
577 | inline QByteArray &QByteArray::replace(char before, const char *c) |
578 | { return replace(&before, 1, c, qstrlen(c)); } |
579 | inline QByteArray &QByteArray::replace(const QByteArray &before, const char *c) |
580 | { return replace(before.constData(), before.size(), c, qstrlen(c)); } |
581 | inline QByteArray &QByteArray::replace(const char *before, const char *after) |
582 | { return replace(before, qstrlen(before), after, qstrlen(after)); } |
583 | |
584 | inline QByteArray &QByteArray::setNum(short n, int base) |
585 | { return setNum(qlonglong(n), base); } |
586 | inline QByteArray &QByteArray::setNum(ushort n, int base) |
587 | { return setNum(qulonglong(n), base); } |
588 | inline QByteArray &QByteArray::setNum(int n, int base) |
589 | { return setNum(qlonglong(n), base); } |
590 | inline QByteArray &QByteArray::setNum(uint n, int base) |
591 | { return setNum(qulonglong(n), base); } |
592 | inline QByteArray &QByteArray::setNum(float n, char f, int prec) |
593 | { return setNum(double(n),f,prec); } |
594 | |
595 | |
596 | #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) |
597 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &); |
598 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QByteArray &); |
599 | #endif |
600 | |
601 | #ifndef QT_NO_COMPRESS |
602 | Q_CORE_EXPORT QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel = -1); |
603 | Q_CORE_EXPORT QByteArray qUncompress(const uchar* data, int nbytes); |
604 | inline QByteArray qCompress(const QByteArray& data, int compressionLevel = -1) |
605 | { return qCompress(reinterpret_cast<const uchar *>(data.constData()), data.size(), compressionLevel); } |
606 | inline QByteArray qUncompress(const QByteArray& data) |
607 | { return qUncompress(reinterpret_cast<const uchar*>(data.constData()), data.size()); } |
608 | #endif |
609 | |
610 | Q_DECLARE_TYPEINFO(QByteArray, Q_MOVABLE_TYPE); |
611 | Q_DECLARE_SHARED(QByteArray) |
612 | |
613 | QT_END_NAMESPACE |
614 | |
615 | QT_END_HEADER |
616 | |
617 | #ifdef QT_USE_QSTRINGBUILDER |
618 | #include <QtCore/qstring.h> |
619 | #endif |
620 | |
621 | #endif // QBYTEARRAY_H |
622 | |