45 #include <QtCore/qatomic.h> 46 #include <QtCore/qnamespace.h> 52 #error qbytearray.h must be included before any header file that defines truncate 55 #if defined(Q_CC_GNU) && (__GNUC__ == 4 && __GNUC_MINOR__ == 0) 57 # ifdef QT_USE_FAST_OPERATOR_PLUS 58 # undef QT_USE_FAST_OPERATOR_PLUS 60 # ifdef QT_USE_QSTRINGBUILDER 61 # undef QT_USE_QSTRINGBUILDER 80 {
return str ?
uint(strlen(str)) : 0; }
86 while (length < maxlen && *str++)
99 {
return -
qstrcmp(str2, str1); }
103 return (str1 && str2) ? strncmp(str1, str2, len)
104 : (str1 ? 1 : (str2 ? -1 : 0));
114 inline QT3_SUPPORT
void *qmemmove(
void *dst,
const void *src,
uint len)
115 {
return memmove(dst, src, len); }
116 inline QT3_SUPPORT
uint cstrlen(
const char *str)
117 {
return uint(strlen(str)); }
118 inline QT3_SUPPORT
char *cstrcpy(
char *dst,
const char *src)
120 inline QT3_SUPPORT
int cstrcmp(
const char *str1,
const char *str2)
121 {
return strcmp(str1,str2); }
122 inline QT3_SUPPORT
int cstrncmp(
const char *str1,
const char *str2,
uint len)
123 {
return strncmp(str1,str2,len); }
133 template <
typename T>
class QList;
159 #ifdef Q_COMPILER_RVALUE_REFS 161 {
qSwap(
d, other.d);
return *
this; }
166 inline int size()
const;
168 void resize(
int size);
172 int capacity()
const;
173 void reserve(
int size);
176 #ifndef QT_NO_CAST_FROM_BYTEARRAY 177 operator const char *()
const;
178 operator const void *()
const;
181 const char *
data()
const;
182 inline const char *constData()
const;
183 inline void detach();
184 bool isDetached()
const;
188 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE 189 const char at(
int i)
const;
190 const char operator[](
int i)
const;
191 const char operator[](
uint i)
const;
193 char at(
int i)
const;
194 char operator[](
int i)
const;
195 char operator[](
uint i)
const;
200 int indexOf(
char c,
int from = 0)
const;
201 int indexOf(
const char *c,
int from = 0)
const;
202 int indexOf(
const QByteArray &
a,
int from = 0)
const;
203 int lastIndexOf(
char c,
int from = -1)
const;
204 int lastIndexOf(
const char *c,
int from = -1)
const;
205 int lastIndexOf(
const QByteArray &a,
int from = -1)
const;
207 QBool contains(
char c)
const;
208 QBool contains(
const char *a)
const;
210 int count(
char c)
const;
211 int count(
const char *a)
const;
219 bool startsWith(
char c)
const;
220 bool startsWith(
const char *c)
const;
223 bool endsWith(
char c)
const;
224 bool endsWith(
const char *c)
const;
226 void truncate(
int pos);
234 QByteArray leftJustified(
int width,
char fill =
' ',
bool truncate =
false)
const;
235 QByteArray rightJustified(
int width,
char fill =
' ',
bool truncate =
false)
const;
238 inline QT3_SUPPORT
QByteArray leftJustify(
uint width,
char aFill =
' ',
bool aTruncate =
false)
const 239 {
return leftJustified(
int(width), aFill, aTruncate); }
240 inline QT3_SUPPORT
QByteArray rightJustify(
uint width,
char aFill =
' ',
bool aTruncate =
false)
const 241 {
return rightJustified(
int(width), aFill, aTruncate); }
254 QByteArray &insert(
int i,
const char *s,
int len);
257 QByteArray &replace(
int index,
int len,
const char *s);
258 QByteArray &replace(
int index,
int len,
const char *s,
int alen);
260 QByteArray &replace(
char before,
const char *after);
262 QByteArray &replace(
const char *before,
const char *after);
263 QByteArray &replace(
const char *before,
int bsize,
const char *after,
int asize);
276 #ifndef QT_NO_CAST_TO_ASCII 287 #ifndef QT_NO_CAST_FROM_ASCII 296 short toShort(
bool *ok = 0,
int base = 10)
const;
297 ushort toUShort(
bool *ok = 0,
int base = 10)
const;
298 int toInt(
bool *ok = 0,
int base = 10)
const;
299 uint toUInt(
bool *ok = 0,
int base = 10)
const;
300 long toLong(
bool *ok = 0,
int base = 10)
const;
301 ulong toULong(
bool *ok = 0,
int base = 10)
const;
304 float toFloat(
bool *ok = 0)
const;
305 double toDouble(
bool *ok = 0)
const;
310 char percent =
'%')
const;
318 QByteArray &setNum(
float,
char f =
'g',
int prec = 6);
319 QByteArray &setNum(
double,
char f =
'g',
int prec = 6);
326 static QByteArray number(
double,
char f =
'g',
int prec = 6);
327 static QByteArray fromRawData(
const char *,
int size);
338 const_iterator begin()
const;
339 const_iterator constBegin()
const;
341 const_iterator
end()
const;
342 const_iterator constEnd()
const;
348 void push_back(
char c);
349 void push_back(
const char *c);
351 void push_front(
char c);
352 void push_front(
const char *c);
355 inline int count()
const {
return d->size; }
362 inline QT3_SUPPORT QByteArray& duplicate(
const QByteArray& a) { *
this =
a;
return *
this; }
363 inline QT3_SUPPORT QByteArray& duplicate(
const char *a,
uint n)
364 { *
this = QByteArray(a, n);
return *
this; }
365 inline QT3_SUPPORT
void resetRawData(
const char *,
uint) {
clear(); }
366 inline QT3_SUPPORT QByteArray lower()
const {
return toLower(); }
367 inline QT3_SUPPORT QByteArray upper()
const {
return toUpper(); }
368 inline QT3_SUPPORT QByteArray stripWhiteSpace()
const {
return trimmed(); }
369 inline QT3_SUPPORT QByteArray simplifyWhiteSpace()
const {
return simplified(); }
370 inline QT3_SUPPORT
int find(
char c,
int from = 0)
const {
return indexOf(c, from); }
371 inline QT3_SUPPORT
int find(
const char *c,
int from = 0)
const {
return indexOf(c, from); }
372 inline QT3_SUPPORT
int find(
const QByteArray &ba,
int from = 0)
const {
return indexOf(ba, from); }
373 inline QT3_SUPPORT
int findRev(
char c,
int from = -1)
const {
return lastIndexOf(c, from); }
374 inline QT3_SUPPORT
int findRev(
const char *c,
int from = -1)
const {
return lastIndexOf(c, from); }
375 inline QT3_SUPPORT
int findRev(
const QByteArray &ba,
int from = -1)
const {
return lastIndexOf(ba, from); }
376 #ifndef QT_NO_CAST_TO_ASCII 377 QT3_SUPPORT
int find(
const QString &s,
int from = 0)
const;
378 QT3_SUPPORT
int findRev(
const QString &s,
int from = -1)
const;
388 void realloc(
int alloc);
390 QByteArray nulTerminated()
const;
405 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE 422 {
return d->
size == 0; }
423 #ifndef QT_NO_CAST_FROM_BYTEARRAY 424 inline QByteArray::operator
const char *()
const 426 inline QByteArray::operator
const void *()
const 438 {
return d->
ref == 1; }
443 {
d->
ref.
ref();
if (aSize > 0)
fill(
'\0', aSize); }
462 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE 463 inline operator const char()
const 464 {
return i < a.
d->
size ? a.
d->
data[i] : char(0); }
466 inline operator char()
const 467 {
return i < a.
d->
size ? a.
d->
data[i] : char(0); }
471 a.
d->
data[i] =
c;
return *
this; }
476 {
return a.
d->
data[i] ==
c; }
478 {
return a.
d->
data[i] !=
c; }
480 {
return a.
d->
data[i] >
c; }
482 {
return a.
d->
data[i] >=
c; }
484 {
return a.
d->
data[i] <
c; }
486 {
return a.
d->
data[i] <=
c; }
534 {
return !(a1==a2); }
540 {
return qstrcmp(a1, a2) < 0; }
542 {
return qstrcmp(a1, a2) < 0; }
544 {
return qstrcmp(a1, a2) < 0; }
546 {
return qstrcmp(a1, a2) <= 0; }
548 {
return qstrcmp(a1, a2) <= 0; }
550 {
return qstrcmp(a1, a2) <= 0; }
552 {
return qstrcmp(a1, a2) > 0; }
554 {
return qstrcmp(a1, a2) > 0; }
556 {
return qstrcmp(a1, a2) > 0; }
558 {
return qstrcmp(a1, a2) >= 0; }
560 {
return qstrcmp(a1, a2) >= 0; }
562 {
return qstrcmp(a1, a2) >= 0; }
563 #if !defined(QT_USE_QSTRINGBUILDER) 574 #endif // QT_USE_QSTRINGBUILDER 593 {
return setNum(
double(n),f,prec); }
596 #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) 601 #ifndef QT_NO_COMPRESS 617 #ifdef QT_USE_QSTRINGBUILDER 618 #include <QtCore/qstring.h> 621 #endif // QBYTEARRAY_H #define QT_ASCII_CAST_WARN
bool operator>=(char c) const
bool operator<(char c) const
int qstrncmp(const char *str1, const char *str2, uint len)
QByteArray & fill(char c, int size=-1)
Sets every byte in the byte array to character ch.
#define QT_END_NAMESPACE
This macro expands to.
QByteRef & operator=(char c)
char * data()
Returns a pointer to the data stored in the byte array.
void swap(QByteArray &other)
Swaps byte array other with this byte array.
QT_ASCII_CAST_WARN bool operator==(const QString &s2) const
Returns true if this byte array is equal to string str; otherwise returns false.
Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes)
bool operator>(const QByteArray &a1, const QByteArray &a2)
const char * const_iterator
QByteArray & append(char c)
Appends the character ch to this byte array.
bool operator!=(char c) const
const_iterator constBegin() const
char operator[](int i) const
Same as at(i).
Q_CORE_EXPORT void qFree(void *ptr)
#define at(className, varName)
The QByteArray class provides an array of bytes.
static void clear(QVariant::Private *d)
QByteArray()
Constructs an empty byte array.
bool operator<=(char c) const
void squeeze()
Releases any memory not required to store the array's data.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count() const
Same as size().
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
The QString class provides a Unicode character string.
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
uint qstrnlen(const char *str, uint maxlen)
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Returns a byte array that is the result of concatenating byte array a1 and byte array a2...
bool operator<=(const QByteArray &a1, const QByteArray &a2)
#define Q_DECLARE_SHARED(TYPE)
char * qstrcpy(char *dst, const char *src)
Copies all the characters up to and including the '\0' from src into dst and returns a pointer to dst...
static char toHex(quint8 c)
bool operator==(const QByteArray &a1, const QByteArray &a2)
QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const
Returns true if this byte array is greater than or equal to string str; otherwise returns false...
quint16 qChecksum(const char *data, uint len)
Returns the CRC-16 checksum of the first len bytes of data.
QByteArray(Data *dd, int, int)
#define QT_BEGIN_NAMESPACE
This macro expands to.
~QByteArray()
Destroys the byte array.
static bool isEmpty(const char *str)
QByteRef(QByteArray &array, int idx)
QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const
Returns true if this byte array is not equal to string str; otherwise returns false.
bool operator>(char c) const
static int toInt(const QByteArray &str)
void push_back(char c)
Same as append(ch).
static const char * data(const QByteArray &arr)
QByteArray qCompress(const QByteArray &data, int compressionLevel)
Compresses the data byte array and returns the compressed data in a new byte array.
static void split(QT_FT_Vector *b)
int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
A portable vsnprintf() function.
int qstrnicmp(const char *str1, const char *str2, uint len)
A safe strnicmp() function.
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int qstricmp(const char *str1, const char *str2)
A safe stricmp() function.
const char & const_reference
QDataStream & operator<<(QDataStream &out, const QByteArray &ba)
Writes byte array ba to the stream out and returns a reference to the stream.
QT_ASCII_CAST_WARN bool operator>(const QString &s2) const
Returns true if this byte array is lexically greater than string str; otherwise returns false...
bool isSharedWith(const QByteArray &other) const
void qSwap(T &value1, T &value2)
QByteRef & operator=(const QByteRef &c)
bool operator!=(const QByteArray &a1, const QByteArray &a2)
int length() const
Same as size().
const char * constData() const
Returns a pointer to the data stored in the byte array.
const_iterator ConstIterator
const_iterator constEnd() const
QString trimmed(QString source)
uint qstrlen(const char *str)
bool operator>=(const QByteArray &a1, const QByteArray &a2)
static uchar fromHex(const uchar c, const uchar c2)
QByteArray & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const
Returns true if this byte array is lexically less than or equal to string str; otherwise returns fals...
int qsnprintf(char *str, size_t n, const char *fmt,...)
A portable snprintf() function, calls qvsnprintf.
Q_DECLARE_TYPEINFO(QByteArray, Q_MOVABLE_TYPE)
int size() const
Returns the number of bytes in this byte array.
QByteArray & operator+=(char c)
Appends the character ch onto the end of this byte array and returns a reference to this byte array...
bool operator==(char c) const
bool operator<(const QByteArray &a1, const QByteArray &a2)
int capacity() const
Returns the maximum number of bytes that can be stored in the byte array without forcing a reallocati...
char * qstrdup(const char *src)
Returns a duplicate string.
static qreal toDouble(const QChar *&str)
QDataStream & operator>>(QDataStream &in, QByteArray &ba)
Reads a byte array into ba from the stream in and returns a reference to the stream.
QByteArray & replace(int index, int len, const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
The QDataStream class provides serialization of binary data to a QIODevice.
timeval & operator+=(timeval &t1, const timeval &t2)
char at(int i) const
Returns the character at index position i in the byte array.
void reserve(int size)
Attempts to allocate memory for at least size bytes.
static const KeyPair *const end
char * qstrncpy(char *dst, const char *src, uint len)
A safe strncpy() function.
QT_ASCII_CAST_WARN bool operator<(const QString &s2) const
Returns true if this byte array is lexically less than string str; otherwise returns false...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void push_front(char c)
Same as prepend(ch).
static bool isNull(const QVariant::Private *d)
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
The QList class is a template class that provides lists.
friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes)
Uncompresses the first nbytes of data and returns a new byte array with the uncompressed data...