CopperSpice API
1.9.2
|
Stores a sequence of bytes. More...
Public Methods | |
QByteArray () | |
QByteArray (const char *str, int size=-1) | |
QByteArray (const QByteArray &other) | |
QByteArray (int size, char ch) | |
QByteArray (QByteArray &&other) | |
~QByteArray () | |
QByteArray & | append (char ch) |
QByteArray & | append (const char *str) |
QByteArray & | append (const char *str, int len) |
QByteArray & | append (const QByteArray &value) |
char | at (int i) const |
iterator | begin () |
const_iterator | begin () const |
int | capacity () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
void | chop (int n) |
void | clear () |
const_iterator | constBegin () const |
const char * | constData () const |
const_iterator | constEnd () const |
bool | contains (char ch) const |
bool | contains (const char *str) const |
bool | contains (const QByteArray &value) const |
int | count () const |
int | count (char ch) const |
int | count (const char *str) const |
int | count (const QByteArray &value) const |
const_reverse_iterator | crbegin () const |
const_reverse_iterator | crend () const |
char * | data () |
const char * | data () const |
iterator | end () |
const_iterator | end () const |
bool | endsWith (char ch) const |
bool | endsWith (const char *str) const |
bool | endsWith (const QByteArray &value) const |
QByteArray & | fill (char ch, int size=-1) |
int | indexOf (char ch, int from=0) const |
int | indexOf (const char *str, int from=0) const |
int | indexOf (const QByteArray &value, int from=0) const |
QByteArray & | insert (int i, char ch) |
QByteArray & | insert (int i, const char *str) |
QByteArray & | insert (int i, const char *str, int len) |
QByteArray & | insert (int i, const QByteArray &value) |
bool | isEmpty () const |
bool | isNull () const |
int | lastIndexOf (char ch, int from=-1) const |
int | lastIndexOf (const char *str, int from=-1) const |
int | lastIndexOf (const QByteArray &value, int from=-1) const |
QByteArray | left (int len) const |
QByteArray | leftJustified (int width, char fill= ' ', bool truncate=false) const |
int | length () const |
QByteArray | mid (int pos, int len=-1) const |
QByteArray & | operator+= (char ch) |
QByteArray & | operator+= (const char *str) |
QByteArray & | operator+= (const QByteArray &value) |
QByteArray & | operator= (const char *str) |
QByteArray & | operator= (const QByteArray &other) |
QByteArray & | operator= (QByteArray &&other) |
QByteRef | operator[] (int i) |
char | operator[] (int i) const |
QByteRef | operator[] (uint i) |
char | operator[] (uint i) const |
QByteArray & | prepend (char ch) |
QByteArray & | prepend (const char *str) |
QByteArray & | prepend (const char *str, int len) |
QByteArray & | prepend (const QByteArray &value) |
void | push_back (char ch) |
void | push_back (const char *str) |
void | push_back (const QByteArray &value) |
void | push_front (char ch) |
void | push_front (const char *str) |
void | push_front (const QByteArray &value) |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
QByteArray & | remove (char ch) |
QByteArray & | remove (int pos, int len) |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
QByteArray | repeated (int times) const |
QByteArray & | replace (char before, char after) |
QByteArray & | replace (char before, const char *after) |
QByteArray & | replace (char before, const QByteArray &after) |
QByteArray & | replace (const char *before, const char *after) |
QByteArray & | replace (const char *before, const QByteArray &after) |
QByteArray & | replace (const char *before, int bsize, const char *after, int asize) |
QByteArray & | replace (const QByteArray &before, const char *after) |
QByteArray & | replace (const QByteArray &before, const QByteArray &after) |
QByteArray & | replace (int pos, int len, const char *str) |
QByteArray & | replace (int pos, int len, const char *str, int size) |
QByteArray & | replace (int pos, int len, const QByteArray &value) |
void | reserve (int size) |
void | resize (int size) |
QByteArray | right (int len) const |
QByteArray | rightJustified (int width, char fill= ' ', bool truncate=false) const |
QByteArray & | setNum (double n, char f= 'g', int prec=6) |
QByteArray & | setNum (float n, char f= 'g', int prec=6) |
QByteArray & | setNum (int n, int base=10) |
QByteArray & | setNum (qint64 n, int base=10) |
QByteArray & | setNum (quint64 n, int base=10) |
QByteArray & | setNum (short n, int base=10) |
QByteArray & | setNum (uint n, int base=10) |
QByteArray & | setNum (ushort n, int base=10) |
QByteArray & | setRawData (const char *str, int size) |
QByteArray | simplified () const |
int | size () const |
QList< QByteArray > | split (char sep) const |
void | squeeze () |
bool | startsWith (char ch) const |
bool | startsWith (const char *str) const |
bool | startsWith (const QByteArray &value) const |
void | swap (QByteArray &other) |
QByteArray | toBase64 () const |
CFDataRef | toCFData () const |
double | toDouble (bool *ok=nullptr) const |
float | toFloat (bool *ok=nullptr) const |
QByteArray | toHex () const |
int | toInt (bool *ok=nullptr, int base=10) const |
long | toLong (bool *ok=nullptr, int base=10) const |
qint64 | toLongLong (bool *ok=nullptr, int base=10) const |
QByteArray | toLower () const |
NSData * | toNSData () const |
QByteArray | toPercentEncoding (const QByteArray &exclude=QByteArray (), const QByteArray &include=QByteArray (), char percent= '%') const |
CFDataRef | toRawCFData () const |
NSData * | toRawNSData () const |
short | toShort (bool *ok=nullptr, int base=10) const |
uint | toUInt (bool *ok=nullptr, int base=10) const |
ulong | toULong (bool *ok=nullptr, int base=10) const |
quint64 | toULongLong (bool *ok=nullptr, int base=10) const |
QByteArray | toUpper () const |
ushort | toUShort (bool *ok=nullptr, int base=10) const |
QByteArray | trimmed () const |
void | truncate (int pos) |
Static Public Methods | |
static QByteArray | fromBase64 (const QByteArray &value) |
static QByteArray | fromCFData (CFDataRef data) |
static QByteArray | fromHex (const QByteArray &value) |
static QByteArray | fromNSData (const NSData *data) |
static QByteArray | fromPercentEncoding (const QByteArray &value, char percent= '%') |
static QByteArray | fromRawCFData (CFDataRef data) |
static QByteArray | fromRawData (const char *str, int size) |
static QByteArray | fromRawNSData (const NSData *data) |
static QByteArray | number (double n, char f= 'g', int prec=6) |
static QByteArray | number (int n, int base=10) |
static QByteArray | number (qint64 n, int base=10) |
static QByteArray | number (quint64 n, int base=10) |
static QByteArray | number (uint n, int base=10) |
Friends | |
QByteArray | qUncompress (const uchar *data, int nbytes) |
Related Functions | |
These are not member functions | |
bool | operator!= (const char *a1, const QByteArray &a2) |
bool | operator!= (const QByteArray &a1, const char *a2) |
bool | operator!= (const QByteArray &a1, const QByteArray &a2) |
const QByteArray | operator+ (char a1, const QByteArray &a2) |
const QByteArray | operator+ (const char *a1, const QByteArray &a2) |
const QByteArray | operator+ (const QByteArray &a1, char a2) |
const QByteArray | operator+ (const QByteArray &a1, const char *a2) |
const QByteArray | operator+ (const QByteArray &a1, const QByteArray &a2) |
bool | operator< (const char *a1, const QByteArray &a2) |
bool | operator< (const QByteArray &a1, const char *a2) |
bool | operator< (const QByteArray &a1, const QByteArray &a2) |
QDataStream & | operator<< (QDataStream &stream, const QByteArray &byteArray) |
bool | operator<= (const char *data, const QByteArray &value) |
bool | operator<= (const QByteArray &value, const char *data) |
bool | operator<= (const QByteArray &value1, const QByteArray &value2) |
bool | operator== (const char *ch, const QByteArray &value) |
bool | operator== (const QByteArray &value1, const char *value2) |
bool | operator== (const QByteArray &value1, const QByteArray &value2) |
bool | operator> (const char *ch, const QByteArray &value) |
bool | operator> (const QByteArray &value, const char *ch) |
bool | operator> (const QByteArray &value1, const QByteArray &value2) |
bool | operator>= (const char *ch, const QByteArray &value) |
bool | operator>= (const QByteArray &value, const char *ch) |
bool | operator>= (const QByteArray &value1, const QByteArray &value2) |
QDataStream & | operator>> (QDataStream &stream, QByteArray &byteArray) |
quint16 | qChecksum (const char *data, uint len) |
QByteArray | qCompress (const QByteArray &data, int compressionLevel=-1) |
QByteArray | qCompress (const uchar *data, int nbytes, int compressionLevel=-1) |
int | qstrcmp (const char *str1, const char *str2) |
char * | qstrcpy (char *dst, const char *src) |
char * | qstrdup (const char *src) |
int | qstricmp (const char *str1, const char *str2) |
uint | qstrlen (const char *str) |
int | qstrncmp (const char *str1, const char *str2, uint len) |
char * | qstrncpy (char *dst, const char *src, uint len) |
int | qstrnicmp (const char *str1, const char *str2, uint len) |
uint | qstrnlen (const char *str, uint maxlen) |
QByteArray | qUncompress (const QByteArray &data) |
QByteArray can be used to store both raw data including embedded null characters and 8-bit null terminated strings. Internally a QByteArray will always end with a null terminator. As an alternative, the QString class is preferred for storing string data as 32 bit Unicode code points. QByteArray is the better choice when storing raw binary data.
QByteArray uses 0 based indexes. To access the element at a particular index position call operator[]().
One way to initialize a QByteArray is to pass a const char *
to the constructor. For example, the following code creates a byte array of size 5 containing the data "Hello". Calling the size() method will return 5 even though the array contains an extra '\0' character at the end.
Another way to create a QByteArray is to construct an empty QByteArray, call the resize() method, then initialize the data one byte at a time.
For read only access an alternative syntax is to use at().
To extract multiple bytes at a time use the methods left(), right(), or mid().
A QByteArray can contain null bytes. The size() method always returns the size of the whole array, including embedded null bytes. If you want to obtain the length of the data up to and excluding the first null character, call qstrlen() on the byte array.
After a call to resize() newly allocated bytes have undefined values. To set all the bytes to a particular value, call fill().
To obtain a pointer to the actual character data call data() or constData(). These methods return a pointer to the beginning of the data. The pointer is guaranteed to remain valid until a non-const method is called on the QByteArray. It is also guaranteed that the data ends with a null byte unless the QByteArray was created from a raw data. The null terminator is automatically provided by QByteArray and is not counted in size().
QByteArray provides the following basic methods for modifying the byte data: append(), prepend(), insert(), replace(), and remove().
The replace() and remove() methods first two arguments are the position from which to start erasing and the number of bytes that should be erased.
When you append() data to a non-empty array the array will be reallocated and the new data copied to it. You can avoid this behavior by calling reserve(), which preallocates a certain amount of memory. You can also call capacity() to find out how much memory QByteArray actually allocated. Data appended to an empty array is not copied.
A frequent requirement is to remove whitespace characters from a byte array ('\n', '\t', ' ', etc.). If you want to remove whitespace from both ends of a QByteArray, use trimmed(). If you want to remove whitespace from both ends and replace multiple consecutive whitespaces with a single space character within the byte array, use simplified().
If you want to find all occurrences of a particular character or substring in a QByteArray, use indexOf() or lastIndexOf(). The former searches forward starting from a given index position, the latter searches backward. Both return the index position of the character or substring if found, otherwise they return -1. This loop finds all occurrences of a particular substring.
To check whether a QByteArray contains a particular character or substring, use contains(). If you want to find out how many times a particular character or substring occurs in the byte array, use count(). If you want to replace all occurrences of a particular value with another, use one of the two-parameter replace() overloads.
A QByteArray can be compared using overloaded operators such as operator<(), operator<=(), operator==(), operator>=(), and so on. The comparison is based exclusively on the numeric values of the characters and is very fast, but is not what a human would expect. QString8::localeAwareCompare() is a better choice for sorting user-interface strings.
QByteArray distinguishes between a null byte array and an empty byte array. A null byte array is a byte array that is initialized using QByteArray's default constructor or by passing (const char *)0 to the constructor. An empty byte array is any byte array with size 0. A null byte array is always empty but an empty byte array is not necessarily null.
All methods except isNull() treat null byte arrays the same as empty byte arrays. For example, data() returns a valid pointer to a null character for a null byte array and QByteArray() compares equal to QByteArray(""). You should normally use isEmpty() instead of isNull().
Methods that perform conversions between numeric data types and strings are performed in the C locale regardless of the user's locale settings. Use QString to perform locale-aware conversions between numbers and strings.
In QByteArray the notion of uppercase and lowercase and of which character is greater than or less than another character is locale dependent. This affects methods which support a case insensitive option or that compare or lowercase or uppercase their arguments.
Case insensitive operations and comparisons will only be accurate if both strings contain only ASCII characters.
The following methods and typedefs are unsafe.
Obsolete Method | Replace With |
---|---|
qsnprintf() | Since C variadic functions are not type safe use QTextStream or QStringParser::formatArgs |
qvsnprintf() | Since C variadic functions are not type safe use QTextStream or QStringParser::formatArgs |
The following methods or overloads on QByteArray have been removed since they only work with Latin-1 characters. Replacement syntax is shown for each method.
Obsolete Method | Replace With |
---|---|
QByteArray::append(const QString &str) | data.append(str.toLatin1()) |
QByteArray::insert(int i, const QString &str) | data.insert(i, str.toLatin1()) |
QByteArray::replace(char ch, const QString &after) | data.replace(ch, after.toLatin1()) |
QByteArray::replace(const QString &before, const char *after) | data.replace(before.toLatin1(), after) |
QByteArray::replace(const QString &before, const QByteArray &after) | data.replace(before.toLatin1(), after) |
QByteArray::indexOf(const QString &str, int from) const | data.indexOf(str.toLatin1(), from) |
QByteArray::lastIndexOf(const QString &str, int from) const | data.lastIndexOf(str.toLatin1(), from) |
QByteArray::operator+=(const QString &str) | data += str.toLatin1() |
QByteArray::operator==(const QString &str) const | data == str.toLatin1() |
QByteArray::operator!=(const QString &str) const | data != str.toLatin1() |
QByteArray::operator<(const QString &str) const | data < str.toLatin1() |
QByteArray::operator>(const QString &str) const | data > str.toLatin1() |
QByteArray::operator<=(const QString &str) const | data <= str.toLatin1() |
QByteArray::operator>=(const QString &str) const | data >= str.toLatin1() |
|
inline |
Constructs an empty byte array.
QByteArray::QByteArray | ( | const char * | str, |
int | size = -1 |
||
) |
Constructs a byte array containing the first size bytes of array str. If data is 0 a null byte array is constructed.
QByteArray makes a deep copy of the string data.
QByteArray::QByteArray | ( | int | size, |
char | ch | ||
) |
Constructs a byte array of size with every byte set to character ch.
|
inline |
Copy constructs a new QByteArray from other.
|
inline |
Move constructs a new QByteArray from other.
|
inline |
Destroys the byte array.
QByteArray & QByteArray::append | ( | char | ch | ) |
Appends the character ch to this byte array.
QByteArray & QByteArray::append | ( | const char * | str | ) |
Appends the string str to this byte array.
QByteArray & QByteArray::append | ( | const char * | str, |
int | len | ||
) |
Appends the first len characters of the string str to this byte array and returns a reference to this byte array.
If len is negative then the length of the string will be determined using qstrlen(). If len is zero or str is a null pointer nothing is appended to the byte array. Your code must ensure len is not larger than the length of str.
QByteArray & QByteArray::append | ( | const QByteArray & | value | ) |
Appends the byte array value onto the end of this byte array. Equivalent to calling insert(size(), value).
QByteArray is an implicitly shared class.
|
inline |
Returns the character at index position i in the byte array. The value for i must be a valid index position in the byte array.
|
inline |
Returns an STL style iterator pointing to the first character in the byte array.
|
inline |
This method overloads begin().
|
inline |
Returns the maximum number of bytes that can be stored in the byte array without forcing a reallocation.
The sole purpose of this method is to provide a means of fine tuning QByteArray's memory usage. In general, you will rarely ever need to call this method. If you want to know how many bytes are in the byte array, call size().
|
inline |
|
inline |
void QByteArray::chop | ( | int | n | ) |
Removes n bytes from the end of the byte array. If n is greater than size(), the result is an empty byte array.
void QByteArray::clear | ( | ) |
|
inline |
Returns a const STL style iterator pointing to the first character in the byte array.
|
inline |
Returns a pointer to the data stored in the byte array. The pointer can be used to access the bytes that compose the array. The data is null terminated unless the QByteArray object was created from raw data. The pointer remains valid as long as the byte array is not reallocated or destroyed.
This method is mostly useful to pass a byte array to a method that accepts a const char *
.
A QByteArray can store any byte values including null. Most methods which take char *
arguments assume the data ends at the first null character they encounter.
|
inline |
Returns a const STL style iterator pointing to the imaginary character after the last character in the list.
|
inline |
Returns true if the byte array contains the character ch otherwise returns false.
|
inline |
Returns true if the byte array contains the string str, otherwise returns false.
|
inline |
|
inline |
Equivalent to calling size().
int QByteArray::count | ( | char | ch | ) | const |
Returns the number of occurrences of character ch in the byte array.
int QByteArray::count | ( | const char * | str | ) | const |
Returns the number of (potentially overlapping) occurrences of string str in the byte array.
int QByteArray::count | ( | const QByteArray & | value | ) | const |
Returns the number of (potentially overlapping) occurrences of byte array value in this byte array.
|
inline |
|
inline |
|
inline |
Returns a pointer to the data stored in the byte array. The pointer can be used to access and modify the bytes that compose the array. The data is null terminated so the number of bytes in the returned character string is size() + 1 for the terminator. The pointer remains valid as long as the byte array is not reallocated or destroyed.
|
inline |
This is an overloaded method.
|
inline |
Returns an STL style iterator pointing to the imaginary character after the last character in the byte array.
|
inline |
This method overloads end().
bool QByteArray::endsWith | ( | char | ch | ) | const |
Returns true if this byte array ends with character ch, otherwise returns false.
bool QByteArray::endsWith | ( | const char * | str | ) | const |
Returns true if this byte array ends with string str, otherwise returns false.
bool QByteArray::endsWith | ( | const QByteArray & | value | ) | const |
Returns true if this byte array ends with byte array value, otherwise returns false.
QByteArray & QByteArray::fill | ( | char | ch, |
int | size = -1 |
||
) |
Sets every byte in the byte array to character ch. If size is different from -1 (the default), the byte array is resized to size beforehand.
|
static |
Returns a decoded copy of the Base64 array value. Input is not checked for validity. Invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters. The following algorithm is used to decode Base64-encoded data as defined in RFC 2045.
|
static |
Constructs a new QByteArray containing a copy of the CFData data.
|
static |
Returns a decoded copy of the hex encoded array value. Input is not checked for validity, invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.
|
static |
Constructs a new QByteArray containing a copy of the NSData data.
|
static |
Returns a decoded copy of the URI/URL-style percent-encoded value. The percent parameter allows you to replace the '%'
character for another (for instance, '_' or '=').
|
static |
Constructs a QByteArray that uses the bytes of the CFData data. The data is not copied.
The caller guarantees that the CFData will not be deleted or modified as long as this QByteArray object exists.
|
static |
Constructs a QByteArray that uses the first size bytes of the str array. The data is not copied. The caller guarantees the data will not be deleted or modified as long as this QByteArray and any copies of it exist.
Since QByteArray does not take ownership of the data the destructor will never delete the raw data, even when the last QByteArray referring to data is destroyed. A subsequent attempt to modify the contents of the returned QByteArray or any copy made from it will cause it to create a deep copy of the data array before doing the modification. This ensures that the raw data array itself will never be modified by QByteArray.
The following example of how to read data using a QDataStream on raw data in memory without copying the raw data into a QByteArray.
|
static |
Constructs a QByteArray that uses the bytes of the NSData data. The data is not copied.
The caller guarantees the NSData will not be deleted or modified as long as this QByteArray object exists.
int QByteArray::indexOf | ( | char | ch, |
int | from = 0 |
||
) | const |
Returns the index position of the first occurrence of the character ch in the byte array, searching forward from index position from. Returns -1 if ch could not be found.
int QByteArray::indexOf | ( | const char * | str, |
int | from = 0 |
||
) | const |
Returns the index position of the first occurrence of the string str in the byte array, searching forward from index position from. Returns -1 if data could not be found.
int QByteArray::indexOf | ( | const QByteArray & | value, |
int | from = 0 |
||
) | const |
Returns the index position of the first occurrence of the byte array value in this byte array, searching forward from index position from. Returns -1 if value could not be found.
QByteArray & QByteArray::insert | ( | int | i, |
char | ch | ||
) |
QByteArray & QByteArray::insert | ( | int | i, |
const char * | str | ||
) |
QByteArray & QByteArray::insert | ( | int | i, |
const char * | str, | ||
int | len | ||
) |
QByteArray & QByteArray::insert | ( | int | i, |
const QByteArray & | value | ||
) |
Inserts the byte array value at index position i and returns a reference to this byte array.
|
inline |
Returns true if the byte array has size 0, otherwise returns false.
bool QByteArray::isNull | ( | ) | const |
Returns true if this byte array is null, otherwise returns false.
CopperSpice makes a distinction between null byte arrays and empty byte arrays for historical reasons. For most applications, what matters is whether or not a byte array contains any data, and this can be determined using isEmpty().
int QByteArray::lastIndexOf | ( | char | ch, |
int | from = -1 |
||
) | const |
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from. If from is -1 (the default), the search starts at the last (size() - 1) byte. Returns -1 if ch could not be found.
int QByteArray::lastIndexOf | ( | const char * | str, |
int | from = -1 |
||
) | const |
Returns the index position of the last occurrence of the string str in the byte array, searching backward from index position from. If from is -1 (the default), the search starts at the last (size() - 1) byte. Returns -1 if str could not be found.
int QByteArray::lastIndexOf | ( | const QByteArray & | value, |
int | from = -1 |
||
) | const |
Returns the index position of the last occurrence of the byte array value in this byte array, searching backward from index position from. If from is -1 (the default), the search starts at the last byte. Returns -1 if value could not be found.
QByteArray QByteArray::left | ( | int | len | ) | const |
Returns a byte array that contains the leftmost len bytes of this byte array. The entire byte array is returned if len is greater than size().
QByteArray QByteArray::leftJustified | ( | int | width, |
char | fill = ' ' , |
||
bool | truncate = false |
||
) | const |
Returns a byte array of size width that contains this byte array padded by the fill character. If truncate is false and the size() of the byte array is more than width, then the returned byte array is a copy of this byte array.
If truncate is true and the size() of the byte array is more than width, then any bytes in a copy of the byte array after position width are removed, and the copy is returned.
|
inline |
Equivalent to calling size().
QByteArray QByteArray::mid | ( | int | pos, |
int | len = -1 |
||
) | const |
Returns a byte array containing len bytes from this byte array, starting at position pos.
If len is -1 (the default), or pos + len >= size(), this method returns a byte array containing all bytes starting at position pos until the end of the byte array.
|
static |
Returns a byte array which contains the printed value of n, using the specified format f with precision prec. The value for n is formatted according to the f format specified, which is g
by default, and can be any of the following.
Format | Meaning |
---|---|
e | format as [-]9.9e[+|-]999 |
E | format as [-]9.9E[+|-]999 |
f | format as [-]9.9 |
g | use e or f format, whichever is the most concise |
G | use E or f format, whichever is the most concise |
With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).
|
static |
Returns a byte array containing the string equivalent of the number n to base (10 by default). The base can be any value between 2 and 36.
|
static |
This is an overloaded method.
|
static |
This is an overloaded method.
|
static |
This is an overloaded method.
|
inline |
Appends the character ch onto the end of this byte array and returns a reference to this byte array.
|
inline |
Appends the string>/i> onto the end of this byte array and returns a reference to this byte array.
|
inline |
Appends the byte array value onto the end of this byte array and returns a reference to this byte array.
QByteArray is an implicitly shared class.
QByteArray & QByteArray::operator= | ( | const char * | str | ) |
Assigns str to this byte array and returns a reference to this object.
QByteArray & QByteArray::operator= | ( | const QByteArray & | other | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
|
inline |
Returns a reference to the data at index position i. If an assignment is made beyond the end of the byte array, the array is extended with resize() before the assignment takes place.
The return value is of type QByteRef, a helper class for QByteArray. When you get an object of type QByteRef, you can use it as if it were a char &. If you assign to it, the assignment will apply to the character in the QByteArray from which you got the reference.
|
inline |
Equivalent to calling at(i).
|
inline |
This is an overloaded method.
|
inline |
This is an overloaded method.
QByteArray & QByteArray::prepend | ( | char | ch | ) |
Prepends the character ch to this byte array.
QByteArray & QByteArray::prepend | ( | const char * | str | ) |
Prepends the string str to this byte array.
QByteArray & QByteArray::prepend | ( | const char * | str, |
int | len | ||
) |
Prepends len bytes of the string str to this byte array.
QByteArray & QByteArray::prepend | ( | const QByteArray & | value | ) |
Prepends the byte array value to this byte array and returns a reference to this byte array. Equivalent to calling insert(0, value).
QByteArray is an implicitly shared class.
|
inline |
Equivalent to calling append(ch).
|
inline |
Equivalent to calling append(str).
|
inline |
Equivalent to calling append(value).
|
inline |
Equivalent to calling prepend(ch).
|
inline |
Equivalent to calling prepend(str).
|
inline |
Equivalent to calling prepend(value).
|
inline |
This is an overloaded method.
|
inline |
QByteArray & QByteArray::remove | ( | char | ch | ) |
Removes all instances of the character ch from the current array.
QByteArray & QByteArray::remove | ( | int | pos, |
int | len | ||
) |
Removes len bytes from the array, starting at index position pos, returns a reference to the array.
If pos is out of range, nothing happens. If pos is valid, but pos + len is larger than the size of the array, the array is truncated at position pos.
|
inline |
|
inline |
This is an overloaded method.
QByteArray QByteArray::repeated | ( | int | times | ) | const |
Returns a copy of this byte array repeated the specified number of times. If times is less than 1, an empty byte array is returned.
QByteArray & QByteArray::replace | ( | char | before, |
char | after | ||
) |
Replaces every occurrence of the character before with the character after.
|
inline |
Replaces every occurrence of the character before with the string after.
QByteArray & QByteArray::replace | ( | char | before, |
const QByteArray & | after | ||
) |
Replaces every occurrence of the character before with the byte array after.
|
inline |
Replaces every occurrence of the string before with the string after.
QByteArray & QByteArray::replace | ( | const char * | before, |
const QByteArray & | after | ||
) |
Replaces every occurrence of the string before with the byte array after.
QByteArray & QByteArray::replace | ( | const char * | before, |
int | bsize, | ||
const char * | after, | ||
int | asize | ||
) |
Replaces every occurrence of the string before with the string after. Since the sizes of the strings are given by bsize and asize, they may contain null characters and do not need to be null terminated.
|
inline |
Replaces every occurrence of the byte array before with the string after.
QByteArray & QByteArray::replace | ( | const QByteArray & | before, |
const QByteArray & | after | ||
) |
Replaces every occurrence of the byte array before with the byte array after.
QByteArray & QByteArray::replace | ( | int | pos, |
int | len, | ||
const char * | str | ||
) |
Replaces len bytes from index position pos with the null terminated string str.
QByteArray & QByteArray::replace | ( | int | pos, |
int | len, | ||
const char * | str, | ||
int | size | ||
) |
Replaces len bytes from index position pos with size bytes from the string str. The value for str is allowed to contain null characters.
QByteArray & QByteArray::replace | ( | int | pos, |
int | len, | ||
const QByteArray & | value | ||
) |
Replaces len bytes from index position pos with the byte array value. Returns a reference to this byte array.
|
inline |
Attempts to allocate memory for at least size bytes. If you know in advance how large the byte array will be, you can call this method, and if you call resize() often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QByteArray will be a bit slower.
The sole purpose of this method is to provide a means of fine tuning QByteArray's memory usage. In general, you will rarely ever need to call this method. If you want to change the size of the byte array, call resize().
void QByteArray::resize | ( | int | size | ) |
Sets the size of the byte array to size bytes.
If size is greater than the current size, the byte array is extended to make it size bytes with the extra bytes added to the end. The new bytes are uninitialized. If size is less than the current size, bytes are removed from the end.
QByteArray QByteArray::right | ( | int | len | ) | const |
Returns a byte array that contains the rightmost len bytes of this byte array. The entire byte array is returned if len is greater than size().
QByteArray QByteArray::rightJustified | ( | int | width, |
char | fill = ' ' , |
||
bool | truncate = false |
||
) | const |
Returns a byte array of size width that contains the fill character followed by this byte array. If truncate is false and the size of the byte array is more than width, then the returned byte array is a copy of this byte array.
If truncate is true and the size of the byte array is more than width, then the resulting byte array is truncated at position width.
QByteArray & QByteArray::setNum | ( | double | n, |
char | f = 'g' , |
||
int | prec = 6 |
||
) |
Sets the byte array to the printed value of n, formatted in format f with precision prec, and returns a reference to the byte array.
The format f can be any of the following:
Format | Meaning |
---|---|
e | format as [-]9.9e[+|-]999 |
E | format as [-]9.9E[+|-]999 |
f | format as [-]9.9 |
g | use e or f format, whichever is the most concise |
G | use E or f format, whichever is the most concise |
With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).
|
inline |
Sets the byte array to the printed value of n, formatted in format f with precision prec, and returns a reference to the byte array.
|
inline |
Sets the byte array to the printed value of n in base (10 by default) and returns a reference to the byte array. The base can be any value between 2 and 36.
QByteArray & QByteArray::setNum | ( | qint64 | n, |
int | base = 10 |
||
) |
This is an overloaded method.
QByteArray & QByteArray::setNum | ( | quint64 | n, |
int | base = 10 |
||
) |
This is an overloaded method.
|
inline |
This is an overloaded method.
|
inline |
This is an overloaded method.
|
inline |
This is an overloaded method.
QByteArray & QByteArray::setRawData | ( | const char * | str, |
int | size | ||
) |
Resets the QByteArray to use the first size bytes of the data array.
The bytes are not copied. Users must guarantee the data will not be deleted or modified as long as this QByteArray and any copies of it exist. This method can be used instead of fromRawData() to re-use existing QByteArray objects to save memory re-allocations.
QByteArray QByteArray::simplified | ( | ) | const |
Returns a byte array that has whitespace removed from the start and the end, and which has each sequence of internal whitespace replaced with a single space.
Whitespace means any character for which the standard C++ isspace() method returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.
|
inline |
Returns the number of bytes in this byte array.
The last byte in the byte array is at position size() - 1. QByteArray ensures the byte at position size() is always a null character. You can use the return value of data() and constData() as arguments to methods which expect null terminated strings. If the QByteArray object was created from raw data which did not include the trailing null termination, then QByteArray does not add it automatically.
QList< QByteArray > QByteArray::split | ( | char | sep | ) | const |
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays. If sep does not match anywhere in the byte array, split() returns a single-element list containing this byte array.
|
inline |
Releases any memory not required to store the array's data.
The sole purpose of this method is to provide a means of fine tuning QByteArray's memory usage. In general, you will rarely ever need to call this method.
bool QByteArray::startsWith | ( | char | ch | ) | const |
Returns true if this byte array starts with character ch, otherwise returns false.
bool QByteArray::startsWith | ( | const char * | str | ) | const |
Returns true if this byte array starts with string str, otherwise returns false.
bool QByteArray::startsWith | ( | const QByteArray & | value | ) | const |
Returns true if this byte array starts with byte array value, otherwise returns false.
|
inline |
Swaps other with this object. This operation is very fast and never fails.
QByteArray QByteArray::toBase64 | ( | ) | const |
Returns a copy of the byte array, encoded as Base64.
The algorithm used to encode Base64-encoded data is defined in RFC 2045.
CFDataRef QByteArray::toCFData | ( | ) | const |
Creates a CFData from a QByteArray. The caller owns the CFData object and is responsible for releasing it.
double QByteArray::toDouble | ( | bool * | ok = nullptr | ) | const |
Returns the byte array converted to a double value. Returns 0.0 if the conversion fails. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
float QByteArray::toFloat | ( | bool * | ok = nullptr | ) | const |
Returns the byte array converted to a float value. Returns 0.0 if the conversion fails. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QByteArray QByteArray::toHex | ( | ) | const |
Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.
int QByteArray::toInt | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to an int using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
long QByteArray::toLong | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to a long int using base, which is 10 by default and must be between 2 and 36, or 0. The method returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
qint64 QByteArray::toLongLong | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to a long long using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QByteArray QByteArray::toLower | ( | ) | const |
Returns a lowercase copy of the byte array. The byte array is interpreted as a Latin-1 encoded string.
NSData * QByteArray::toNSData | ( | ) | const |
Creates a NSData from a QByteArray. The NSData object is autoreleased.
QByteArray QByteArray::toPercentEncoding | ( | const QByteArray & | exclude = QByteArray() , |
const QByteArray & | include = QByteArray() , |
||
char | percent = '%' |
||
) | const |
Returns a URL style "percent encoded" copy of the current QByteArray. The default character for percent is a percent sign. This method will encode every character except those listed below.
To prevent a character from being "percent encoded" a QByteArray is provided in exclude. To force characters to be "percent encoded" provide these as a QByteArray in include.
CFDataRef QByteArray::toRawCFData | ( | ) | const |
Constructs a CFData that uses the bytes of the QByteArray. The data is not copied.
The caller guarantees that the QByteArray will not be deleted or modified as long as this CFData object exists.
NSData * QByteArray::toRawNSData | ( | ) | const |
Constructs a NSData that uses the bytes of the QByteArray. The data is not copied.
The caller guarantees the QByteArray will not be deleted or modified as long as this NSData object exists.
short QByteArray::toShort | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to a short using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr then the status of the conversion is placed in ok. The value is false to indicate the conversion failed, otherwise ok is set to true.
uint QByteArray::toUInt | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to an unsigned int using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0s" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
ulong QByteArray::toULong | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to an unsigned long int using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
quint64 QByteArray::toULongLong | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to an unsigned long long using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QByteArray QByteArray::toUpper | ( | ) | const |
Returns an uppercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.
ushort QByteArray::toUShort | ( | bool * | ok = nullptr , |
int | base = 10 |
||
) | const |
Returns the byte array converted to an unsigned short using base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If base is 0 it is determined using the following rules: (1) If the byte array begins with "0x" it is assumed to be hexadecimal (2) If it begins with "0" it is assumed to be octal, (3) otherwise it is assumed to be decimal.
If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QByteArray QByteArray::trimmed | ( | ) | const |
Returns a byte array that has whitespace removed from the start and the end.
Whitespace means any character for which the standard C++ isspace() method returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.
Unlike simplified(), trimmed() leaves internal whitespace alone.
void QByteArray::truncate | ( | int | pos | ) |
Truncates the byte array at index position pos. If pos is beyond the end of the array, nothing happens.
|
related |
Returns true if string a1 is not equal to byte array a2, otherwise returns false.
|
related |
Returns true if byte array a1 is not equal to string a2, otherwise returns false.
|
related |
Returns true if byte array a1 is not equal to byte array a2, otherwise returns false.
|
related |
Returns a byte array that is the result of concatenating character a1 and byte array a2.
|
related |
Returns a byte array that is the result of concatenating string a1 and byte array a2.
|
related |
Returns a byte array that is the result of concatenating byte array a1 and character a2.
|
related |
Returns a byte array that is the result of concatenating byte array a1 and string a2.
|
related |
Returns a byte array that is the result of concatenating byte array a1 and byte array a2.
|
related |
Returns true if string a1 is lexically less than byte array a2, otherwise returns false.
|
related |
Returns true if byte array a1 is lexically less than string a2, otherwise returns false.
|
related |
Returns true if byte array a1 is lexically less than byte array a2, otherwise returns false.
|
related |
Writes the given byteArray to the stream. Returns a reference to the stream.
Refer to Serializing Data Types for additional information.
|
related |
Returns true if string data is lexically less than or equal to byte array value, otherwise returns false.
|
related |
Returns true if byte array value1 is lexically less than or equal to string data, otherwise returns false.
|
related |
Returns true if byte array value1 is lexically less than or equal to byte array value2, otherwise returns false.
|
related |
Returns true if string ch is equal to byte array value, otherwise returns false.
|
related |
Returns true if byte array value1 is equal to string value2, otherwise returns false.
|
related |
Returns true if byte array value1 is equal to byte array value2, otherwise returns false.
|
related |
Returns true if string ch is lexically greater than byte array value, otherwise returns false.
|
related |
Returns true if byte array value is lexically greater than string ch, otherwise returns false.
|
related |
Returns true if byte array value1 is lexically greater than byte array value2, otherwise returns false.
|
related |
Returns true if string ch is lexically greater than or equal to byte array value, otherwise returns false.
|
related |
Returns true if byte array value is lexically greater than or equal to string ch, otherwise returns false.
|
related |
Returns true if byte array value1 is lexically greater than or equal to byte array value2, otherwise returns false.
|
related |
Reads from the stream into the given byteArray. Returns a reference to the stream.
Refer to Serializing Data Types for additional information.
Returns the CRC-16 checksum of the first len bytes of data. The checksum is independent of the byte order (endianness).
|
related |
Compresses the data byte array and returns the compressed data in a new byte array.
The compressionLevel parameter specifies how much compression should be used. Valid values are between 0 and 9, with 9 corresponding to the greatest compression at the cost of using a slower algorithm. Smaller values then 9 provide successively less compression at slightly faster speeds. The value 0 corresponds to no compression at all. The default value is -1, which specifies zlib's default compression.
|
related |
Compresses the first nbytes of data and returns the compressed result in a new byte array. The compressionLevel parameter specifies how much compression should be used.
|
related |
Compares str1 and str2. Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2, or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both nullptr.
Special case 2: Returns an arbitrary non-zero value if str1 is nullptr or str2 is nullptr (but not both).
|
related |
Copies all the characters up to and including the null terminator from src into dst and returns a pointer to dst. If src is a nullptr, this function returns a nullptr.
This function assumes dst is large enough to hold the contents of src.
|
related |
Returns a duplicate string. Allocates space for a copy of src, copies it, and returns a pointer to the copy. If src is a nullptr, this function returns a nullptr.
Ownership is passed to the caller, so the returned string must be deleted using delete[]
.
|
related |
Compares str1 and str2 ignoring the case of the characters. The encoding of the strings is assumed to be Latin-1.
Returns a negative value if str1 is less than <str2, 0 if str1 is equal to str2, or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both nullptr.
Special case 2: Returns a random non-zero value if str1 is nullptr or str2 is nullptr (but not both).
|
related |
Returns the number of characters which precede the terminating null character or 0 if str is a nullptr.
|
related |
Compares at most len bytes of str1 and str2. Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2, or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both nullptr.
Special case 2: Returns a random non-zero value if str1 is nullptr or str2 is nullptr (but not both).
|
related |
Copies at most len bytes from src (stopping at len or the null terminator, whichever comes first) into dst and returns a pointer to dst. Guarantees that dst is null terminated. If src is a nullptr, this function returns a nullptr.
This function assumes that dst is at least len characters long.
|
related |
Compares at most len bytes of str1 and str2 ignoring the case of the characters. The encoding of the strings is assumed to be Latin-1. Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2, or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both nullptr.
Special case 2: Returns a random non-zero value if str1 is nullptr or str2 is nullptr (but not both).
Returns the number of characters which precede the null terminator but not more than maxlen. If str is a nullptr this method returns 0.
|
related |
Uncompresses the data byte array and returns a new byte array with the uncompressed data. Returns an empty QByteArray if the input data was corrupt.
|
friend |
Uncompresses the first nbytes of data and returns a new byte array with the uncompressed data.