8#include <QtCore/qrefcount.h>
9#include <QtCore/qnamespace.h>
10#include <QtCore/qarraydata.h>
11#include <QtCore/qarraydatapointer.h>
12#include <QtCore/qcontainerfwd.h>
13#include <QtCore/qbytearrayalgorithms.h>
14#include <QtCore/qbytearrayview.h>
23#ifndef QT5_NULL_STRINGS
25#define QT5_NULL_STRINGS 1
29#error qbytearray.h must be included before any header file that defines truncate
32#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
37#if defined(Q_OS_WASM) || defined(Q_QDOC)
52# define QByteArrayLiteral(str) \
53 (QByteArray(QByteArrayData(nullptr, const_cast<char *>(str), sizeof(str) - 1))) \
64 static const char _empty;
66 friend class ::tst_QByteArray;
68 template <
typename InputIterator>
74 Base64UrlEncoding = 1,
76 KeepTrailingEquals = 0,
77 OmitTrailingEquals = 2,
79 IgnoreBase64DecodingErrors = 0,
80 AbortOnBase64DecodingErrors = 4,
102 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(
QByteArray)
114 inline void squeeze();
116#ifndef QT_NO_CAST_FROM_BYTEARRAY
117 inline operator const char *()
const;
118 inline operator const void *()
const;
121 inline const char *
data() const noexcept;
122 const
char *constData() const noexcept {
return data(); }
123 inline void detach();
124 inline bool isDetached()
const;
131 [[nodiscard]]
inline char &operator[](
qsizetype i);
132 [[nodiscard]]
char front()
const {
return at(0); }
133 [[nodiscard]]
inline char &front();
135 [[nodiscard]]
inline char &back();
178 bool isUpper()
const;
179 bool isLower()
const;
191 {
return toLower_helper(*
this); }
193 {
return toLower_helper(*
this); }
195 {
return toUpper_helper(*
this); }
197 {
return toUpper_helper(*
this); }
199 {
return trimmed_helper(*
this); }
201 {
return trimmed_helper(*
this); }
203 {
return simplified_helper(*
this); }
205 {
return simplified_helper(*
this); }
243 template <
typename InputIterator, if_input_iterator<InputIterator> = true>
247 d.data()[
d.size] =
'\0';
268 template <
typename Predicate>
271 removeIf_helper(pred);
298#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
313 {
return !(
a1==
a2); }
358 short toShort(
bool *
ok =
nullptr,
int base = 10)
const;
359 ushort toUShort(
bool *
ok =
nullptr,
int base = 10)
const;
360 int toInt(
bool *
ok =
nullptr,
int base = 10)
const;
361 uint toUInt(
bool *
ok =
nullptr,
int base = 10)
const;
362 long toLong(
bool *
ok =
nullptr,
int base = 10)
const;
363 ulong toULong(
bool *
ok =
nullptr,
int base = 10)
const;
366 float toFloat(
bool *
ok =
nullptr)
const;
368 QByteArray toBase64(Base64Options options = Base64Encoding)
const;
369 QByteArray toHex(
char separator =
'\0')
const;
372 char percent =
'%')
const;
373 [[nodiscard]]
QByteArray percentDecoded(
char percent =
'%')
const;
399 class FromBase64Result;
400 [[nodiscard]]
static FromBase64Result fromBase64Encoding(
QByteArray &&base64, Base64Options options = Base64Encoding);
401 [[nodiscard]]
static FromBase64Result fromBase64Encoding(
const QByteArray &base64, Base64Options options = Base64Encoding);
402 [[nodiscard]]
static QByteArray fromBase64(
const QByteArray &base64, Base64Options options = Base64Encoding);
404 [[nodiscard]]
static QByteArray fromPercentEncoding(
const QByteArray &pctEncoded,
char percent =
'%');
406#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
417#if defined(Q_OS_WASM) || defined(Q_QDOC)
418 static QByteArray fromEcmaUint8Array(emscripten::val uint8array);
419 emscripten::val toEcmaUint8Array();
468 iterator
erase(const_iterator
first, const_iterator last);
471 static QByteArray fromStdString(
const std::string &
s);
472 std::string toStdString()
const;
475#if QT_DEPRECATED_SINCE(6, 4)
480 QT_CORE_INLINE_SINCE(6, 4)
481 bool isNull() const noexcept;
484#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
485 explicit inline QByteArray(
const DataPointer &dd) :
d(dd) {}
502 template <
typename Predicate>
503 qsizetype removeIf_helper(Predicate pred)
507 d.data()[
d.size] =
'\0';
528#ifndef QT_NO_CAST_FROM_BYTEARRAY
529inline QByteArray::operator
const char *()
const
531inline QByteArray::operator
const void *()
const
542#if QT5_NULL_STRINGS == 1
543 return d.data() ?
d.data() : &_empty;
551{
return !
d->isShared(); }
559 if (
d->needsDetach() || asize >
capacity() -
d->freeSpaceAtBegin())
561 if (
d->constAllocatedCapacity())
571 if (
d->constAllocatedCapacity())
592#if !defined(QT_USE_QSTRINGBUILDER)
596{
return std::move(lhs += rhs); }
600{
return std::move(lhs += rhs); }
604{
return std::move(lhs += rhs); }
626#if QT_CORE_INLINE_IMPL_SINCE(6, 4)
633#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED)
638#ifndef QT_NO_COMPRESS
658 std::swap(decodingStatus,
other.decodingStatus);
663#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC)
674 if (lhs.decodingStatus != rhs.decodingStatus)
685 return !(lhs == rhs);
697 return ba.removeIf_helper([&
t](
const auto &
e) {
return t ==
e; });
700template <
typename Predicate>
703 return ba.removeIf_helper(pred);
715inline namespace Literals {
716inline namespace StringLiterals {
728#if QT_DEPRECATED_SINCE(6, 8)
733 return Qt::StringLiterals::operator
""_ba(
str,
size);
QByteArray toByteArray() const
constexpr qsizetype size() const noexcept
constexpr const_pointer data() const noexcept
QByteArray & operator*() noexcept
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
QByteArray::Base64DecodingStatus decodingStatus
void swap(QByteArray::FromBase64Result &other) noexcept
const QByteArray & operator*() const noexcept
Returns the decoded byte array.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
QByteArray trimmed() const &
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
const char * const_pointer
QByteArray & insert(qsizetype i, const char *s, qsizetype len)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void push_front(QByteArrayView a)
bool endsWith(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
char * iterator
This typedef provides an STL-style non-const iterator for QByteArray.
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last byte in the ...
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first byte in the byte-ar...
QByteArray & insert(qsizetype i, const char *s)
Inserts s at index position i and returns a reference to this byte array.
QByteArray & prepend(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator<=(const char *a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_reverse_iterator crbegin() const noexcept
friend bool operator!=(const QByteArray &a1, std::nullptr_t) noexcept
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
reverse_iterator rbegin()
void reserve(qsizetype size)
Attempts to allocate memory for at least size bytes.
QByteArray & assign(qsizetype n, char c)
QByteArray last(qsizetype n) const
iterator erase(const_iterator it)
QByteArray simplified() const &
void push_back(const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::reverse_iterator< const_iterator > const_reverse_iterator
QByteArray toUpper() const &
QByteArray & insert(qsizetype i, char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator!=(std::nullptr_t, const QByteArray &a2) noexcept
const_iterator begin() const noexcept
friend bool operator>(const char *a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator>=(const QByteArray &, std::nullptr_t) noexcept
qsizetype lastIndexOf(QByteArrayView bv) const
friend bool operator<=(const QByteArray &a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator>=(std::nullptr_t, const QByteArray &a2) noexcept
qsizetype indexOf(QByteArrayView bv, qsizetype from=0) const
const_reverse_iterator crend() const noexcept
qsizetype indexOf(char c, qsizetype from=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & operator+=(const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & operator+=(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & removeLast()
QByteArray & prepend(const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray chopped(qsizetype len) const
QByteArray & prepend(QByteArrayView a)
Prepends the byte array view ba to this byte array and returns a reference to this byte array.
friend bool operator==(const char *a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isValidUtf8() const noexcept
Returns true if this byte array contains valid UTF-8 encoded data, or false otherwise.
friend bool operator>=(const QByteArray &a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype length() const noexcept
Same as size().
friend bool operator==(std::nullptr_t, const QByteArray &a2) noexcept
friend bool operator==(const QByteArray &a1, std::nullptr_t) noexcept
friend bool operator<(const QByteArray &a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator end()
Returns an \l{STL-style iterators}{STL-style iterator} pointing just after the last byte in the byte-...
QByteArray sliced(qsizetype pos, qsizetype n) const
const char * const_iterator
This typedef provides an STL-style const iterator for QByteArray.
friend bool operator!=(const QByteArray &a1, const char *a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator>=(const QByteArray &a1, const char *a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & removeAt(qsizetype pos)
QByteArray & append(const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void push_back(const QByteArray &a)
This function is provided for STL compatibility.
bool isSharedWith(const QByteArray &other) const noexcept
bool startsWith(QByteArrayView bv) const
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
QByteArray & replace(const char *before, qsizetype bsize, const char *after, qsizetype asize)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_iterator ConstIterator
QByteArray & replace(char before, QByteArrayView after)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator<(const char *a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype count(QByteArrayView bv) const
friend bool operator!=(const QByteArray &a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & operator+=(const QByteArray &a)
Appends the byte array ba onto the end of this byte array and returns a reference to this byte array.
void push_back(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void swap(QByteArray &other) noexcept
void push_back(QByteArrayView a)
QByteArray & removeIf(Predicate pred)
QByteArray & insert(qsizetype i, QByteArrayView data)
QByteArray & assign(InputIterator first, InputIterator last)
QByteArray & removeFirst()
bool contains(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_reverse_iterator rend() const noexcept
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
constexpr QByteArray() noexcept
Constructs an empty byte array.
const_iterator end() const noexcept
void squeeze()
Releases any memory not required to store the array's data.
QByteArray & prepend(const char *s, qsizetype len)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & insert(qsizetype i, const QByteArray &data)
Inserts data at index position i and returns a reference to this byte array.
friend bool operator<=(std::nullptr_t, const QByteArray &a2) noexcept
const_iterator cbegin() const noexcept
const_reverse_iterator rbegin() const noexcept
qsizetype lastIndexOf(QByteArrayView bv, qsizetype from) const
QByteArray sliced(qsizetype pos) const
QByteArray first(qsizetype n) const
QByteArray & operator+=(QByteArrayView a)
friend bool operator>=(const char *a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator>(const QByteArray &a1, const char *a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator>(const QByteArray &a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
int compare(QByteArrayView a, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
QByteArray toLower() const &
const_iterator cend() const noexcept
QByteArray(DataPointer &&dd)
QByteArray & append(const char *s, qsizetype len)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & append(QByteArrayView a)
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first byte in the byte-array.
void push_front(const QByteArray &a)
This function is provided for STL compatibility.
qsizetype capacity() const
Returns the maximum number of bytes that can be stored in the byte array without forcing a reallocati...
~QByteArray()
Destroys the byte array.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::reverse_iterator< iterator > reverse_iterator
friend bool operator==(const QByteArray &a1, const char *a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray simplified() &&
char operator[](qsizetype i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void push_front(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator<(const QByteArray &a1, const char *a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator!=(const char *a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
const char & const_reference
friend bool operator<=(const QByteArray &a1, const char *a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const noexcept
Returns true if this byte array is null; otherwise returns false.
void push_front(const char *c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool endsWith(QByteArrayView bv) const
friend bool operator<=(const QByteArray &a1, std::nullptr_t) noexcept
bool startsWith(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
QByteArray & replace(qsizetype index, qsizetype len, const char *s, qsizetype alen)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator==(const QByteArray &a1, const QByteArray &a2) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
list append(new Employee("Blackpool", "Stephen"))
cache insert(employee->id(), employee)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept
typename std::enable_if< std::is_convertible< typename std::iterator_traits< Iterator >::iterator_category, std::input_iterator_tag >::value, bool >::type IfIsInputIterator
Q_CORE_EXPORT int compareMemory(QByteArrayView lhs, QByteArrayView rhs)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findByteArray(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf8(QByteArrayView s) noexcept
int qstrnicmp(const char *str1, qsizetype len1, const char *str2, qsizetype len2)
Q_CORE_EXPORT QDataStream & operator<<(QDataStream &, const QByteArray &)
Q_CORE_EXPORT QByteArray qCompress(const uchar *data, qsizetype nbytes, int compressionLevel=-1)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray::FromBase64Result &key, size_t seed=0) noexcept
qsizetype erase_if(QByteArray &ba, Predicate pred)
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &, QByteArray &)
QArrayDataPointer< char > QByteArrayData
qsizetype erase(QByteArray &ba, const T &t)
Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, qsizetype nbytes)
size_t qstrlen(const char *str)
QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
#define Q_DECL_NS_RETURNS_AUTORELEASED
#define Q_DECL_PURE_FUNCTION
#define Q_DECL_CF_RETURNS_RETAINED
constexpr bool operator!=(const timespec &t1, const timespec &t2)
constexpr timespec operator*(const timespec &t1, int mul)
#define Q_FORWARD_DECLARE_CF_TYPE(type)
#define Q_FORWARD_DECLARE_OBJC_CLASS(classname)
#define Q_DECLARE_FLAGS(Flags, Enum)
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
constexpr const T & qMax(const T &a, const T &b)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLenum GLint GLint * precision
const void * data_ptr(const QTransform &t)
bool operator>(const QPoint &a, const QPoint &b)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
static void split(QT_FT_Vector *b)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
static constexpr QChar sep
#define QT_ASCII_CAST_WARN
#define QT_DEPRECATED_VERSION_X_6_4(text)
#define QT_DEPRECATED_VERSION_X_6_8(text)
static int compare(quint64 a, quint64 b)
bool operator<=(const QUuid &lhs, const QUuid &rhs) noexcept
bool operator>=(const QUuid &lhs, const QUuid &rhs) noexcept
static int toInt(const QChar &qc, int R)
static double toDouble(Value v)
settings remove("monkey")
@ CapacityReserved
the capacity was reserved by the user, try to keep it