8#include <QtCore/qrefcount.h>
9#include <QtCore/qnamespace.h>
10#include <QtCore/qarraydata.h>
11#include <QtCore/qarraydatapointer.h>
12#include <QtCore/qcompare.h>
13#include <QtCore/qcontainerfwd.h>
14#include <QtCore/qbytearrayalgorithms.h>
15#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)
33Q_FORWARD_DECLARE_CF_TYPE(CFData);
34Q_FORWARD_DECLARE_OBJC_CLASS(NSData);
37#if defined(Q_OS_WASM) || defined(Q_QDOC)
50using QByteArrayData = QArrayDataPointer<
char>;
52# define QByteArrayLiteral(str)
53 (QByteArray(QByteArrayData(nullptr, const_cast<char *>(str), sizeof(str) - 1
)))
59 using DataPointer = QByteArrayData;
61 typedef QTypedArrayData<
char> Data;
64 static const char _empty;
66 friend class ::tst_QByteArray;
68 template <
typename InputIterator>
69 using if_input_iterator = QtPrivate::IfIsInputIterator<InputIterator>;
73 Base64UrlEncoding = 1,
75 KeepTrailingEquals = 0,
76 OmitTrailingEquals = 2,
78 IgnoreBase64DecodingErrors = 0,
79 AbortOnBase64DecodingErrors = 4,
81 Q_DECLARE_FLAGS(Base64Options, Base64Option)
83 enum class Base64DecodingStatus {
90 inline constexpr QByteArray()
noexcept;
91 QByteArray(
const char *, qsizetype size = -1);
92 QByteArray(qsizetype size,
char c);
93 QByteArray(qsizetype size, Qt::Initialization);
94 explicit QByteArray(QByteArrayView v) : QByteArray(v.data(), v.size()) {}
95 inline QByteArray(
const QByteArray &)
noexcept;
98 QByteArray &operator=(
const QByteArray &)
noexcept;
99 QByteArray &operator=(
const char *str);
100 inline QByteArray(QByteArray && other)
noexcept
102 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QByteArray)
103 inline void swap(QByteArray &other)
noexcept
106 bool isEmpty()
const noexcept {
return size() == 0; }
107 void resize(qsizetype size);
108 void resize(qsizetype size,
char c);
109 void resizeForOverwrite(qsizetype size);
111 QByteArray &fill(
char c, qsizetype size = -1);
113 inline qsizetype capacity()
const;
114 inline void reserve(qsizetype size);
115 inline void squeeze();
117#ifndef QT_NO_CAST_FROM_BYTEARRAY
118 inline operator
const char *()
const;
119 inline operator
const void *()
const;
122 inline const char *data()
const noexcept;
123 const char *constData()
const noexcept {
return data(); }
124 inline void detach();
125 inline bool isDetached()
const;
126 inline bool isSharedWith(
const QByteArray &other)
const noexcept
127 {
return data() == other.data() && size() == other.size(); }
130 inline char at(qsizetype i)
const;
131 inline char operator[](qsizetype i)
const;
132 [[nodiscard]]
inline char &operator[](qsizetype i);
133 [[nodiscard]]
char front()
const {
return at(0); }
134 [[nodiscard]]
inline char &front();
135 [[nodiscard]]
char back()
const {
return at(size() - 1); }
136 [[nodiscard]]
inline char &back();
138 QT_CORE_INLINE_SINCE(6, 8)
139 qsizetype indexOf(
char c, qsizetype from = 0)
const;
140 qsizetype indexOf(QByteArrayView bv, qsizetype from = 0)
const
141 {
return QtPrivate::findByteArray(qToByteArrayViewIgnoringNull(*
this), from, bv); }
143 QT_CORE_INLINE_SINCE(6, 8)
144 qsizetype lastIndexOf(
char c, qsizetype from = -1)
const;
145 qsizetype lastIndexOf(QByteArrayView bv)
const
146 {
return lastIndexOf(bv, size()); }
147 qsizetype lastIndexOf(QByteArrayView bv, qsizetype from)
const
148 {
return QtPrivate::lastIndexOf(qToByteArrayViewIgnoringNull(*
this), from, bv); }
150 inline bool contains(
char c)
const;
151 inline bool contains(QByteArrayView bv)
const;
152 qsizetype count(
char c)
const;
153 qsizetype count(QByteArrayView bv)
const
154 {
return QtPrivate::count(qToByteArrayViewIgnoringNull(*
this), bv); }
156 inline int compare(QByteArrayView a, Qt::CaseSensitivity cs = Qt::CaseSensitive)
const noexcept;
158#if QT_CORE_REMOVED_SINCE(6
, 7
)
159 QByteArray left(qsizetype len)
const;
160 QByteArray right(qsizetype len)
const;
161 QByteArray mid(qsizetype index, qsizetype len = -1)
const;
162 QByteArray first(qsizetype n)
const;
163 QByteArray last(qsizetype n)
const;
164 QByteArray sliced(qsizetype pos)
const;
165 QByteArray sliced(qsizetype pos, qsizetype n)
const;
166 QByteArray chopped(qsizetype len)
const;
168 [[nodiscard]] QByteArray left(qsizetype n)
const &
172 return first(qMax(n, 0));
174 [[nodiscard]] QByteArray left(qsizetype n) &&
177 return std::move(*
this);
178 return std::move(*
this).first(qMax(n, 0));
180 [[nodiscard]] QByteArray right(qsizetype n)
const &
184 return last(qMax(n, 0));
186 [[nodiscard]] QByteArray right(qsizetype n) &&
189 return std::move(*
this);
190 return std::move(*
this).last(qMax(n, 0));
192 [[nodiscard]] QByteArray mid(qsizetype index, qsizetype len = -1)
const &;
193 [[nodiscard]] QByteArray mid(qsizetype index, qsizetype len = -1) &&;
195 [[nodiscard]] QByteArray first(qsizetype n)
const &
196 { verify(0, n);
return sliced(0, n); }
197 [[nodiscard]] QByteArray last(qsizetype n)
const &
198 { verify(0, n);
return sliced(size() - n, n); }
199 [[nodiscard]] QByteArray sliced(qsizetype pos)
const &
200 { verify(pos, 0);
return sliced(pos, size() - pos); }
201 [[nodiscard]] QByteArray sliced(qsizetype pos, qsizetype n)
const &
202 { verify(pos, n);
return QByteArray(d.data() + pos, n); }
203 [[nodiscard]] QByteArray chopped(qsizetype len)
const &
204 { verify(0, len);
return sliced(0, size() - len); }
206 [[nodiscard]] QByteArray first(qsizetype n) &&
210 return std::move(*
this);
212 [[nodiscard]] QByteArray last(qsizetype n) &&
213 { verify(0, n);
return sliced_helper(*
this, size() - n, n); }
214 [[nodiscard]] QByteArray sliced(qsizetype pos) &&
215 { verify(pos, 0);
return sliced_helper(*
this, pos, size() - pos); }
216 [[nodiscard]] QByteArray sliced(qsizetype pos, qsizetype n) &&
217 { verify(pos, n);
return sliced_helper(*
this, pos, n); }
218 [[nodiscard]] QByteArray chopped(qsizetype len) &&
219 { verify(0, len);
return std::move(*
this).first(size() - len); }
222 bool startsWith(QByteArrayView bv)
const
223 {
return QtPrivate::startsWith(qToByteArrayViewIgnoringNull(*
this), bv); }
224 bool startsWith(
char c)
const {
return size() > 0 && front() == c; }
226 bool endsWith(
char c)
const {
return size() > 0 && back() == c; }
227 bool endsWith(QByteArrayView bv)
const
228 {
return QtPrivate::endsWith(qToByteArrayViewIgnoringNull(*
this), bv); }
230 bool isUpper()
const;
231 bool isLower()
const;
233 [[nodiscard]]
bool isValidUtf8()
const noexcept
235 return QtPrivate::isValidUtf8(qToByteArrayViewIgnoringNull(*
this));
238 void truncate(qsizetype pos);
239 void chop(qsizetype n);
241 QByteArray &slice(qsizetype pos)
242 { verify(pos, 0);
return remove(0, pos); }
243 QByteArray &slice(qsizetype pos, qsizetype n)
249 return remove(0, pos);
253 [[nodiscard]] QByteArray toLower()
const &
254 {
return toLower_helper(*
this); }
255 [[nodiscard]] QByteArray toLower() &&
256 {
return toLower_helper(*
this); }
257 [[nodiscard]] QByteArray toUpper()
const &
258 {
return toUpper_helper(*
this); }
259 [[nodiscard]] QByteArray toUpper() &&
260 {
return toUpper_helper(*
this); }
261 [[nodiscard]] QByteArray trimmed()
const &
262 {
return trimmed_helper(*
this); }
263 [[nodiscard]] QByteArray trimmed() &&
264 {
return trimmed_helper(*
this); }
265 [[nodiscard]] QByteArray simplified()
const &
266 {
return simplified_helper(*
this); }
267 [[nodiscard]] QByteArray simplified() &&
268 {
return simplified_helper(*
this); }
270 [[nodiscard]] QByteArray toLower()
const;
271 [[nodiscard]] QByteArray toUpper()
const;
272 [[nodiscard]] QByteArray trimmed()
const;
273 [[nodiscard]] QByteArray simplified()
const;
276 [[nodiscard]] QByteArray leftJustified(qsizetype width,
char fill =
' ',
bool truncate =
false)
const;
277 [[nodiscard]] QByteArray rightJustified(qsizetype width,
char fill =
' ',
bool truncate =
false)
const;
279 QByteArray &prepend(
char c)
280 {
return insert(0, QByteArrayView(&c, 1)); }
281 inline QByteArray &prepend(qsizetype count,
char c);
282 QByteArray &prepend(
const char *s)
283 {
return insert(0, QByteArrayView(s, qsizetype(qstrlen(s)))); }
284 QByteArray &prepend(
const char *s, qsizetype len)
285 {
return insert(0, QByteArrayView(s, len)); }
286 QByteArray &prepend(
const QByteArray &a);
287 QByteArray &prepend(QByteArrayView a)
288 {
return insert(0, a); }
290 QByteArray &append(
char c);
291 inline QByteArray &append(qsizetype count,
char c);
292 QByteArray &append(
const char *s)
293 {
return append(s, -1); }
294 QByteArray &append(
const char *s, qsizetype len)
295 {
return append(QByteArrayView(s, len < 0 ? qsizetype(qstrlen(s)) : len)); }
296 QByteArray &append(
const QByteArray &a);
297 QByteArray &append(QByteArrayView a)
298 {
return insert(size(), a); }
300 QByteArray &assign(QByteArrayView v);
301 QByteArray &assign(qsizetype n,
char c)
306 template <
typename InputIterator, if_input_iterator<InputIterator> =
true>
307 QByteArray &assign(InputIterator first, InputIterator last)
309 d.assign(first, last);
311 d.data()[d.size] =
'\0';
315 QByteArray &insert(qsizetype i, QByteArrayView data);
316 inline QByteArray &insert(qsizetype i,
const char *s)
317 {
return insert(i, QByteArrayView(s)); }
318 inline QByteArray &insert(qsizetype i,
const QByteArray &data)
319 {
return insert(i, QByteArrayView(data)); }
320 QByteArray &insert(qsizetype i, qsizetype count,
char c);
321 QByteArray &insert(qsizetype i,
char c)
322 {
return insert(i, QByteArrayView(&c, 1)); }
323 QByteArray &insert(qsizetype i,
const char *s, qsizetype len)
324 {
return insert(i, QByteArrayView(s, len)); }
326 QByteArray &remove(qsizetype index, qsizetype len);
327 QByteArray &removeAt(qsizetype pos)
328 {
return size_t(pos) < size_t(size()) ? remove(pos, 1) : *
this; }
329 QByteArray &removeFirst() {
return !isEmpty() ? remove(0, 1) : *
this; }
330 QByteArray &removeLast() {
return !isEmpty() ? remove(size() - 1, 1) : *
this; }
332 template <
typename Predicate>
333 QByteArray &removeIf(Predicate pred)
335 removeIf_helper(pred);
339 QByteArray &replace(qsizetype index, qsizetype len,
const char *s, qsizetype alen)
340 {
return replace(index, len, QByteArrayView(s, alen)); }
341 QByteArray &replace(qsizetype index, qsizetype len, QByteArrayView s);
342 QByteArray &replace(
char before, QByteArrayView after)
343 {
return replace(QByteArrayView(&before, 1), after); }
344 QByteArray &replace(
const char *before, qsizetype bsize,
const char *after, qsizetype asize)
345 {
return replace(QByteArrayView(before, bsize), QByteArrayView(after, asize)); }
346 QByteArray &replace(QByteArrayView before, QByteArrayView after);
347 QByteArray &replace(
char before,
char after);
349 QByteArray &operator+=(
char c)
350 {
return append(c); }
351 QByteArray &operator+=(
const char *s)
352 {
return append(s); }
353 QByteArray &operator+=(
const QByteArray &a)
354 {
return append(a); }
355 QByteArray &operator+=(QByteArrayView a)
356 {
return append(a); }
358 QList<QByteArray> split(
char sep)
const;
360 [[nodiscard]] QByteArray repeated(qsizetype times)
const;
362#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
363#if QT_CORE_REMOVED_SINCE(6
, 8
)
364 QT_ASCII_CAST_WARN
inline bool operator==(
const QString &s2)
const;
365 QT_ASCII_CAST_WARN
inline bool operator!=(
const QString &s2)
const;
366 QT_ASCII_CAST_WARN
inline bool operator<(
const QString &s2)
const;
367 QT_ASCII_CAST_WARN
inline bool operator>(
const QString &s2)
const;
368 QT_ASCII_CAST_WARN
inline bool operator<=(
const QString &s2)
const;
369 QT_ASCII_CAST_WARN
inline bool operator>=(
const QString &s2)
const;
373 short toShort(
bool *ok =
nullptr,
int base = 10)
const;
374 ushort toUShort(
bool *ok =
nullptr,
int base = 10)
const;
375 int toInt(
bool *ok =
nullptr,
int base = 10)
const;
376 uint toUInt(
bool *ok =
nullptr,
int base = 10)
const;
377 long toLong(
bool *ok =
nullptr,
int base = 10)
const;
378 ulong toULong(
bool *ok =
nullptr,
int base = 10)
const;
379 qlonglong toLongLong(
bool *ok =
nullptr,
int base = 10)
const;
380 qulonglong toULongLong(
bool *ok =
nullptr,
int base = 10)
const;
381 float toFloat(
bool *ok =
nullptr)
const;
382 double toDouble(
bool *ok =
nullptr)
const;
383 QByteArray toBase64(Base64Options options = Base64Encoding)
const;
384 QByteArray toHex(
char separator =
'\0')
const;
385 QByteArray toPercentEncoding(
const QByteArray &exclude = QByteArray(),
386 const QByteArray &include = QByteArray(),
387 char percent =
'%')
const;
388 [[nodiscard]] QByteArray percentDecoded(
char percent =
'%')
const;
390 inline QByteArray &setNum(
short,
int base = 10);
391 inline QByteArray &setNum(ushort,
int base = 10);
392 inline QByteArray &setNum(
int,
int base = 10);
393 inline QByteArray &setNum(uint,
int base = 10);
394 inline QByteArray &setNum(
long,
int base = 10);
395 inline QByteArray &setNum(ulong,
int base = 10);
396 QByteArray &setNum(qlonglong,
int base = 10);
397 QByteArray &setNum(qulonglong,
int base = 10);
398 inline QByteArray &setNum(
float,
char format =
'g',
int precision = 6);
399 QByteArray &setNum(
double,
char format =
'g',
int precision = 6);
400 QByteArray &setRawData(
const char *a, qsizetype n);
402 [[nodiscard]]
static QByteArray number(
int,
int base = 10);
403 [[nodiscard]]
static QByteArray number(uint,
int base = 10);
404 [[nodiscard]]
static QByteArray number(
long,
int base = 10);
405 [[nodiscard]]
static QByteArray number(ulong,
int base = 10);
406 [[nodiscard]]
static QByteArray number(qlonglong,
int base = 10);
407 [[nodiscard]]
static QByteArray number(qulonglong,
int base = 10);
408 [[nodiscard]]
static QByteArray number(
double,
char format =
'g',
int precision = 6);
409 [[nodiscard]]
static QByteArray fromRawData(
const char *data, qsizetype size)
411 return QByteArray(DataPointer(
nullptr,
const_cast<
char *>(data), size));
414 class FromBase64Result;
415 [[nodiscard]]
static FromBase64Result fromBase64Encoding(QByteArray &&base64, Base64Options options = Base64Encoding);
416 [[nodiscard]]
static FromBase64Result fromBase64Encoding(
const QByteArray &base64, Base64Options options = Base64Encoding);
417 [[nodiscard]]
static QByteArray fromBase64(
const QByteArray &base64, Base64Options options = Base64Encoding);
418 [[nodiscard]]
static QByteArray fromHex(
const QByteArray &hexEncoded);
419 [[nodiscard]]
static QByteArray fromPercentEncoding(
const QByteArray &pctEncoded,
char percent =
'%');
421#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
422 static QByteArray fromCFData(CFDataRef data);
423 static QByteArray fromRawCFData(CFDataRef data);
424 CFDataRef toCFData()
const Q_DECL_CF_RETURNS_RETAINED;
425 CFDataRef toRawCFData()
const Q_DECL_CF_RETURNS_RETAINED;
426 static QByteArray fromNSData(
const NSData *data);
427 static QByteArray fromRawNSData(
const NSData *data);
428 NSData *toNSData()
const Q_DECL_NS_RETURNS_AUTORELEASED;
429 NSData *toRawNSData()
const Q_DECL_NS_RETURNS_AUTORELEASED;
432#if defined(Q_OS_WASM) || defined(Q_QDOC)
433 static QByteArray fromEcmaUint8Array(emscripten::val uint8array);
434 emscripten::val toEcmaUint8Array();
437 typedef char *iterator;
438 typedef const char *const_iterator;
439 typedef iterator Iterator;
440 typedef const_iterator ConstIterator;
441 typedef std::reverse_iterator<iterator> reverse_iterator;
442 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
443 iterator begin() {
return data(); }
444 const_iterator begin()
const noexcept {
return d.data(); }
445 const_iterator cbegin()
const noexcept {
return begin(); }
446 const_iterator constBegin()
const noexcept {
return begin(); }
447 iterator end() {
return begin() + size(); }
448 const_iterator end()
const noexcept {
return begin() + size(); }
449 const_iterator cend()
const noexcept {
return end(); }
450 const_iterator constEnd()
const noexcept {
return end(); }
451 reverse_iterator rbegin() {
return reverse_iterator(end()); }
452 reverse_iterator rend() {
return reverse_iterator(begin()); }
453 const_reverse_iterator rbegin()
const noexcept {
return const_reverse_iterator(end()); }
454 const_reverse_iterator rend()
const noexcept {
return const_reverse_iterator(begin()); }
455 const_reverse_iterator crbegin()
const noexcept {
return rbegin(); }
456 const_reverse_iterator crend()
const noexcept {
return rend(); }
459 typedef qsizetype size_type;
460 typedef qptrdiff difference_type;
461 typedef const char & const_reference;
462 typedef char & reference;
463 typedef char *pointer;
464 typedef const char *const_pointer;
465 typedef char value_type;
466 void push_back(
char c)
468 void push_back(
const char *s)
470 void push_back(
const QByteArray &a)
472 void push_back(QByteArrayView a)
474 void push_front(
char c)
476 void push_front(
const char *c)
478 void push_front(
const QByteArray &a)
480 void push_front(QByteArrayView a)
482 void shrink_to_fit() { squeeze(); }
483 iterator erase(const_iterator first, const_iterator last);
484 inline iterator erase(const_iterator it) {
return erase(it, it + 1); }
485 constexpr qsizetype max_size()
const noexcept
490 static QByteArray fromStdString(
const std::string &s);
491 std::string toStdString()
const;
493 static constexpr qsizetype maxSize()
noexcept
496 return Data::maxSize() - 1;
498 inline qsizetype size()
const noexcept {
return d.size; }
499#if QT_DEPRECATED_SINCE(6
, 4
)
500 QT_DEPRECATED_VERSION_X_6_4(
"Use size() or length() instead.")
501 inline qsizetype count()
const noexcept {
return size(); }
503 inline qsizetype length()
const noexcept {
return size(); }
504 QT_CORE_INLINE_SINCE(6, 4)
505 bool isNull()
const noexcept;
507 inline const DataPointer &data_ptr()
const {
return d; }
508 inline DataPointer &data_ptr() {
return d; }
509#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
510 explicit inline QByteArray(
const DataPointer &dd) : d(dd) {}
512 explicit inline QByteArray(DataPointer &&dd) : d(std::move(dd)) {}
515 friend bool comparesEqual(
const QByteArray &lhs,
const QByteArrayView &rhs)
noexcept
516 {
return QByteArrayView(lhs) == rhs; }
517 friend Qt::strong_ordering
518 compareThreeWay(
const QByteArray &lhs,
const QByteArrayView &rhs)
noexcept
520 const int res = QtPrivate::compareMemory(QByteArrayView(lhs), rhs);
521 return Qt::compareThreeWay(res, 0);
523 Q_DECLARE_STRONGLY_ORDERED(QByteArray)
524 Q_DECLARE_STRONGLY_ORDERED(QByteArray, QByteArrayView)
525 Q_DECLARE_STRONGLY_ORDERED(QByteArray,
const char *)
526#if defined(__GLIBCXX__
) && defined(__cpp_lib_three_way_comparison)
531 friend bool operator<(
const QByteArray &lhs,
const QByteArray &rhs)
noexcept
532 {
return is_lt(compareThreeWay(lhs, rhs)); }
533 friend bool operator<=(
const QByteArray &lhs,
const QByteArray &rhs)
noexcept
534 {
return is_lteq(compareThreeWay(lhs, rhs)); }
535 friend bool operator>(
const QByteArray &lhs,
const QByteArray &rhs)
noexcept
536 {
return is_gt(compareThreeWay(lhs, rhs)); }
537 friend bool operator>=(
const QByteArray &lhs,
const QByteArray &rhs)
noexcept
538 {
return is_gteq(compareThreeWay(lhs, rhs)); }
542 friend bool comparesEqual(
const QByteArray &lhs, std::nullptr_t)
noexcept
543 {
return lhs.isEmpty(); }
544 friend Qt::strong_ordering compareThreeWay(
const QByteArray &lhs, std::nullptr_t)
noexcept
545 {
return lhs.isEmpty() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
546 Q_DECLARE_STRONGLY_ORDERED(QByteArray, std::nullptr_t)
549 friend Q_CORE_EXPORT
bool comparesEqual(
const QByteArray &lhs,
const QChar &rhs)
noexcept;
550 friend Q_CORE_EXPORT Qt::strong_ordering
551 compareThreeWay(
const QByteArray &lhs,
const QChar &rhs)
noexcept;
552 friend Q_CORE_EXPORT
bool comparesEqual(
const QByteArray &lhs,
char16_t rhs)
noexcept;
553 friend Q_CORE_EXPORT Qt::strong_ordering
554 compareThreeWay(
const QByteArray &lhs,
char16_t rhs)
noexcept;
555#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
556 Q_DECLARE_STRONGLY_ORDERED(QByteArray, QChar, QT_ASCII_CAST_WARN)
557 Q_DECLARE_STRONGLY_ORDERED(QByteArray,
char16_t, QT_ASCII_CAST_WARN)
561 void reallocData(qsizetype alloc, QArrayData::AllocationOption option);
562 void reallocGrowData(qsizetype n);
563 void expand(qsizetype i);
565 Q_ALWAYS_INLINE
constexpr void verify([[maybe_unused]] qsizetype pos = 0,
566 [[maybe_unused]] qsizetype n = 1)
const
569 Q_ASSERT(pos <= d.size);
571 Q_ASSERT(n <= d.size - pos);
574 static QByteArray sliced_helper(QByteArray &a, qsizetype pos, qsizetype n);
575 static QByteArray toLower_helper(
const QByteArray &a);
576 static QByteArray toLower_helper(QByteArray &a);
577 static QByteArray toUpper_helper(
const QByteArray &a);
578 static QByteArray toUpper_helper(QByteArray &a);
579 static QByteArray trimmed_helper(
const QByteArray &a);
580 static QByteArray trimmed_helper(QByteArray &a);
581 static QByteArray simplified_helper(
const QByteArray &a);
582 static QByteArray simplified_helper(QByteArray &a);
583 template <
typename Predicate>
584 qsizetype removeIf_helper(Predicate pred)
586 const qsizetype result = d->eraseIf(pred);
588 d.data()[d.size] =
'\0';
592 friend class QString;
593 friend Q_CORE_EXPORT QByteArray qUncompress(
const uchar *data, qsizetype nbytes);
595 template <
typename T>
friend qsizetype erase(QByteArray &ba,
const T &t);
596 template <
typename Predicate>
friend qsizetype erase_if(QByteArray &ba, Predicate pred);
599Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options)
601inline constexpr QByteArray::QByteArray()
noexcept {}
602inline QByteArray::~QByteArray() {}
604inline char QByteArray::at(qsizetype i)
const
605{ verify(i, 1);
return d.data()[i]; }
606inline char QByteArray::operator[](qsizetype i)
const
607{ verify(i, 1);
return d.data()[i]; }
609#ifndef QT_NO_CAST_FROM_BYTEARRAY
610inline QByteArray::operator
const char *()
const
612inline QByteArray::operator
const void *()
const
615inline char *QByteArray::data()
621inline const char *QByteArray::data()
const noexcept
624 return d.data() ? d.data() : &_empty;
629inline void QByteArray::detach()
630{
if (d.needsDetach()) reallocData(size(), QArrayData::KeepSize); }
631inline bool QByteArray::isDetached()
const
632{
return !d.isShared(); }
633inline QByteArray::QByteArray(
const QByteArray &a)
noexcept : d(a.d)
636inline qsizetype QByteArray::capacity()
const {
return qsizetype(d.constAllocatedCapacity()); }
638inline void QByteArray::reserve(qsizetype asize)
640 if (d.needsDetach() || asize > capacity() - d.freeSpaceAtBegin())
641 reallocData(qMax(size(), asize), QArrayData::KeepSize);
642 if (d.constAllocatedCapacity())
643 d.setFlag(Data::CapacityReserved);
646inline void QByteArray::squeeze()
650 if (d.needsDetach() || size() < capacity())
651 reallocData(size(), QArrayData::KeepSize);
652 if (d.constAllocatedCapacity())
653 d.clearFlag(Data::CapacityReserved);
656inline char &QByteArray::operator[](qsizetype i)
657{ verify(i, 1);
return data()[i]; }
658inline char &QByteArray::front() {
return operator[](0); }
659inline char &QByteArray::back() {
return operator[](size() - 1); }
660inline QByteArray &QByteArray::append(qsizetype n,
char ch)
661{
return insert(size(), n, ch); }
662inline QByteArray &QByteArray::prepend(qsizetype n,
char ch)
663{
return insert(0, n, ch); }
664inline bool QByteArray::contains(
char c)
const
665{
return indexOf(c) != -1; }
666inline bool QByteArray::contains(QByteArrayView bv)
const
667{
return indexOf(bv) != -1; }
668inline int QByteArray::compare(QByteArrayView a, Qt::CaseSensitivity cs)
const noexcept
670 return cs == Qt::CaseSensitive ? QtPrivate::compareMemory(*
this, a) :
671 qstrnicmp(data(), size(), a.data(), a.size());
673#if !defined(QT_USE_QSTRINGBUILDER)
675{
return QByteArray(a1) += a2; }
677{
return std::move(lhs += rhs); }
679{
return QByteArray(a1) += a2; }
681{
return std::move(lhs += rhs); }
683{
return QByteArray(a1) += a2; }
685{
return std::move(lhs += rhs); }
687{
return QByteArray(a1) += a2; }
689{
return QByteArray(&a1, 1) += a2; }
691inline QByteArray operator+(
const QByteArray &lhs, QByteArrayView rhs)
693 QByteArray tmp{lhs.size() + rhs.size(), Qt::Uninitialized};
694 return tmp.assign(lhs).append(rhs);
697inline QByteArray operator+(QByteArrayView lhs,
const QByteArray &rhs)
699 QByteArray tmp{lhs.size() + rhs.size(), Qt::Uninitialized};
700 return tmp.assign(lhs).append(rhs);
704inline QByteArray &QByteArray::setNum(
short n,
int base)
705{
return setNum(qlonglong(n), base); }
706inline QByteArray &QByteArray::setNum(ushort n,
int base)
707{
return setNum(qulonglong(n), base); }
708inline QByteArray &QByteArray::setNum(
int n,
int base)
709{
return setNum(qlonglong(n), base); }
710inline QByteArray &QByteArray::setNum(uint n,
int base)
711{
return setNum(qulonglong(n), base); }
712inline QByteArray &QByteArray::setNum(
long n,
int base)
713{
return setNum(qlonglong(n), base); }
714inline QByteArray &QByteArray::setNum(ulong n,
int base)
715{
return setNum(qulonglong(n), base); }
716inline QByteArray &QByteArray::setNum(
float n,
char format,
int precision)
717{
return setNum(
double(n), format, precision); }
719#if QT_CORE_INLINE_IMPL_SINCE(6
, 4
)
720bool QByteArray::isNull()
const noexcept
725#if QT_CORE_INLINE_IMPL_SINCE(6
, 8
)
726qsizetype QByteArray::indexOf(
char ch, qsizetype from)
const
728 return qToByteArrayViewIgnoringNull(*
this).indexOf(ch, from);
730qsizetype QByteArray::lastIndexOf(
char ch, qsizetype from)
const
732 return qToByteArrayViewIgnoringNull(*
this).lastIndexOf(ch, from);
736#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED)
737Q_CORE_EXPORT
QDataStream &operator<<(QDataStream &,
const QByteArray &);
738Q_CORE_EXPORT
QDataStream &operator>>(QDataStream &, QByteArray &);
741#ifndef QT_NO_COMPRESS
742Q_CORE_EXPORT
QByteArray qCompress(
const uchar* data, qsizetype nbytes,
int compressionLevel = -1);
743Q_CORE_EXPORT
QByteArray qUncompress(
const uchar* data, qsizetype nbytes);
745{
return qCompress(
reinterpret_cast<
const uchar *>(data.constData()), data.size(), compressionLevel); }
747{
return qUncompress(
reinterpret_cast<
const uchar*>(data.constData()), data.size()); }
758 void swap(QByteArray::FromBase64Result &other)
noexcept
760 decoded.swap(other.decoded);
761 std::swap(decodingStatus, other.decodingStatus);
764 explicit operator bool()
const noexcept {
return decodingStatus == QByteArray::Base64DecodingStatus::Ok; }
766#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC)
775 friend inline bool operator==(
const QByteArray::FromBase64Result &lhs,
const QByteArray::FromBase64Result &rhs)
noexcept
777 if (lhs.decodingStatus != rhs.decodingStatus)
780 if (lhs.decodingStatus == QByteArray::Base64DecodingStatus::Ok && lhs.decoded != rhs.decoded)
786 friend inline bool operator!=(
const QByteArray::FromBase64Result &lhs,
const QByteArray::FromBase64Result &rhs)
noexcept
788 return !(lhs == rhs);
795Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(
const QByteArray::FromBase64Result &key, size_t seed = 0)
noexcept;
800 return ba.removeIf_helper([&t](
const auto &e) {
return t == e; });
803template <
typename Predicate>
806 return ba.removeIf_helper(pred);
812QByteArray QByteArrayView::toByteArray()
const
814 return QByteArray(*
this);
823 return QByteArray(QByteArrayData(
nullptr,
const_cast<
char *>(str), qsizetype(size)));
831#if QT_DEPRECATED_SINCE(6
, 8
)
QByteArray & operator*() noexcept
QByteArray::Base64DecodingStatus decodingStatus
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
void swap(QByteArray::FromBase64Result &other) noexcept
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
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.
\inmodule QtCore\reentrant
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
std::optional< BacktraceStorage > backtrace
static constexpr int DefaultBacktraceDepth
static void setFilterRules(const QString &rules)
Configures which categories and message types should be enabled through a set of rules.
~QLoggingCategory()
Destroys a QLoggingCategory object.
bool isInfoEnabled() const
Returns true if informational messages should be shown for this category; false otherwise.
static QLoggingCategory * defaultCategory()
Returns a pointer to the global category "default" that is used, for example, by qDebug(),...
QLoggingCategory & operator()()
Returns the object itself.
void(*) CategoryFilter(QLoggingCategory *)
This is a typedef for a pointer to a function with the following signature:
void setEnabled(QtMsgType type, bool enable)
Changes the message type type for the category to enable.
static CategoryFilter installFilter(CategoryFilter)
Take control of how logging categories are configured.
bool isWarningEnabled() const
Returns true if warning messages should be shown for this category; false otherwise.
bool isEnabled(QtMsgType type) const
Returns true if a message of type msgtype for the category should be shown; false otherwise.
bool isCriticalEnabled() const
Returns true if critical messages should be shown for this category; false otherwise.
const char * categoryName() const
Returns the name of the category.
bool isDebugEnabled() const
Returns true if debug messages should be shown for this category; false otherwise.
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
constexpr QMessageLogContext() noexcept=default
QDebug debug(CategoryFunction catFunc) const
Logs a debug message into category returned by catFunc using a QDebug stream.
QDebug debug(const QLoggingCategory &cat) const
Logs a debug message into category cat using a QDebug stream.
void void void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QDebug debug() const
Logs a debug message using a QDebug stream.
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
QDebug info() const
Logs an informational message using a QDebug stream.
QDebug info(CategoryFunction catFunc) const
Logs an informational message into category returned by catFunc using a QDebug stream.
QNoDebug noDebug() const noexcept
static const char ifCriticalTokenC[]
static const char emptyTokenC[]
static Q_NEVER_INLINE void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static bool systemHasStderr()
Returns true if writing to stderr is supported.
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
static const char messageTokenC[]
static constexpr SystemMessageSink systemMessageSink
#define HANDLE_IF_TOKEN(LEVEL)
static const char defaultPattern[]
static const char timeTokenC[]
static bool is_fatal_count_down(QAtomicInt &n)
static const char qthreadptrTokenC[]
static const char fileTokenC[]
static const char ifDebugTokenC[]
static const char ifFatalTokenC[]
static const char categoryTokenC[]
static const char lineTokenC[]
static const char typeTokenC[]
static const char ifCategoryTokenC[]
static int checked_var_value(const char *varname)
static const char pidTokenC[]
Q_TRACE_POINT(qtcore, qt_message_print, int type, const char *category, const char *function, const char *file, int line, const QString &message)
static const char threadidTokenC[]
static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
static const char backtraceTokenC[]
static const char functionTokenC[]
static const char ifWarningTokenC[]
static const char appnameTokenC[]
static Q_NORETURN void qt_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message)
\inmodule QtCore \title Qt Logging Types
static bool isFatal(QtMsgType msgType)
static const char ifInfoTokenC[]
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message)
static bool stderrHasConsoleAttached()
Returns true if writing to stderr will end up in a console/terminal visible to the user.
Combined button and popup list for selecting options.
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
QByteArray operator""_ba(const char *str, size_t size) noexcept
QByteArray operator+(const QByteArray &a1, const char *a2)
QByteArray qUncompress(const QByteArray &data)
QByteArray operator+(char a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, char rhs)
QByteArray operator+(const QByteArray &a1, char a2)
QByteArray operator+(const char *a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, const QByteArray &rhs)
qsizetype erase_if(QByteArray &ba, Predicate pred)
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
QByteArray qCompress(const QByteArray &data, int compressionLevel=-1)
qsizetype erase(QByteArray &ba, const T &t)
QByteArray operator+(QByteArray &&lhs, const char *rhs)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
#define QT_MESSAGELOG_FUNC
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg,...)
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg,...)
#define QT_MESSAGELOG_FILE
#define QT_MESSAGE_LOGGER_NORETURN
#define QT_MESSAGELOG_LINE
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
#define Q_LOGGING_CATEGORY(name,...)
#define QT_MESSAGE_LOGGER_COMMON(category, level)
#define Q_DECLARE_LOGGING_CATEGORY(name)
void setPattern(const QString &pattern)
std::unique_ptr< std::unique_ptr< const char[]>[]> literals
std::unique_ptr< const char *[]> tokens
QList< QString > timeArgs