~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/tools/qbytearray.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

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