- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qbytearray.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QBYTEARRAY_H
    00043 #define QBYTEARRAY_H
    00044
    00045 #include <QtCore/qatomic.h>
    00046 #include <QtCore/qnamespace.h>
    00047
    00048 #include <string.h>
    00049 #include <stdarg.h>
    00050
    00051 #ifdef truncate
    00052 #error qbytearray.h must be included before any header file that defines truncate
    00053 #endif
    00054
    00055 QT_BEGIN_HEADER
    00056
    00057 QT_BEGIN_NAMESPACE
    00058
    00059 QT_MODULE(Core)
    00060
    00061 /*****************************************************************************
    00062   Safe and portable C string functions; extensions to standard string.h
    00063  *****************************************************************************/
    00064
    00065 Q_CORE_EXPORT char *qstrdup(const char *);
    00066
    00067 inline uint qstrlen(const char *str)
    00068 { return str ? uint(strlen(str)) : 0; }
    00069
    00070 inline uint qstrnlen(const char *str, uint maxlen)
    00071 {
    00072     uint length = 0;
    00073     if (str) {
    00074         while (length < maxlen && *str++)
    00075             length++;
    00076     }
    00077     return length;
    00078 }
    00079
    00080 Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src);
    00081 Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, uint len);
    00082
    00083 Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2);
    00084 Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const QByteArray &str2);
    00085 Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const char *str2);
    00086 static inline int qstrcmp(const char *str1, const QByteArray &str2)
    00087 { return -qstrcmp(str2, str1); }
    00088
    00089 inline int qstrncmp(const char *str1, const char *str2, uint len)
    00090 {
    00091     return (str1 && str2) ? strncmp(str1, str2, len)
    00092         : (str1 ? 1 : (str2 ? -1 : 0));
    00093 }
    00094 Q_CORE_EXPORT int qstricmp(const char *, const char *);
    00095 Q_CORE_EXPORT int qstrnicmp(const char *, const char *, uint len);
    00096
    00097 // implemented in qvsnprintf.cpp
    00098 Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
    00099 Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
    00100
    00101 #ifdef QT3_SUPPORT
    00102 inline QT3_SUPPORT void *qmemmove(void *dst, const void *src, uint len)
    00103 { return memmove(dst, src, len); }
    00104 inline QT3_SUPPORT uint cstrlen(const char *str)
    00105 { return uint(strlen(str)); }
    00106 inline QT3_SUPPORT char *cstrcpy(char *dst, const char *src)
    00107 { return qstrcpy(dst,src); }
    00108 inline QT3_SUPPORT int cstrcmp(const char *str1, const char *str2)
    00109 { return strcmp(str1,str2); }
    00110 inline QT3_SUPPORT int cstrncmp(const char *str1, const char *str2, uint len)
    00111 { return strncmp(str1,str2,len); }
    00112 #endif
    00113
    00114 // qChecksum: Internet checksum
    00115
    00116 Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len);
    00117
    00118 class QByteRef;
    00119 class QString;
    00120 class QDataStream;
    00121 template <typename T> class QList;
    00122
    00123 class Q_CORE_EXPORT QByteArray
    00124 {
    00125 private:
    00126     struct Data {
    00127         QBasicAtomicInt ref;
    00128         int alloc, size;
    00129         // ### Qt 5.0: We need to add the missing capacity bit
    00130         // (like other tool classes have), to maintain the
    00131         // reserved memory on resize.
    00132         char *data;
    00133         char array[1];
    00134     };
    00135
    00136 public:
    00137     inline QByteArray();
    00138     QByteArray(const char *);
    00139     QByteArray(const char *, int size);
    00140     QByteArray(int size, char c);
    00141     QByteArray(int size, Qt::Initialization);
    00142     inline QByteArray(const QByteArray &);
    00143     inline ~QByteArray();
    00144
    00145     QByteArray &operator=(const QByteArray &);
    00146     QByteArray &operator=(const char *str);
    00147
    00148     inline int size() const;
    00149     bool isEmpty() const;
    00150     void resize(int size);
    00151
    00152     QByteArray &fill(char c, int size = -1);
    00153
    00154     int capacity() const;
    00155     void reserve(int size);
    00156     void squeeze();
    00157
    00158 #ifndef QT_NO_CAST_FROM_BYTEARRAY
    00159     operator const char *() const;
    00160     operator const void *() const;
    00161 #endif
    00162     char *data();
    00163     const char *data() const;
    00164     inline const char *constData() const;
    00165     inline void detach();
    00166     bool isDetached() const;
    00167     inline bool isSharedWith(const QByteArray &other) const { return d == other.d; }
    00168     void clear();
    00169
    00170 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
    00171     const char at(int i) const;
    00172     const char operator[](int i) const;
    00173     const char operator[](uint i) const;
    00174 #else
    00175     char at(int i) const;
    00176     char operator[](int i) const;
    00177     char operator[](uint i) const;
    00178 #endif
    00179     QByteRef operator[](int i);
    00180     QByteRef operator[](uint i);
    00181
    00182     int indexOf(char c, int from = 0) const;
    00183     int indexOf(const char *c, int from = 0) const;
    00184     int indexOf(const QByteArray &a, int from = 0) const;
    00185     int lastIndexOf(char c, int from = -1) const;
    00186     int lastIndexOf(const char *c, int from = -1) const;
    00187     int lastIndexOf(const QByteArray &a, int from = -1) const;
    00188
    00189     QBool contains(char c) const;
    00190     QBool contains(const char *a) const;
    00191     QBool contains(const QByteArray &a) const;
    00192     int count(char c) const;
    00193     int count(const char *a) const;
    00194     int count(const QByteArray &a) const;
    00195
    00196     QByteArray left(int len) const;
    00197     QByteArray right(int len) const;
    00198     QByteArray mid(int index, int len = -1) const;
    00199
    00200     bool startsWith(const QByteArray &a) const;
    00201     bool startsWith(char c) const;
    00202     bool startsWith(const char *c) const;
    00203
    00204     bool endsWith(const QByteArray &a) const;
    00205     bool endsWith(char c) const;
    00206     bool endsWith(const char *c) const;
    00207
    00208     void truncate(int pos);
    00209     void chop(int n);
    00210
    00211     QByteArray toLower() const;
    00212     QByteArray toUpper() const;
    00213
    00214     QByteArray trimmed() const;
    00215     QByteArray simplified() const;
    00216     QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const;
    00217     QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const;
    00218
    00219 #ifdef QT3_SUPPORT
    00220     inline QT3_SUPPORT QByteArray leftJustify(uint width, char aFill = ' ', bool aTruncate = false) const
    00221     { return leftJustified(int(width), aFill, aTruncate); }
    00222     inline QT3_SUPPORT QByteArray rightJustify(uint width, char aFill = ' ', bool aTruncate = false) const
    00223     { return rightJustified(int(width), aFill, aTruncate); }
    00224 #endif
    00225
    00226     QByteArray &prepend(char c);
    00227     QByteArray &prepend(const char *s);
    00228     QByteArray &prepend(const char *s, int len);
    00229     QByteArray &prepend(const QByteArray &a);
    00230     QByteArray &append(char c);
    00231     QByteArray &append(const char *s);
    00232     QByteArray &append(const char *s, int len);
    00233     QByteArray &append(const QByteArray &a);
    00234     QByteArray &insert(int i, char c);
    00235     QByteArray &insert(int i, const char *s);
    00236     QByteArray &insert(int i, const char *s, int len);
    00237     QByteArray &insert(int i, const QByteArray &a);
    00238     QByteArray &remove(int index, int len);
    00239     QByteArray &replace(int index, int len, const char *s);
    00240     QByteArray &replace(int index, int len, const char *s, int alen);
    00241     QByteArray &replace(int index, int len, const QByteArray &s);
    00242     QByteArray &replace(char before, const char *after);
    00243     QByteArray &replace(char before, const QByteArray &after);
    00244     QByteArray &replace(const char *before, const char *after);
    00245     QByteArray &replace(const char *before, int bsize, const char *after, int asize);
    00246     QByteArray &replace(const QByteArray &before, const QByteArray &after);
    00247     QByteArray &replace(const QByteArray &before, const char *after);
    00248     QByteArray &replace(const char *before, const QByteArray &after);
    00249     QByteArray &replace(char before, char after);
    00250     QByteArray &operator+=(char c);
    00251     QByteArray &operator+=(const char *s);
    00252     QByteArray &operator+=(const QByteArray &a);
    00253
    00254     QList<QByteArray> split(char sep) const;
    00255
    00256     QByteArray repeated(int times) const;
    00257
    00258 #ifndef QT_NO_CAST_TO_ASCII
    00259     QT_ASCII_CAST_WARN QByteArray &append(const QString &s);
    00260     QT_ASCII_CAST_WARN QByteArray &insert(int i, const QString &s);
    00261     QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const char *after);
    00262     QT_ASCII_CAST_WARN QByteArray &replace(char c, const QString &after);
    00263     QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const QByteArray &after);
    00264
    00265     QT_ASCII_CAST_WARN QByteArray &operator+=(const QString &s);
    00266     QT_ASCII_CAST_WARN int indexOf(const QString &s, int from = 0) const;
    00267     QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int from = -1) const;
    00268 #endif
    00269 #ifndef QT_NO_CAST_FROM_ASCII
    00270     inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const;
    00271     inline QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const;
    00272     inline QT_ASCII_CAST_WARN bool operator<(const QString &s2) const;
    00273     inline QT_ASCII_CAST_WARN bool operator>(const QString &s2) const;
    00274     inline QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const;
    00275     inline QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const;
    00276 #endif
    00277
    00278     short toShort(bool *ok = 0, int base = 10) const;
    00279     ushort toUShort(bool *ok = 0, int base = 10) const;
    00280     int toInt(bool *ok = 0, int base = 10) const;
    00281     uint toUInt(bool *ok = 0, int base = 10) const;
    00282     long toLong(bool *ok = 0, int base = 10) const;
    00283     ulong toULong(bool *ok = 0, int base = 10) const;
    00284     qlonglong toLongLong(bool *ok = 0, int base = 10) const;
    00285     qulonglong toULongLong(bool *ok = 0, int base = 10) const;
    00286     float toFloat(bool *ok = 0) const;
    00287     double toDouble(bool *ok = 0) const;
    00288     QByteArray toBase64() const;
    00289     QByteArray toHex() const;
    00290     QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(),
    00291                                  const QByteArray &include = QByteArray(),
    00292                                  char percent = '%') const;
    00293
    00294     QByteArray &setNum(short, int base = 10);
    00295     QByteArray &setNum(ushort, int base = 10);
    00296     QByteArray &setNum(int, int base = 10);
    00297     QByteArray &setNum(uint, int base = 10);
    00298     QByteArray &setNum(qlonglong, int base = 10);
    00299     QByteArray &setNum(qulonglong, int base = 10);
    00300     QByteArray &setNum(float, char f = 'g', int prec = 6);
    00301     QByteArray &setNum(double, char f = 'g', int prec = 6);
    00302     QByteArray &setRawData(const char *a, uint n); // ### Qt 5: use an int
    00303
    00304     static QByteArray number(int, int base = 10);
    00305     static QByteArray number(uint, int base = 10);
    00306     static QByteArray number(qlonglong, int base = 10);
    00307     static QByteArray number(qulonglong, int base = 10);
    00308     static QByteArray number(double, char f = 'g', int prec = 6);
    00309     static QByteArray fromRawData(const char *, int size);
    00310     static QByteArray fromBase64(const QByteArray &base64);
    00311     static QByteArray fromHex(const QByteArray &hexEncoded);
    00312     static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%');
    00313
    00314
    00315     typedef char *iterator;
    00316     typedef const char *const_iterator;
    00317     typedef iterator Iterator;
    00318     typedef const_iterator ConstIterator;
    00319     iterator begin();
    00320     const_iterator begin() const;
    00321     const_iterator constBegin() const;
    00322     iterator end();
    00323     const_iterator end() const;
    00324     const_iterator constEnd() const;
    00325
    00326     // stl compatibility
    00327     typedef const char & const_reference;
    00328     typedef char & reference;
    00329     typedef char value_type;
    00330     void push_back(char c);
    00331     void push_back(const char *c);
    00332     void push_back(const QByteArray &a);
    00333     void push_front(char c);
    00334     void push_front(const char *c);
    00335     void push_front(const QByteArray &a);
    00336
    00337     inline int count() const { return d->size; }
    00338     int length() const { return d->size; }
    00339     bool isNull() const;
    00340
    00341     // compatibility
    00342 #ifdef QT3_SUPPORT
    00343     QT3_SUPPORT_CONSTRUCTOR QByteArray(int size);
    00344     inline QT3_SUPPORT QByteArray& duplicate(const QByteArray& a) { *this = a; return *this; }
    00345     inline QT3_SUPPORT QByteArray& duplicate(const char *a, uint n)
    00346     { *this = QByteArray(a, n); return *this; }
    00347     inline QT3_SUPPORT void resetRawData(const char *, uint) { clear(); }
    00348     inline QT3_SUPPORT QByteArray lower() const { return toLower(); }
    00349     inline QT3_SUPPORT QByteArray upper() const { return toUpper(); }
    00350     inline QT3_SUPPORT QByteArray stripWhiteSpace() const { return trimmed(); }
    00351     inline QT3_SUPPORT QByteArray simplifyWhiteSpace() const { return simplified(); }
    00352     inline QT3_SUPPORT int find(char c, int from = 0) const { return indexOf(c, from); }
    00353     inline QT3_SUPPORT int find(const char *c, int from = 0) const { return indexOf(c, from); }
    00354     inline QT3_SUPPORT int find(const QByteArray &ba, int from = 0) const { return indexOf(ba, from); }
    00355     inline QT3_SUPPORT int findRev(char c, int from = -1) const { return lastIndexOf(c, from); }
    00356     inline QT3_SUPPORT int findRev(const char *c, int from = -1) const { return lastIndexOf(c, from); }
    00357     inline QT3_SUPPORT int findRev(const QByteArray &ba, int from = -1) const { return lastIndexOf(ba, from); }
    00358 #ifndef QT_NO_CAST_TO_ASCII
    00359     QT3_SUPPORT int find(const QString &s, int from = 0) const;
    00360     QT3_SUPPORT int findRev(const QString &s, int from = -1) const;
    00361 #endif
    00362 #endif
    00363
    00364 private:
    00365     operator QNoImplicitBoolCast() const;
    00366     static Data shared_null;
    00367     static Data shared_empty;
    00368     Data *d;
    00369     QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {}
    00370     void realloc(int alloc);
    00371     void expand(int i);
    00372     QByteArray nulTerminated() const;
    00373
    00374     friend class QByteRef;
    00375     friend class QString;
    00376     friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
    00377 public:
    00378     typedef Data * DataPtr;
    00379     inline DataPtr &data_ptr() { return d; }
    00380 };
    00381
    00382 inline QByteArray::QByteArray(): d(&shared_null) { d->ref.ref(); }
    00383 inline QByteArray::~QByteArray() { if (!d->ref.deref()) qFree(d); }
    00384 inline int QByteArray::size() const
    00385 { return d->size; }
    00386
    00387 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
    00388 inline const char QByteArray::at(int i) const
    00389 { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
    00390 inline const char QByteArray::operator[](int i) const
    00391 { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
    00392 inline const char QByteArray::operator[](uint i) const
    00393 { Q_ASSERT(i < uint(size())); return d->data[i]; }
    00394 #else
    00395 inline char QByteArray::at(int i) const
    00396 { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
    00397 inline char QByteArray::operator[](int i) const
    00398 { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
    00399 inline char QByteArray::operator[](uint i) const
    00400 { Q_ASSERT(i < uint(size())); return d->data[i]; }
    00401 #endif
    00402
    00403 inline bool QByteArray::isEmpty() const
    00404 { return d->size == 0; }
    00405 #ifndef QT_NO_CAST_FROM_BYTEARRAY
    00406 inline QByteArray::operator const char *() const
    00407 { return d->data; }
    00408 inline QByteArray::operator const void *() const
    00409 { return d->data; }
    00410 #endif
    00411 inline char *QByteArray::data()
    00412 { detach(); return d->data; }
    00413 inline const char *QByteArray::data() const
    00414 { return d->data; }
    00415 inline const char *QByteArray::constData() const
    00416 { return d->data; }
    00417 inline void QByteArray::detach()
    00418 { if (d->ref != 1 || d->data != d->array) realloc(d->size); }
    00419 inline bool QByteArray::isDetached() const
    00420 { return d->ref == 1; }
    00421 inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
    00422 { d->ref.ref(); }
    00423 #ifdef QT3_SUPPORT
    00424 inline QByteArray::QByteArray(int aSize) : d(&shared_null)
    00425 { d->ref.ref(); if (aSize > 0) fill('\0', aSize); }
    00426 #endif
    00427
    00428 inline int QByteArray::capacity() const
    00429 { return d->alloc; }
    00430
    00431 inline void QByteArray::reserve(int asize)
    00432 { if (d->ref != 1 || asize > d->alloc) realloc(asize); }
    00433
    00434 inline void QByteArray::squeeze()
    00435 { if (d->size < d->alloc) realloc(d->size); }
    00436
    00437 class Q_CORE_EXPORT QByteRef {
    00438     QByteArray &a;
    00439     int i;
    00440     inline QByteRef(QByteArray &array, int idx)
    00441         : a(array),i(idx) {}
    00442     friend class QByteArray;
    00443 public:
    00444 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
    00445     inline operator const char() const
    00446         { return i < a.d->size ? a.d->data[i] : char(0); }
    00447 #else
    00448     inline operator char() const
    00449         { return i < a.d->size ? a.d->data[i] : char(0); }
    00450 #endif
    00451     inline QByteRef &operator=(char c)
    00452         { if (i >= a.d->size) a.expand(i); else a.detach();
    00453           a.d->data[i] = c;  return *this; }
    00454     inline QByteRef &operator=(const QByteRef &c)
    00455         { if (i >= a.d->size) a.expand(i); else a.detach();
    00456           a.d->data[i] = c.a.d->data[c.i];  return *this; }
    00457     inline bool operator==(char c) const
    00458     { return a.d->data[i] == c; }
    00459     inline bool operator!=(char c) const
    00460     { return a.d->data[i] != c; }
    00461     inline bool operator>(char c) const
    00462     { return a.d->data[i] > c; }
    00463     inline bool operator>=(char c) const
    00464     { return a.d->data[i] >= c; }
    00465     inline bool operator<(char c) const
    00466     { return a.d->data[i] < c; }
    00467     inline bool operator<=(char c) const
    00468     { return a.d->data[i] <= c; }
    00469 };
    00470
    00471 inline QByteRef QByteArray::operator[](int i)
    00472 { Q_ASSERT(i >= 0); return QByteRef(*this, i); }
    00473 inline QByteRef QByteArray::operator[](uint i)
    00474 { return QByteRef(*this, i); }
    00475 inline QByteArray::iterator QByteArray::begin()
    00476 { detach(); return d->data; }
    00477 inline QByteArray::const_iterator QByteArray::begin() const
    00478 { return d->data; }
    00479 inline QByteArray::const_iterator QByteArray::constBegin() const
    00480 { return d->data; }
    00481 inline QByteArray::iterator QByteArray::end()
    00482 { detach(); return d->data + d->size; }
    00483 inline QByteArray::const_iterator QByteArray::end() const
    00484 { return d->data + d->size; }
    00485 inline QByteArray::const_iterator QByteArray::constEnd() const
    00486 { return d->data + d->size; }
    00487 inline QByteArray &QByteArray::operator+=(char c)
    00488 { return append(c); }
    00489 inline QByteArray &QByteArray::operator+=(const char *s)
    00490 { return append(s); }
    00491 inline QByteArray &QByteArray::operator+=(const QByteArray &a)
    00492 { return append(a); }
    00493 inline void QByteArray::push_back(char c)
    00494 { append(c); }
    00495 inline void QByteArray::push_back(const char *c)
    00496 { append(c); }
    00497 inline void QByteArray::push_back(const QByteArray &a)
    00498 { append(a); }
    00499 inline void QByteArray::push_front(char c)
    00500 { prepend(c); }
    00501 inline void QByteArray::push_front(const char *c)
    00502 { prepend(c); }
    00503 inline void QByteArray::push_front(const QByteArray &a)
    00504 { prepend(a); }
    00505 inline QBool QByteArray::contains(const QByteArray &a) const
    00506 { return QBool(indexOf(a) != -1); }
    00507 inline QBool QByteArray::contains(char c) const
    00508 { return QBool(indexOf(c) != -1); }
    00509 inline bool operator==(const QByteArray &a1, const QByteArray &a2)
    00510 { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); }
    00511 inline bool operator==(const QByteArray &a1, const char *a2)
    00512 { return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); }
    00513 inline bool operator==(const char *a1, const QByteArray &a2)
    00514 { return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); }
    00515 inline bool operator!=(const QByteArray &a1, const QByteArray &a2)
    00516 { return !(a1==a2); }
    00517 inline bool operator!=(const QByteArray &a1, const char *a2)
    00518 { return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); }
    00519 inline bool operator!=(const char *a1, const QByteArray &a2)
    00520 { return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); }
    00521 inline bool operator<(const QByteArray &a1, const QByteArray &a2)
    00522 { return qstrcmp(a1, a2) < 0; }
    00523  inline bool operator<(const QByteArray &a1, const char *a2)
    00524 { return qstrcmp(a1, a2) < 0; }
    00525 inline bool operator<(const char *a1, const QByteArray &a2)
    00526 { return qstrcmp(a1, a2) < 0; }
    00527 inline bool operator<=(const QByteArray &a1, const QByteArray &a2)
    00528 { return qstrcmp(a1, a2) <= 0; }
    00529 inline bool operator<=(const QByteArray &a1, const char *a2)
    00530 { return qstrcmp(a1, a2) <= 0; }
    00531 inline bool operator<=(const char *a1, const QByteArray &a2)
    00532 { return qstrcmp(a1, a2) <= 0; }
    00533 inline bool operator>(const QByteArray &a1, const QByteArray &a2)
    00534 { return qstrcmp(a1, a2) > 0; }
    00535 inline bool operator>(const QByteArray &a1, const char *a2)
    00536 { return qstrcmp(a1, a2) > 0; }
    00537 inline bool operator>(const char *a1, const QByteArray &a2)
    00538 { return qstrcmp(a1, a2) > 0; }
    00539 inline bool operator>=(const QByteArray &a1, const QByteArray &a2)
    00540 { return qstrcmp(a1, a2) >= 0; }
    00541 inline bool operator>=(const QByteArray &a1, const char *a2)
    00542 { return qstrcmp(a1, a2) >= 0; }
    00543 inline bool operator>=(const char *a1, const QByteArray &a2)
    00544 { return qstrcmp(a1, a2) >= 0; }
    00545 inline const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
    00546 { return QByteArray(a1) += a2; }
    00547 inline const QByteArray operator+(const QByteArray &a1, const char *a2)
    00548 { return QByteArray(a1) += a2; }
    00549 inline const QByteArray operator+(const QByteArray &a1, char a2)
    00550 { return QByteArray(a1) += a2; }
    00551 inline const QByteArray operator+(const char *a1, const QByteArray &a2)
    00552 { return QByteArray(a1) += a2; }
    00553 inline const QByteArray operator+(char a1, const QByteArray &a2)
    00554 { return QByteArray(&a1, 1) += a2; }
    00555 inline QBool QByteArray::contains(const char *c) const
    00556 { return QBool(indexOf(c) != -1); }
    00557 inline QByteArray &QByteArray::replace(char before, const char *c)
    00558 { return replace(&before, 1, c, qstrlen(c)); }
    00559 inline QByteArray &QByteArray::replace(const QByteArray &before, const char *c)
    00560 { return replace(before.constData(), before.size(), c, qstrlen(c)); }
    00561 inline QByteArray &QByteArray::replace(const char *before, const char *after)
    00562 { return replace(before, qstrlen(before), after, qstrlen(after)); }
    00563
    00564 inline QByteArray &QByteArray::setNum(short n, int base)
    00565 { return setNum(qlonglong(n), base); }
    00566 inline QByteArray &QByteArray::setNum(ushort n, int base)
    00567 { return setNum(qulonglong(n), base); }
    00568 inline QByteArray &QByteArray::setNum(int n, int base)
    00569 { return setNum(qlonglong(n), base); }
    00570 inline QByteArray &QByteArray::setNum(uint n, int base)
    00571 { return setNum(qulonglong(n), base); }
    00572 inline QByteArray &QByteArray::setNum(float n, char f, int prec)
    00573 { return setNum(double(n),f,prec); }
    00574
    00575
    00576 #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE))
    00577 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &);
    00578 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QByteArray &);
    00579 #endif
    00580
    00581 #ifndef QT_NO_COMPRESS
    00582 Q_CORE_EXPORT QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel = -1);
    00583 Q_CORE_EXPORT QByteArray qUncompress(const uchar* data, int nbytes);
    00584 inline QByteArray qCompress(const QByteArray& data, int compressionLevel = -1)
    00585 { return qCompress(reinterpret_cast<const uchar *>(data.constData()), data.size(), compressionLevel); }
    00586 inline QByteArray qUncompress(const QByteArray& data)
    00587 { return qUncompress(reinterpret_cast<const uchar*>(data.constData()), data.size()); }
    00588 #endif
    00589
    00590 Q_DECLARE_TYPEINFO(QByteArray, Q_MOVABLE_TYPE);
    00591 Q_DECLARE_SHARED(QByteArray)
    00592
    00593 QT_END_NAMESPACE
    00594
    00595 QT_END_HEADER
    00596
    00597 #endif // QBYTEARRAY_H