LCOV - code coverage report
Current view: top level - usr/include/x86_64-linux-gnu/qt5/QtCore - qbytearray.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 30 83.3 %
Date: 2016-11-29 15:07:43 Functions: 12 15 80.0 %

          Line data    Source code
       1             : /****************************************************************************
       2             : **
       3             : ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
       4             : ** Contact: http://www.qt-project.org/legal
       5             : **
       6             : ** This file is part of the QtCore module of the Qt Toolkit.
       7             : **
       8             : ** $QT_BEGIN_LICENSE:LGPL$
       9             : ** Commercial License Usage
      10             : ** Licensees holding valid commercial Qt licenses may use this file in
      11             : ** accordance with the commercial license agreement provided with the
      12             : ** Software or, alternatively, in accordance with the terms contained in
      13             : ** a written agreement between you and Digia.  For licensing terms and
      14             : ** conditions see http://qt.digia.com/licensing.  For further information
      15             : ** use the contact form at http://qt.digia.com/contact-us.
      16             : **
      17             : ** GNU Lesser General Public License Usage
      18             : ** Alternatively, this file may be used under the terms of the GNU Lesser
      19             : ** General Public License version 2.1 as published by the Free Software
      20             : ** Foundation and appearing in the file LICENSE.LGPL included in the
      21             : ** packaging of this file.  Please review the following information to
      22             : ** ensure the GNU Lesser General Public License version 2.1 requirements
      23             : ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
      24             : **
      25             : ** In addition, as a special exception, Digia gives you certain additional
      26             : ** rights.  These rights are described in the Digia Qt LGPL Exception
      27             : ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
      28             : **
      29             : ** GNU General Public License Usage
      30             : ** Alternatively, this file may be used under the terms of the GNU
      31             : ** General Public License version 3.0 as published by the Free Software
      32             : ** Foundation and appearing in the file LICENSE.GPL included in the
      33             : ** packaging of this file.  Please review the following information to
      34             : ** ensure the GNU General Public License version 3.0 requirements will be
      35             : ** met: http://www.gnu.org/copyleft/gpl.html.
      36             : **
      37             : **
      38             : ** $QT_END_LICENSE$
      39             : **
      40             : ****************************************************************************/
      41             : 
      42             : #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             : #ifdef Q_OS_MAC
      69             : Q_FORWARD_DECLARE_CF_TYPE(CFData);
      70             : #  ifdef __OBJC__
      71             : Q_FORWARD_DECLARE_OBJC_CLASS(NSData);
      72             : #  endif
      73             : #endif
      74             : 
      75             : QT_BEGIN_NAMESPACE
      76             : 
      77             : 
      78             : /*****************************************************************************
      79             :   Safe and portable C string functions; extensions to standard string.h
      80             :  *****************************************************************************/
      81             : 
      82             : Q_CORE_EXPORT char *qstrdup(const char *);
      83             : 
      84             : inline uint qstrlen(const char *str)
      85             : { return str ? uint(strlen(str)) : 0; }
      86             : 
      87          17 : inline uint qstrnlen(const char *str, uint maxlen)
      88             : {
      89          17 :     uint length = 0;
      90          17 :     if (str) {
      91        1344 :         while (length < maxlen && *str++)
      92        1310 :             length++;
      93             :     }
      94          17 :     return length;
      95             : }
      96             : 
      97             : Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src);
      98             : Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, uint len);
      99             : 
     100             : Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2);
     101             : Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const QByteArray &str2);
     102             : Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const char *str2);
     103             : static inline int qstrcmp(const char *str1, const QByteArray &str2)
     104             : { return -qstrcmp(str2, str1); }
     105             : 
     106             : inline int qstrncmp(const char *str1, const char *str2, uint len)
     107             : {
     108             :     return (str1 && str2) ? strncmp(str1, str2, len)
     109             :         : (str1 ? 1 : (str2 ? -1 : 0));
     110             : }
     111             : Q_CORE_EXPORT int qstricmp(const char *, const char *);
     112             : Q_CORE_EXPORT int qstrnicmp(const char *, const char *, uint len);
     113             : 
     114             : // implemented in qvsnprintf.cpp
     115             : Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
     116             : Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
     117             : 
     118             : // qChecksum: Internet checksum
     119             : 
     120             : Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len);
     121             : 
     122             : class QByteRef;
     123             : class QString;
     124             : class QDataStream;
     125             : template <typename T> class QList;
     126             : 
     127             : typedef QArrayData QByteArrayData;
     128             : 
     129             : template<int N> struct QStaticByteArrayData
     130             : {
     131             :     QByteArrayData ba;
     132             :     char data[N + 1];
     133             : 
     134             :     QByteArrayData *data_ptr() const
     135             :     {
     136             :         Q_ASSERT(ba.ref.isStatic());
     137             :         return const_cast<QByteArrayData *>(&ba);
     138             :     }
     139             : };
     140             : 
     141             : struct QByteArrayDataPtr
     142             : {
     143             :     QByteArrayData *ptr;
     144             : };
     145             : 
     146             : #define Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \
     147             :     Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset)
     148             :     /**/
     149             : 
     150             : #define Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(size) \
     151             :     Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, sizeof(QByteArrayData)) \
     152             :     /**/
     153             : 
     154             : #if defined(Q_COMPILER_LAMBDA)
     155             : 
     156             : #  define QByteArrayLiteral(str) \
     157             :     ([]() -> QByteArray { \
     158             :         enum { Size = sizeof(str) - 1 }; \
     159             :         static const QStaticByteArrayData<Size> qbytearray_literal = { \
     160             :             Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \
     161             :             str }; \
     162             :         QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \
     163             :         const QByteArray ba(holder); \
     164             :         return ba; \
     165             :     }()) \
     166             :     /**/
     167             : 
     168             : #endif
     169             : 
     170             : #ifndef QByteArrayLiteral
     171             : // no lambdas, not GCC, just return a temporary QByteArray
     172             : 
     173             : # define QByteArrayLiteral(str) QByteArray(str, sizeof(str) - 1)
     174             : #endif
     175             : 
     176             : class Q_CORE_EXPORT QByteArray
     177             : {
     178             : private:
     179             :     typedef QTypedArrayData<char> Data;
     180             : 
     181             : public:
     182             :     enum Base64Option {
     183             :         Base64Encoding = 0,
     184             :         Base64UrlEncoding = 1,
     185             : 
     186             :         KeepTrailingEquals = 0,
     187             :         OmitTrailingEquals = 2
     188             :     };
     189             :     Q_DECLARE_FLAGS(Base64Options, Base64Option)
     190             : 
     191             :     inline QByteArray();
     192             :     QByteArray(const char *, int size = -1);
     193             :     QByteArray(int size, char c);
     194             :     QByteArray(int size, Qt::Initialization);
     195             :     inline QByteArray(const QByteArray &);
     196             :     inline ~QByteArray();
     197             : 
     198             :     QByteArray &operator=(const QByteArray &);
     199             :     QByteArray &operator=(const char *str);
     200             : #ifdef Q_COMPILER_RVALUE_REFS
     201           1 :     inline QByteArray(QByteArray && other) : d(other.d) { other.d = Data::sharedNull(); }
     202          46 :     inline QByteArray &operator=(QByteArray &&other)
     203          46 :     { qSwap(d, other.d); return *this; }
     204             : #endif
     205             : 
     206             :     inline void swap(QByteArray &other) { qSwap(d, other.d); }
     207             : 
     208             :     inline int size() const;
     209             :     bool isEmpty() const;
     210             :     void resize(int size);
     211             : 
     212             :     QByteArray &fill(char c, int size = -1);
     213             : 
     214             :     int capacity() const;
     215             :     void reserve(int size);
     216             :     void squeeze();
     217             : 
     218             : #ifndef QT_NO_CAST_FROM_BYTEARRAY
     219             :     operator const char *() const;
     220             :     operator const void *() const;
     221             : #endif
     222             :     char *data();
     223             :     const char *data() const;
     224             :     inline const char *constData() const;
     225             :     inline void detach();
     226             :     bool isDetached() const;
     227             :     inline bool isSharedWith(const QByteArray &other) const { return d == other.d; }
     228             :     void clear();
     229             : 
     230             :     char at(int i) const;
     231             :     char operator[](int i) const;
     232             :     char operator[](uint i) const;
     233             :     QByteRef operator[](int i);
     234             :     QByteRef operator[](uint i);
     235             : 
     236             :     int indexOf(char c, int from = 0) const;
     237             :     int indexOf(const char *c, int from = 0) const;
     238             :     int indexOf(const QByteArray &a, int from = 0) const;
     239             :     int lastIndexOf(char c, int from = -1) const;
     240             :     int lastIndexOf(const char *c, int from = -1) const;
     241             :     int lastIndexOf(const QByteArray &a, int from = -1) const;
     242             : 
     243             :     bool contains(char c) const;
     244             :     bool contains(const char *a) const;
     245             :     bool contains(const QByteArray &a) const;
     246             :     int count(char c) const;
     247             :     int count(const char *a) const;
     248             :     int count(const QByteArray &a) const;
     249             : 
     250             :     QByteArray left(int len) const;
     251             :     QByteArray right(int len) const;
     252             :     QByteArray mid(int index, int len = -1) const;
     253             : 
     254             :     bool startsWith(const QByteArray &a) const;
     255             :     bool startsWith(char c) const;
     256             :     bool startsWith(const char *c) const;
     257             : 
     258             :     bool endsWith(const QByteArray &a) const;
     259             :     bool endsWith(char c) const;
     260             :     bool endsWith(const char *c) const;
     261             : 
     262             :     void truncate(int pos);
     263             :     void chop(int n);
     264             : 
     265             :     QByteArray toLower() const;
     266             :     QByteArray toUpper() const;
     267             : 
     268             :     QByteArray trimmed() const;
     269             :     QByteArray simplified() const;
     270             :     QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const;
     271             :     QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const;
     272             : 
     273             :     QByteArray &prepend(char c);
     274             :     QByteArray &prepend(const char *s);
     275             :     QByteArray &prepend(const char *s, int len);
     276             :     QByteArray &prepend(const QByteArray &a);
     277             :     QByteArray &append(char c);
     278             :     QByteArray &append(const char *s);
     279             :     QByteArray &append(const char *s, int len);
     280             :     QByteArray &append(const QByteArray &a);
     281             :     QByteArray &insert(int i, char c);
     282             :     QByteArray &insert(int i, const char *s);
     283             :     QByteArray &insert(int i, const char *s, int len);
     284             :     QByteArray &insert(int i, const QByteArray &a);
     285             :     QByteArray &remove(int index, int len);
     286             :     QByteArray &replace(int index, int len, const char *s);
     287             :     QByteArray &replace(int index, int len, const char *s, int alen);
     288             :     QByteArray &replace(int index, int len, const QByteArray &s);
     289             :     QByteArray &replace(char before, const char *after);
     290             :     QByteArray &replace(char before, const QByteArray &after);
     291             :     QByteArray &replace(const char *before, const char *after);
     292             :     QByteArray &replace(const char *before, int bsize, const char *after, int asize);
     293             :     QByteArray &replace(const QByteArray &before, const QByteArray &after);
     294             :     QByteArray &replace(const QByteArray &before, const char *after);
     295             :     QByteArray &replace(const char *before, const QByteArray &after);
     296             :     QByteArray &replace(char before, char after);
     297             :     QByteArray &operator+=(char c);
     298             :     QByteArray &operator+=(const char *s);
     299             :     QByteArray &operator+=(const QByteArray &a);
     300             : 
     301             :     QList<QByteArray> split(char sep) const;
     302             : 
     303             :     QByteArray repeated(int times) const;
     304             : 
     305             : #ifndef QT_NO_CAST_TO_ASCII
     306             :     QT_ASCII_CAST_WARN QByteArray &append(const QString &s);
     307             :     QT_ASCII_CAST_WARN QByteArray &insert(int i, const QString &s);
     308             :     QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const char *after);
     309             :     QT_ASCII_CAST_WARN QByteArray &replace(char c, const QString &after);
     310             :     QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const QByteArray &after);
     311             : 
     312             :     QT_ASCII_CAST_WARN QByteArray &operator+=(const QString &s);
     313             :     QT_ASCII_CAST_WARN int indexOf(const QString &s, int from = 0) const;
     314             :     QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int from = -1) const;
     315             : #endif
     316             : #ifndef QT_NO_CAST_FROM_ASCII
     317             :     inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const;
     318             :     inline QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const;
     319             :     inline QT_ASCII_CAST_WARN bool operator<(const QString &s2) const;
     320             :     inline QT_ASCII_CAST_WARN bool operator>(const QString &s2) const;
     321             :     inline QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const;
     322             :     inline QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const;
     323             : #endif
     324             : 
     325             :     short toShort(bool *ok = 0, int base = 10) const;
     326             :     ushort toUShort(bool *ok = 0, int base = 10) const;
     327             :     int toInt(bool *ok = 0, int base = 10) const;
     328             :     uint toUInt(bool *ok = 0, int base = 10) const;
     329             :     long toLong(bool *ok = 0, int base = 10) const;
     330             :     ulong toULong(bool *ok = 0, int base = 10) const;
     331             :     qlonglong toLongLong(bool *ok = 0, int base = 10) const;
     332             :     qulonglong toULongLong(bool *ok = 0, int base = 10) const;
     333             :     float toFloat(bool *ok = 0) const;
     334             :     double toDouble(bool *ok = 0) const;
     335             :     QByteArray toBase64(Base64Options options) const;
     336             :     QByteArray toBase64() const; // ### Qt6 merge with previous
     337             :     QByteArray toHex() const;
     338             :     QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(),
     339             :                                  const QByteArray &include = QByteArray(),
     340             :                                  char percent = '%') const;
     341             : 
     342             :     QByteArray &setNum(short, int base = 10);
     343             :     QByteArray &setNum(ushort, int base = 10);
     344             :     QByteArray &setNum(int, int base = 10);
     345             :     QByteArray &setNum(uint, int base = 10);
     346             :     QByteArray &setNum(qlonglong, int base = 10);
     347             :     QByteArray &setNum(qulonglong, int base = 10);
     348             :     QByteArray &setNum(float, char f = 'g', int prec = 6);
     349             :     QByteArray &setNum(double, char f = 'g', int prec = 6);
     350             :     QByteArray &setRawData(const char *a, uint n); // ### Qt 6: use an int
     351             : 
     352             :     static QByteArray number(int, int base = 10);
     353             :     static QByteArray number(uint, int base = 10);
     354             :     static QByteArray number(qlonglong, int base = 10);
     355             :     static QByteArray number(qulonglong, int base = 10);
     356             :     static QByteArray number(double, char f = 'g', int prec = 6);
     357             :     static QByteArray fromRawData(const char *, int size);
     358             :     static QByteArray fromBase64(const QByteArray &base64, Base64Options options);
     359             :     static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous
     360             :     static QByteArray fromHex(const QByteArray &hexEncoded);
     361             :     static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%');
     362             : 
     363             : #if defined(Q_OS_MAC) || defined(Q_QDOC)
     364             :     static QByteArray fromCFData(CFDataRef data);
     365             :     static QByteArray fromRawCFData(CFDataRef data);
     366             :     CFDataRef toCFData() const Q_DECL_CF_RETURNS_RETAINED;
     367             :     CFDataRef toRawCFData() const Q_DECL_CF_RETURNS_RETAINED;
     368             : #  if defined(__OBJC__) || defined(Q_QDOC)
     369             :     static QByteArray fromNSData(const NSData *data);
     370             :     static QByteArray fromRawNSData(const NSData *data);
     371             :     NSData *toNSData() const Q_DECL_NS_RETURNS_AUTORELEASED;
     372             :     NSData *toRawNSData() const Q_DECL_NS_RETURNS_AUTORELEASED;
     373             : #  endif
     374             : #endif
     375             : 
     376             :     typedef char *iterator;
     377             :     typedef const char *const_iterator;
     378             :     typedef iterator Iterator;
     379             :     typedef const_iterator ConstIterator;
     380             :     iterator begin();
     381             :     const_iterator begin() const;
     382             :     const_iterator cbegin() const;
     383             :     const_iterator constBegin() const;
     384             :     iterator end();
     385             :     const_iterator end() const;
     386             :     const_iterator cend() const;
     387             :     const_iterator constEnd() const;
     388             : 
     389             :     // stl compatibility
     390             :     typedef const char & const_reference;
     391             :     typedef char & reference;
     392             :     typedef char value_type;
     393             :     void push_back(char c);
     394             :     void push_back(const char *c);
     395             :     void push_back(const QByteArray &a);
     396             :     void push_front(char c);
     397             :     void push_front(const char *c);
     398             :     void push_front(const QByteArray &a);
     399             : 
     400             :     inline int count() const { return d->size; }
     401           0 :     int length() const { return d->size; }
     402             :     bool isNull() const;
     403             : 
     404             :     inline QByteArray(QByteArrayDataPtr dd)
     405             :         : d(static_cast<Data *>(dd.ptr))
     406             :     {
     407             :     }
     408             : 
     409             : private:
     410             :     operator QNoImplicitBoolCast() const;
     411             :     Data *d;
     412             :     void reallocData(uint alloc, Data::AllocationOptions options);
     413             :     void expand(int i);
     414             :     QByteArray nulTerminated() const;
     415             : 
     416             :     friend class QByteRef;
     417             :     friend class QString;
     418             :     friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
     419             : public:
     420             :     typedef Data * DataPtr;
     421             :     inline DataPtr &data_ptr() { return d; }
     422             : };
     423             : 
     424             : Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options)
     425             : 
     426         136 : inline QByteArray::QByteArray(): d(Data::sharedNull()) { }
     427         220 : inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); }
     428         210 : inline int QByteArray::size() const
     429         210 : { return d->size; }
     430             : 
     431             : inline char QByteArray::at(int i) const
     432             : { Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }
     433             : inline char QByteArray::operator[](int i) const
     434             : { Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }
     435             : inline char QByteArray::operator[](uint i) const
     436             : { Q_ASSERT(i < uint(size())); return d->data()[i]; }
     437             : 
     438           0 : inline bool QByteArray::isEmpty() const
     439           0 : { return d->size == 0; }
     440             : #ifndef QT_NO_CAST_FROM_BYTEARRAY
     441             : inline QByteArray::operator const char *() const
     442             : { return d->data(); }
     443           0 : inline QByteArray::operator const void *() const
     444           0 : { return d->data(); }
     445             : #endif
     446          52 : inline char *QByteArray::data()
     447          52 : { detach(); return d->data(); }
     448           4 : inline const char *QByteArray::data() const
     449           4 : { return d->data(); }
     450          61 : inline const char *QByteArray::constData() const
     451          61 : { return d->data(); }
     452          52 : inline void QByteArray::detach()
     453          52 : { if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u, d->detachFlags()); }
     454             : inline bool QByteArray::isDetached() const
     455             : { return !d->ref.isShared(); }
     456          35 : inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
     457          35 : { d->ref.ref(); }
     458             : 
     459             : inline int QByteArray::capacity() const
     460             : { return d->alloc ? d->alloc - 1 : 0; }
     461             : 
     462             : inline void QByteArray::reserve(int asize)
     463             : {
     464             :     if (d->ref.isShared() || uint(asize) + 1u > d->alloc) {
     465             :         reallocData(qMax(uint(size()), uint(asize)) + 1u, d->detachFlags() | Data::CapacityReserved);
     466             :     } else {
     467             :         // cannot set unconditionally, since d could be the shared_null or
     468             :         // otherwise static
     469             :         d->capacityReserved = true;
     470             :     }
     471             : }
     472             : 
     473             : inline void QByteArray::squeeze()
     474             : {
     475             :     if (d->ref.isShared() || uint(d->size) + 1u < d->alloc) {
     476             :         reallocData(uint(d->size) + 1u, d->detachFlags() & ~Data::CapacityReserved);
     477             :     } else {
     478             :         // cannot set unconditionally, since d could be shared_null or
     479             :         // otherwise static.
     480             :         d->capacityReserved = false;
     481             :     }
     482             : }
     483             : 
     484             : class Q_CORE_EXPORT QByteRef {
     485             :     QByteArray &a;
     486             :     int i;
     487             :     inline QByteRef(QByteArray &array, int idx)
     488             :         : a(array),i(idx) {}
     489             :     friend class QByteArray;
     490             : public:
     491             :     inline operator char() const
     492             :         { return i < a.d->size ? a.d->data()[i] : char(0); }
     493             :     inline QByteRef &operator=(char c)
     494             :         { if (i >= a.d->size) a.expand(i); else a.detach();
     495             :           a.d->data()[i] = c;  return *this; }
     496             :     inline QByteRef &operator=(const QByteRef &c)
     497             :         { if (i >= a.d->size) a.expand(i); else a.detach();
     498             :           a.d->data()[i] = c.a.d->data()[c.i];  return *this; }
     499             :     inline bool operator==(char c) const
     500             :     { return a.d->data()[i] == c; }
     501             :     inline bool operator!=(char c) const
     502             :     { return a.d->data()[i] != c; }
     503             :     inline bool operator>(char c) const
     504             :     { return a.d->data()[i] > c; }
     505             :     inline bool operator>=(char c) const
     506             :     { return a.d->data()[i] >= c; }
     507             :     inline bool operator<(char c) const
     508             :     { return a.d->data()[i] < c; }
     509             :     inline bool operator<=(char c) const
     510             :     { return a.d->data()[i] <= c; }
     511             : };
     512             : 
     513             : inline QByteRef QByteArray::operator[](int i)
     514             : { Q_ASSERT(i >= 0); return QByteRef(*this, i); }
     515             : inline QByteRef QByteArray::operator[](uint i)
     516             : { return QByteRef(*this, i); }
     517             : inline QByteArray::iterator QByteArray::begin()
     518             : { detach(); return d->data(); }
     519             : inline QByteArray::const_iterator QByteArray::begin() const
     520             : { return d->data(); }
     521             : inline QByteArray::const_iterator QByteArray::cbegin() const
     522             : { return d->data(); }
     523             : inline QByteArray::const_iterator QByteArray::constBegin() const
     524             : { return d->data(); }
     525             : inline QByteArray::iterator QByteArray::end()
     526             : { detach(); return d->data() + d->size; }
     527             : inline QByteArray::const_iterator QByteArray::end() const
     528             : { return d->data() + d->size; }
     529             : inline QByteArray::const_iterator QByteArray::cend() const
     530             : { return d->data() + d->size; }
     531             : inline QByteArray::const_iterator QByteArray::constEnd() const
     532             : { return d->data() + d->size; }
     533             : inline QByteArray &QByteArray::operator+=(char c)
     534             : { return append(c); }
     535             : inline QByteArray &QByteArray::operator+=(const char *s)
     536             : { return append(s); }
     537             : inline QByteArray &QByteArray::operator+=(const QByteArray &a)
     538             : { return append(a); }
     539             : inline void QByteArray::push_back(char c)
     540             : { append(c); }
     541             : inline void QByteArray::push_back(const char *c)
     542             : { append(c); }
     543             : inline void QByteArray::push_back(const QByteArray &a)
     544             : { append(a); }
     545             : inline void QByteArray::push_front(char c)
     546             : { prepend(c); }
     547             : inline void QByteArray::push_front(const char *c)
     548             : { prepend(c); }
     549             : inline void QByteArray::push_front(const QByteArray &a)
     550             : { prepend(a); }
     551             : inline bool QByteArray::contains(const QByteArray &a) const
     552             : { return indexOf(a) != -1; }
     553             : inline bool QByteArray::contains(char c) const
     554             : { return indexOf(c) != -1; }
     555           6 : inline bool operator==(const QByteArray &a1, const QByteArray &a2)
     556           6 : { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); }
     557             : inline bool operator==(const QByteArray &a1, const char *a2)
     558             : { return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); }
     559             : inline bool operator==(const char *a1, const QByteArray &a2)
     560             : { return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); }
     561             : inline bool operator!=(const QByteArray &a1, const QByteArray &a2)
     562             : { return !(a1==a2); }
     563             : inline bool operator!=(const QByteArray &a1, const char *a2)
     564             : { return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); }
     565             : inline bool operator!=(const char *a1, const QByteArray &a2)
     566             : { return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); }
     567             : inline bool operator<(const QByteArray &a1, const QByteArray &a2)
     568             : { return qstrcmp(a1, a2) < 0; }
     569             :  inline bool operator<(const QByteArray &a1, const char *a2)
     570             : { return qstrcmp(a1, a2) < 0; }
     571             : inline bool operator<(const char *a1, const QByteArray &a2)
     572             : { return qstrcmp(a1, a2) < 0; }
     573             : inline bool operator<=(const QByteArray &a1, const QByteArray &a2)
     574             : { return qstrcmp(a1, a2) <= 0; }
     575             : inline bool operator<=(const QByteArray &a1, const char *a2)
     576             : { return qstrcmp(a1, a2) <= 0; }
     577             : inline bool operator<=(const char *a1, const QByteArray &a2)
     578             : { return qstrcmp(a1, a2) <= 0; }
     579             : inline bool operator>(const QByteArray &a1, const QByteArray &a2)
     580             : { return qstrcmp(a1, a2) > 0; }
     581             : inline bool operator>(const QByteArray &a1, const char *a2)
     582             : { return qstrcmp(a1, a2) > 0; }
     583             : inline bool operator>(const char *a1, const QByteArray &a2)
     584             : { return qstrcmp(a1, a2) > 0; }
     585             : inline bool operator>=(const QByteArray &a1, const QByteArray &a2)
     586             : { return qstrcmp(a1, a2) >= 0; }
     587             : inline bool operator>=(const QByteArray &a1, const char *a2)
     588             : { return qstrcmp(a1, a2) >= 0; }
     589             : inline bool operator>=(const char *a1, const QByteArray &a2)
     590             : { return qstrcmp(a1, a2) >= 0; }
     591             : #if !defined(QT_USE_QSTRINGBUILDER)
     592             : inline const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
     593             : { return QByteArray(a1) += a2; }
     594             : inline const QByteArray operator+(const QByteArray &a1, const char *a2)
     595             : { return QByteArray(a1) += a2; }
     596             : inline const QByteArray operator+(const QByteArray &a1, char a2)
     597             : { return QByteArray(a1) += a2; }
     598             : inline const QByteArray operator+(const char *a1, const QByteArray &a2)
     599             : { return QByteArray(a1) += a2; }
     600             : inline const QByteArray operator+(char a1, const QByteArray &a2)
     601             : { return QByteArray(&a1, 1) += a2; }
     602             : #endif // QT_USE_QSTRINGBUILDER
     603             : inline bool QByteArray::contains(const char *c) const
     604             : { return indexOf(c) != -1; }
     605             : inline QByteArray &QByteArray::replace(char before, const char *c)
     606             : { return replace(&before, 1, c, qstrlen(c)); }
     607             : inline QByteArray &QByteArray::replace(const QByteArray &before, const char *c)
     608             : { return replace(before.constData(), before.size(), c, qstrlen(c)); }
     609             : inline QByteArray &QByteArray::replace(const char *before, const char *after)
     610             : { return replace(before, qstrlen(before), after, qstrlen(after)); }
     611             : 
     612             : inline QByteArray &QByteArray::setNum(short n, int base)
     613             : { return base == 10 ? setNum(qlonglong(n), base) : setNum(qulonglong(ushort(n)), base); }
     614             : inline QByteArray &QByteArray::setNum(ushort n, int base)
     615             : { return setNum(qulonglong(n), base); }
     616             : inline QByteArray &QByteArray::setNum(int n, int base)
     617             : { return base == 10 ? setNum(qlonglong(n), base) : setNum(qulonglong(uint(n)), base); }
     618             : inline QByteArray &QByteArray::setNum(uint n, int base)
     619             : { return setNum(qulonglong(n), base); }
     620             : inline QByteArray &QByteArray::setNum(float n, char f, int prec)
     621             : { return setNum(double(n),f,prec); }
     622             : 
     623             : 
     624             : #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE))
     625             : Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &);
     626             : Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QByteArray &);
     627             : #endif
     628             : 
     629             : #ifndef QT_NO_COMPRESS
     630             : Q_CORE_EXPORT QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel = -1);
     631             : Q_CORE_EXPORT QByteArray qUncompress(const uchar* data, int nbytes);
     632             : inline QByteArray qCompress(const QByteArray& data, int compressionLevel = -1)
     633             : { return qCompress(reinterpret_cast<const uchar *>(data.constData()), data.size(), compressionLevel); }
     634             : inline QByteArray qUncompress(const QByteArray& data)
     635             : { return qUncompress(reinterpret_cast<const uchar*>(data.constData()), data.size()); }
     636             : #endif
     637             : 
     638             : Q_DECLARE_SHARED(QByteArray)
     639             : 
     640             : QT_END_NAMESPACE
     641             : 
     642             : #ifdef QT_USE_QSTRINGBUILDER
     643             : #include <QtCore/qstring.h>
     644             : #endif
     645             : 
     646             : #endif // QBYTEARRAY_H

Generated by: LCOV version 1.11