1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.core.bytearray;
13 extern(C++):
14 
15 import core.stdc.config;
16 import core.vararg;
17 import qt.config;
18 import qt.core.arraydata;
19 import qt.core.arraydatapointer;
20 import qt.core.bytearrayview;
21 import qt.core.flags;
22 import qt.core.global;
23 import qt.core.list;
24 import qt.core.namespace;
25 import qt.core.typeinfo;
26 import qt.helpers;
27 
28 /+ #ifndef QT5_NULL_STRINGS
29 // Would ideally be off, but in practice breaks too much (Qt 6.0).
30 #define QT5_NULL_STRINGS 1
31 #endif
32 
33 #ifdef truncate
34 #error qbytearray.h must be included before any header file that defines truncate
35 #endif
36 
37 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
38 Q_FORWARD_DECLARE_CF_TYPE(CFData);
39 Q_FORWARD_DECLARE_OBJC_CLASS(NSData);
40 #endif +/
41 
42 
43 
44 alias QByteArrayData = QArrayDataPointer!(char);
45 
46 /+ #  define QByteArrayLiteral(str) \
47     (QByteArray(QByteArrayData(nullptr, const_cast<char *>(str), sizeof(str) - 1))) \
48     /**/ +/
49 
50 /// Binding for C++ class [QByteArray](https://doc.qt.io/qt-6/qbytearray.html).
51 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QByteArray
52 {
53 public:
54     alias DataPointer = QByteArrayData;
55 private:
56     alias Data = QTypedArrayData!(char);
57 
58     DataPointer d;
59     mixin(mangleWindows("?_empty@QByteArray@@0DB", exportOnWindows ~ q{
60     extern static __gshared const(char) _empty;
61     }));
62 public:
63 
64     enum Base64Option {
65         Base64Encoding = 0,
66         Base64UrlEncoding = 1,
67 
68         KeepTrailingEquals = 0,
69         OmitTrailingEquals = 2,
70 
71         IgnoreBase64DecodingErrors = 0,
72         AbortOnBase64DecodingErrors = 4,
73     }
74     /+ Q_DECLARE_FLAGS(Base64Options, Base64Option) +/
75 alias Base64Options = QFlags!(Base64Option);
76     enum /+ class +/ Base64DecodingStatus {
77         Ok,
78         IllegalInputLength,
79         IllegalCharacter,
80         IllegalPadding,
81     }
82 
83     //pragma(inline, true) void this()/+ noexcept+/ {}
84     static typeof(this) create()
85     {
86         return typeof(this).init;
87     }
88 
89     this(const(char)* , qsizetype size = -1);
90     this(qsizetype size, char c);
91     this(qsizetype size, /+ Qt:: +/qt.core.namespace.Initialization);
92     /+@disable this(this);
93     pragma(inline, true) this(ref const(QByteArray) a)/+ noexcept+/
94     {
95         this.d = a.d;
96     }+/
97     pragma(inline, true) ~this() {}
98 
99     /+ref QByteArray operator =(ref const(QByteArray) )/+ noexcept+/;+/
100     /+ref QByteArray operator =(const(char)* str);+/
101     /+ inline QByteArray(QByteArray && other) noexcept
102     { qSwap(d, other.d); } +/
103     /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QByteArray) +/
104     /+ inline void swap(QByteArray &other) noexcept
105     { qSwap(d, other.d); } +/
106 
107     pragma(inline, true) bool isEmpty() const
108     { return size() == 0; }
109     void resize(qsizetype size);
110 
111     ref QByteArray fill(char c, qsizetype size = -1);
112 
113     pragma(inline, true) qsizetype capacity() const { return qsizetype(d.constAllocatedCapacity()); }
114     pragma(inline, true) void reserve(qsizetype asize)
115     {
116         if (d.needsDetach() || asize > capacity() - d.freeSpaceAtBegin())
117             reallocData(qMax(size(), asize), QArrayData.AllocationOption.KeepSize);
118         if (d.constAllocatedCapacity())
119             d.setFlag(Data.ArrayOptions.CapacityReserved);
120     }
121     pragma(inline, true) void squeeze()
122     {
123         if (!d.isMutable())
124             return;
125         if (d.needsDetach() || size() < capacity())
126             reallocData(size(), QArrayData.AllocationOption.KeepSize);
127         if (d.constAllocatedCapacity())
128             d.clearFlag(Data.ArrayOptions.CapacityReserved);
129     }
130 
131     version(QT_NO_CAST_FROM_BYTEARRAY){}else
132     {
133         /+pragma(inline, true) auto opCast(T : const(char))() const;+/
134         /+pragma(inline, true) auto opCast(T : const(void))() const;+/
135     }
136     pragma(inline, true) char* data()
137     {
138         detach();
139         (mixin(Q_ASSERT(q{QByteArray.d.data()})));
140         return d.data();
141     }
142     pragma(inline, true) const(char)* data() const
143     {
144         static if((configValue!"QT5_NULL_STRINGS" == 1 || !defined!"QT5_NULL_STRINGS"))
145         {
146             return d.data() ? d.data() : &_empty;
147         }
148         else
149         {
150             return d.data();
151         }
152     }
153     pragma(inline, true) const(char)* constData() const
154     { return data(); }
155 
156     extern(D) const(ubyte)[] toConstUByteArray()
157     {
158         return (cast(const(ubyte)*)constData())[0..length];
159     }
160     extern(D) const(char)[] toConstCharArray()
161     {
162         return (cast(const(char)*)constData())[0..length];
163     }
164 
165     pragma(inline, true) void detach()
166     { if (d.needsDetach()) reallocData(size(), QArrayData.AllocationOption.KeepSize); }
167     pragma(inline, true) bool isDetached() const
168     { return !d.isShared(); }
169     pragma(inline, true) bool isSharedWith(ref const(QByteArray) other) const
170     { return data() == other.data() && size() == other.size(); }
171     void clear();
172 
173     pragma(inline, true) char at(qsizetype i) const
174     { (mixin(Q_ASSERT(q{size_t(i) < size_t(QByteArray.size())}))); return d.data()[i]; }
175     pragma(inline, true) char opIndex(qsizetype i) const
176     { (mixin(Q_ASSERT(q{size_t(i) < size_t(QByteArray.size())}))); return d.data()[i]; }
177     /+ [[nodiscard]] +/ pragma(inline, true) ref char opIndex(qsizetype i)
178     { (mixin(Q_ASSERT(q{i >= 0 && i < QByteArray.size()}))); return data()[i]; }
179     /+ [[nodiscard]] +/ char front() const { return at(0); }
180     /+ [[nodiscard]] +/ pragma(inline, true) ref char front() { return opIndex(0); }
181     /+ [[nodiscard]] +/ char back() const { return at(size() - 1); }
182     /+ [[nodiscard]] +/ pragma(inline, true) ref char back() { return opIndex(size() - 1); }
183 
184     qsizetype indexOf(char c, qsizetype from = 0) const;
185     qsizetype indexOf(QByteArrayView bv, qsizetype from = 0) const
186     {
187         import qt.core.bytearrayalgorithms;
188         return /+ QtPrivate:: +/qt.core.bytearrayalgorithms.findByteArray(qToByteArrayViewIgnoringNull(this), from, bv);
189     }
190 
191     qsizetype lastIndexOf(char c, qsizetype from = -1) const;
192     qsizetype lastIndexOf(QByteArrayView bv) const
193     { return lastIndexOf(bv, size()); }
194     qsizetype lastIndexOf(QByteArrayView bv, qsizetype from) const
195     {
196         import qt.core.bytearrayalgorithms;
197         return /+ QtPrivate:: +/qt.core.bytearrayalgorithms.lastIndexOf(qToByteArrayViewIgnoringNull(this), from, bv);
198     }
199 
200     pragma(inline, true) bool contains(char c) const
201     { return indexOf(c) != -1; }
202     pragma(inline, true) bool contains(QByteArrayView bv) const
203     { return indexOf(bv) != -1; }
204     qsizetype count(char c) const;
205     qsizetype count(QByteArrayView bv) const
206     {
207         import qt.core.bytearrayalgorithms;
208         return /+ QtPrivate:: +/qt.core.bytearrayalgorithms.count(qToByteArrayViewIgnoringNull(this), bv);
209     }
210 
211     pragma(inline, true) int compare(QByteArrayView a, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/
212     {
213         import qt.core.bytearrayalgorithms;
214 
215         return cs == /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive ? /+ QtPrivate:: +/qt.core.bytearrayalgorithms.compareMemory(QByteArrayView(this), a) :
216                                          qstrnicmp(data(), size(), a.data(), a.size());
217     }
218 
219     /+ [[nodiscard]] +/ QByteArray left(qsizetype len) const;
220     /+ [[nodiscard]] +/ QByteArray right(qsizetype len) const;
221     /+ [[nodiscard]] +/ QByteArray mid(qsizetype index, qsizetype len = -1) const;
222 
223     /+ [[nodiscard]] +/ QByteArray first(qsizetype n) const
224     { (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{n <= size()}))); return QByteArray(data(), n); }
225     /+ [[nodiscard]] +/ QByteArray last(qsizetype n) const
226     { (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{n <= size()}))); return QByteArray(data() + size() - n, n); }
227     /+ [[nodiscard]] +/ QByteArray sliced(qsizetype pos) const
228     { (mixin(Q_ASSERT(q{pos >= 0}))); (mixin(Q_ASSERT(q{pos <= size()}))); return QByteArray(data() + pos, size() - pos); }
229     /+ [[nodiscard]] +/ QByteArray sliced(qsizetype pos, qsizetype n) const
230     { (mixin(Q_ASSERT(q{pos >= 0}))); (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{size_t(pos) + size_t(n) <= size_t(size())}))); return QByteArray(data() + pos, n); }
231     /+ [[nodiscard]] +/ QByteArray chopped(qsizetype len) const
232     { (mixin(Q_ASSERT(q{len >= 0}))); (mixin(Q_ASSERT(q{len <= size()}))); return first(size() - len); }
233 
234     bool startsWith(QByteArrayView bv) const
235     {
236         import qt.core.bytearrayalgorithms;
237         return /+ QtPrivate:: +/qt.core.bytearrayalgorithms.startsWith(qToByteArrayViewIgnoringNull(this), bv);
238     }
239     bool startsWith(char c) const { return size() > 0 && front() == c; }
240 
241     bool endsWith(char c) const { return size() > 0 && back() == c; }
242     bool endsWith(QByteArrayView bv) const
243     {
244         import qt.core.bytearrayalgorithms;
245         return /+ QtPrivate:: +/qt.core.bytearrayalgorithms.endsWith(qToByteArrayViewIgnoringNull(this), bv);
246     }
247 
248     bool isUpper() const;
249     bool isLower() const;
250 
251     void truncate(qsizetype pos);
252     void chop(qsizetype n);
253 
254 /+ #if !defined(Q_CLANG_QDOC) +/
255     /+ [[nodiscard]] +/ QByteArray toLower() const/+ &+/
256     { return toLower_helper(this); }
257     /+ [[nodiscard]] QByteArray toLower() &&
258     { return toLower_helper(*this); } +/
259     /+ [[nodiscard]] +/ QByteArray toUpper() const/+ &+/
260     { return toUpper_helper(this); }
261     /+ [[nodiscard]] QByteArray toUpper() &&
262     { return toUpper_helper(*this); } +/
263     /+ [[nodiscard]] +/ QByteArray trimmed() const/+ &+/
264     { return trimmed_helper(this); }
265     /+ [[nodiscard]] QByteArray trimmed() &&
266     { return trimmed_helper(*this); } +/
267     /+ [[nodiscard]] +/ QByteArray simplified() const/+ &+/
268     { return simplified_helper(this); }
269     /+ [[nodiscard]] QByteArray simplified() &&
270     { return simplified_helper(*this); } +/
271 /+ #else
272     [[nodiscard]] QByteArray toLower() const;
273     [[nodiscard]] QByteArray toUpper() const;
274     [[nodiscard]] QByteArray trimmed() const;
275     [[nodiscard]] QByteArray simplified() const;
276 #endif +/
277 
278     /+ [[nodiscard]] +/ QByteArray leftJustified(qsizetype width, char fill = ' ', bool truncate = false) const;
279     /+ [[nodiscard]] +/ QByteArray rightJustified(qsizetype width, char fill = ' ', bool truncate = false) const;
280 
281     ref QByteArray prepend(char c)
282     { return insert(0, QByteArrayView(&c, 1)); }
283     pragma(inline, true) ref QByteArray prepend(qsizetype n, char ch)
284     { return insert(0, n, ch); }
285     ref QByteArray prepend(const(char)* s)
286     {
287         import qt.core.bytearrayalgorithms;
288         return insert(0, QByteArrayView(s, qsizetype(qstrlen(s))));
289     }
290     ref QByteArray prepend(const(char)* s, qsizetype len)
291     { return insert(0, QByteArrayView(s, len)); }
292     ref QByteArray prepend(ref const(QByteArray) a);
293     ref QByteArray prepend(QByteArrayView a)
294     { return insert(0, a); }
295 
296     ref QByteArray append(char c);
297     pragma(inline, true) ref QByteArray append(qsizetype n, char ch)
298     { return insert(size(), n, ch); }
299     ref QByteArray append(const(char)* s)
300     {
301         import qt.core.bytearrayalgorithms;
302         return append(QByteArrayView(s, qsizetype(qstrlen(s))));
303     }
304     ref QByteArray append(const(char)* s, qsizetype len)
305     { return append(QByteArrayView(s, len)); }
306     ref QByteArray append(ref const(QByteArray) a);
307     ref QByteArray append(QByteArrayView a)
308     { return insert(size(), a); }
309 
310     ref QByteArray insert(qsizetype i, QByteArrayView data);
311     pragma(inline, true) ref QByteArray insert(qsizetype i, const(char)* s)
312     { return insert(i, QByteArrayView(s)); }
313     pragma(inline, true) ref QByteArray insert(qsizetype i, ref const(QByteArray) data)
314     { return insert(i, QByteArrayView(data)); }
315     ref QByteArray insert(qsizetype i, qsizetype count, char c);
316     ref QByteArray insert(qsizetype i, char c)
317     { return insert(i, QByteArrayView(&c, 1)); }
318     ref QByteArray insert(qsizetype i, const(char)* s, qsizetype len)
319     { return insert(i, QByteArrayView(s, len)); }
320 
321     ref QByteArray remove(qsizetype index, qsizetype len);
322     /+ template <typename Predicate> +/
323     ref QByteArray removeIf(Predicate)(Predicate pred)
324     {
325         import qt.core.containertools_impl;
326 
327         /+ QtPrivate:: +/qt.core.containertools_impl.sequential_erase_if(this, pred);
328         return this;
329     }
330 
331     ref QByteArray replace(qsizetype index, qsizetype len, const(char)* s, qsizetype alen)
332     { return replace(index, len, QByteArrayView(s, alen)); }
333     ref QByteArray replace(qsizetype index, qsizetype len, QByteArrayView s);
334     ref QByteArray replace(char before, QByteArrayView after)
335     { return replace(QByteArrayView(&before, 1), after); }
336     ref QByteArray replace(const(char)* before, qsizetype bsize, const(char)* after, qsizetype asize)
337     { return replace(QByteArrayView(before, bsize), QByteArrayView(after, asize)); }
338     ref QByteArray replace(QByteArrayView before, QByteArrayView after);
339     ref QByteArray replace(char before, char after);
340 
341     extern(D) ref QByteArray opOpAssign(string op)(char c) if(op == "~")
342     { return append(c); }
343     extern(D) ref QByteArray opOpAssign(string op)(const(char)* s) if(op == "~")
344     { return append(s); }
345     extern(D) ref QByteArray opOpAssign(string op)(ref const(QByteArray) a) if(op == "~")
346     { return append(a); }
347     extern(D) ref QByteArray opOpAssign(string op)(QByteArrayView a) if(op == "~")
348     { return append(a); }
349 
350     QList!(QByteArray) split(char sep) const;
351 
352     /+ [[nodiscard]] +/ QByteArray repeated(qsizetype times) const;
353 
354 /+ #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
355     QT_ASCII_CAST_WARN inline bool operator==(const QString &s2) const;
356     QT_ASCII_CAST_WARN inline bool operator!=(const QString &s2) const;
357     QT_ASCII_CAST_WARN inline bool operator<(const QString &s2) const;
358     QT_ASCII_CAST_WARN inline bool operator>(const QString &s2) const;
359     QT_ASCII_CAST_WARN inline bool operator<=(const QString &s2) const;
360     QT_ASCII_CAST_WARN inline bool operator>=(const QString &s2) const;
361 #endif +/
362     /+ friend inline bool operator==(const QByteArray &a1, const QByteArray &a2) noexcept
363     { return QByteArrayView(a1) == QByteArrayView(a2); } +/
364     /+ friend inline bool operator==(const QByteArray &a1, const char *a2) noexcept
365     { return a2 ? QtPrivate::compareMemory(a1, a2) == 0 : a1.isEmpty(); } +/
366     /+ friend inline bool operator==(const char *a1, const QByteArray &a2) noexcept
367     { return a1 ? QtPrivate::compareMemory(a1, a2) == 0 : a2.isEmpty(); } +/
368     /+ friend inline bool operator!=(const QByteArray &a1, const QByteArray &a2) noexcept
369     { return !(a1==a2); } +/
370     /+ friend inline bool operator!=(const QByteArray &a1, const char *a2) noexcept
371     { return a2 ? QtPrivate::compareMemory(a1, a2) != 0 : !a1.isEmpty(); } +/
372     /+ friend inline bool operator!=(const char *a1, const QByteArray &a2) noexcept
373     { return a1 ? QtPrivate::compareMemory(a1, a2) != 0 : !a2.isEmpty(); } +/
374     /+ friend inline bool operator<(const QByteArray &a1, const QByteArray &a2) noexcept
375     { return QtPrivate::compareMemory(QByteArrayView(a1), QByteArrayView(a2)) < 0; } +/
376     /+ friend inline bool operator<(const QByteArray &a1, const char *a2) noexcept
377     { return QtPrivate::compareMemory(a1, a2) < 0; } +/
378     /+ friend inline bool operator<(const char *a1, const QByteArray &a2) noexcept
379     { return QtPrivate::compareMemory(a1, a2) < 0; } +/
380     /+ friend inline bool operator<=(const QByteArray &a1, const QByteArray &a2) noexcept
381     { return QtPrivate::compareMemory(QByteArrayView(a1), QByteArrayView(a2)) <= 0; } +/
382     /+ friend inline bool operator<=(const QByteArray &a1, const char *a2) noexcept
383     { return QtPrivate::compareMemory(a1, a2) <= 0; } +/
384     /+ friend inline bool operator<=(const char *a1, const QByteArray &a2) noexcept
385     { return QtPrivate::compareMemory(a1, a2) <= 0; } +/
386     /+ friend inline bool operator>(const QByteArray &a1, const QByteArray &a2) noexcept
387     { return QtPrivate::compareMemory(QByteArrayView(a1), QByteArrayView(a2)) > 0; } +/
388     /+ friend inline bool operator>(const QByteArray &a1, const char *a2) noexcept
389     { return QtPrivate::compareMemory(a1, a2) > 0; } +/
390     /+ friend inline bool operator>(const char *a1, const QByteArray &a2) noexcept
391     { return QtPrivate::compareMemory(a1, a2) > 0; } +/
392     /+ friend inline bool operator>=(const QByteArray &a1, const QByteArray &a2) noexcept
393     { return QtPrivate::compareMemory(QByteArrayView(a1), QByteArrayView(a2)) >= 0; } +/
394     /+ friend inline bool operator>=(const QByteArray &a1, const char *a2) noexcept
395     { return QtPrivate::compareMemory(a1, a2) >= 0; } +/
396     /+ friend inline bool operator>=(const char *a1, const QByteArray &a2) noexcept
397     { return QtPrivate::compareMemory(a1, a2) >= 0; } +/
398 
399     // Check isEmpty() instead of isNull() for backwards compatibility.
400     /+ friend inline bool operator==(const QByteArray &a1, std::nullptr_t) noexcept { return a1.isEmpty(); } +/
401     /+ friend inline bool operator!=(const QByteArray &a1, std::nullptr_t) noexcept { return !a1.isEmpty(); } +/
402     /+ friend inline bool operator< (const QByteArray &  , std::nullptr_t) noexcept { return false; } +/
403     /+ friend inline bool operator> (const QByteArray &a1, std::nullptr_t) noexcept { return !a1.isEmpty(); } +/
404     /+ friend inline bool operator<=(const QByteArray &a1, std::nullptr_t) noexcept { return a1.isEmpty(); } +/
405     /+ friend inline bool operator>=(const QByteArray &  , std::nullptr_t) noexcept { return true; } +/
406 
407     /+ friend inline bool operator==(std::nullptr_t, const QByteArray &a2) noexcept { return a2 == nullptr; } +/
408     /+ friend inline bool operator!=(std::nullptr_t, const QByteArray &a2) noexcept { return a2 != nullptr; } +/
409     /+ friend inline bool operator< (std::nullptr_t, const QByteArray &a2) noexcept { return a2 >  nullptr; } +/
410     /+ friend inline bool operator> (std::nullptr_t, const QByteArray &a2) noexcept { return a2 <  nullptr; } +/
411     /+ friend inline bool operator<=(std::nullptr_t, const QByteArray &a2) noexcept { return a2 >= nullptr; } +/
412     /+ friend inline bool operator>=(std::nullptr_t, const QByteArray &a2) noexcept { return a2 <= nullptr; } +/
413 
414     short toShort(bool* ok = null, int base = 10) const;
415     ushort toUShort(bool* ok = null, int base = 10) const;
416     int toInt(bool* ok = null, int base = 10) const;
417     uint toUInt(bool* ok = null, int base = 10) const;
418     cpp_long toLong(bool* ok = null, int base = 10) const;
419     cpp_ulong toULong(bool* ok = null, int base = 10) const;
420     qlonglong toLongLong(bool* ok = null, int base = 10) const;
421     qulonglong toULongLong(bool* ok = null, int base = 10) const;
422     float toFloat(bool* ok = null) const;
423     double toDouble(bool* ok = null) const;
424     QByteArray toBase64(Base64Options options = Base64Option.Base64Encoding) const;
425     QByteArray toHex(char separator = '\0') const;
426     QByteArray toPercentEncoding(ref const(QByteArray) exclude/* = globalInitVar!QByteArray*/,
427                                      ref const(QByteArray) include/* = globalInitVar!QByteArray*/,
428                                      char percent/* = '%'*/) const;
429 
430     pragma(inline, true) ref QByteArray setNum(short n, int base = 10)
431     { return setNum(qlonglong(n), base); }
432     pragma(inline, true) ref QByteArray setNum(ushort n, int base = 10)
433     { return setNum(qulonglong(n), base); }
434     pragma(inline, true) ref QByteArray setNum(int n, int base = 10)
435     { return setNum(qlonglong(n), base); }
436     pragma(inline, true) ref QByteArray setNum(uint n, int base = 10)
437     { return setNum(qulonglong(n), base); }
438     pragma(inline, true) ref QByteArray setNum(cpp_long n, int base = 10)
439     { return setNum(qlonglong(n), base); }
440     pragma(inline, true) ref QByteArray setNum(cpp_ulong n, int base = 10)
441     { return setNum(qulonglong(n), base); }
442     ref QByteArray setNum(qlonglong, int base = 10);
443     ref QByteArray setNum(qulonglong, int base = 10);
444     pragma(inline, true) ref QByteArray setNum(float n, char format = 'g', int precision = 6)
445     { return setNum(double(n), format, precision); }
446     ref QByteArray setNum(double, char format = 'g', int precision = 6);
447     ref QByteArray setRawData(const(char)* a, qsizetype n);
448 
449     /+ [[nodiscard]] +/ static QByteArray number(int, int base = 10);
450     /+ [[nodiscard]] +/ static QByteArray number(uint, int base = 10);
451     /+ [[nodiscard]] +/ static QByteArray number(cpp_long, int base = 10);
452     /+ [[nodiscard]] +/ static QByteArray number(cpp_ulong, int base = 10);
453     /+ [[nodiscard]] +/ static QByteArray number(qlonglong, int base = 10);
454     /+ [[nodiscard]] +/ static QByteArray number(qulonglong, int base = 10);
455     /+ [[nodiscard]] +/ static QByteArray number(double, char format = 'g', int precision = 6);
456     /+ [[nodiscard]] +/ static QByteArray fromRawData(const(char)* data, qsizetype size)
457     {
458         auto tmp = DataPointer(null, const_cast!(char*)(data), size); return QByteArray(tmp);
459     }
460 
461     /+
462     extern(C++, class) struct FromBase64Result;
463     +/
464     /// Binding for C++ class [FromBase64Result](https://doc.qt.io/qt-6/qbytearray-frombase64result.html).
465     extern(C++, class) struct FromBase64Result
466     {
467     public:
468         QByteArray decoded;
469         Base64DecodingStatus decodingStatus;
470 
471         /+ void swap(QByteArray::FromBase64Result &other) noexcept
472         {
473             qSwap(decoded, other.decoded);
474             qSwap(decodingStatus, other.decodingStatus);
475         } +/
476 
477         /+/+ explicit +/ auto opCast(T : bool)() const/+ noexcept+/ { return decodingStatus == QByteArray.Base64DecodingStatus.Ok; }+/
478 
479     /+ #if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC) +/
480         ref QByteArray opUnary(string op)()/+ & noexcept+/ if(op == "*") { return decoded; }
481         ref const(QByteArray) opUnary(string op)() const/+ & noexcept+/ if(op == "*") { return decoded; }
482         /+ QByteArray &&operator*() && noexcept { return std::move(decoded); } +/
483     /+ #else
484         QByteArray &operator*() noexcept { return decoded; }
485         const QByteArray &operator*() const noexcept { return decoded; }
486     #endif +/
487 
488         /+ friend inline bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
489         {
490             if (lhs.decodingStatus != rhs.decodingStatus)
491                 return false;
492 
493             if (lhs.decodingStatus == QByteArray::Base64DecodingStatus::Ok && lhs.decoded != rhs.decoded)
494                 return false;
495 
496             return true;
497         } +/
498 
499         /+ friend inline bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
500         {
501             return !(lhs == rhs);
502         } +/
503         mixin(CREATE_CONVENIENCE_WRAPPERS);
504     }
505 
506     /+ [[nodiscard]] static FromBase64Result fromBase64Encoding(QByteArray &&base64, Base64Options options = Base64Encoding); +/
507     /+ [[nodiscard]] +/ static FromBase64Result fromBase64Encoding(ref const(QByteArray) base64, Base64Options options = Base64Option.Base64Encoding);
508     /+ [[nodiscard]] +/ static QByteArray fromBase64(ref const(QByteArray) base64, Base64Options options = Base64Option.Base64Encoding);
509     /+ [[nodiscard]] +/ static QByteArray fromHex(ref const(QByteArray) hexEncoded);
510     /+ [[nodiscard]] +/ static QByteArray fromPercentEncoding(ref const(QByteArray) pctEncoded, char percent = '%');
511 
512     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
513     {
514         /+ static QByteArray fromCFData(CFDataRef data); +/
515         /+ static QByteArray fromRawCFData(CFDataRef data); +/
516         /+ CFDataRef toCFData() const Q_DECL_CF_RETURNS_RETAINED; +/
517         /+ CFDataRef toRawCFData() const Q_DECL_CF_RETURNS_RETAINED; +/
518         /+ static QByteArray fromNSData(const NSData *data); +/
519         /+ static QByteArray fromRawNSData(const NSData *data); +/
520         /+ NSData *toNSData() const Q_DECL_NS_RETURNS_AUTORELEASED; +/
521         /+ NSData *toRawNSData() const Q_DECL_NS_RETURNS_AUTORELEASED; +/
522     }
523 
524     alias iterator = char*;
525     alias const_iterator = const(char)*;
526     alias Iterator = iterator;
527     alias ConstIterator = const_iterator;
528     /+ typedef std::reverse_iterator<iterator> reverse_iterator; +/
529     /+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +/
530     pragma(inline, true) iterator begin()
531     { return data(); }
532     pragma(inline, true) const_iterator begin() const
533     { return data(); }
534     pragma(inline, true) const_iterator cbegin() const
535     { return data(); }
536     pragma(inline, true) const_iterator constBegin() const
537     { return data(); }
538     pragma(inline, true) iterator end()
539     { return data() + size(); }
540     pragma(inline, true) const_iterator end() const
541     { return data() + size(); }
542     pragma(inline, true) const_iterator cend() const
543     { return data() + size(); }
544     pragma(inline, true) const_iterator constEnd() const
545     { return data() + size(); }
546     /+ reverse_iterator rbegin() { return reverse_iterator(end()); } +/
547     /+ reverse_iterator rend() { return reverse_iterator(begin()); } +/
548     /+ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } +/
549     /+ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } +/
550     /+ const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } +/
551     /+ const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } +/
552 
553     // stl compatibility
554     alias size_type = qsizetype;
555     alias difference_type = qptrdiff;
556     /+ typedef const char & const_reference; +/
557     /+ typedef char & reference; +/
558     alias pointer = char*;
559     alias const_pointer = const(char)*;
560     alias value_type = char;
561     void push_back(char c)
562     { append(c); }
563     void push_back(const(char)* s)
564     { append(s); }
565     void push_back(ref const(QByteArray) a)
566     { append(a); }
567     void push_back(QByteArrayView a)
568     { append(a); }
569     void push_front(char c)
570     { prepend(c); }
571     void push_front(const(char)* c)
572     { prepend(c); }
573     void push_front(ref const(QByteArray) a)
574     { prepend(a); }
575     void push_front(QByteArrayView a)
576     { prepend(a); }
577     void shrink_to_fit() { squeeze(); }
578     iterator erase(const_iterator first, const_iterator last);
579 
580     /+ static inline QByteArray fromStdString(const std::string &s); +/
581     /+ inline std::string toStdString() const; +/
582 
583     pragma(inline, true) qsizetype size() const { return d.size; }
584     pragma(inline, true) qsizetype count() const { return size(); }
585     pragma(inline, true) qsizetype length() const { return size(); }
586     bool isNull() const;
587 
588     pragma(inline, true) ref DataPointer data_ptr() return { return d; }
589     /+ explicit +/ pragma(inline, true) this(ref DataPointer dd)
590     {
591         this.d = dd;
592     }
593 
594 private:
595     void reallocData(qsizetype alloc, QArrayData.AllocationOption option);
596     void reallocGrowData(qsizetype n);
597     void expand(qsizetype i);
598     QByteArray nulTerminated() const;
599 
600     static QByteArray toLower_helper(ref const(QByteArray) a);
601     static QByteArray toLower_helper(ref QByteArray a);
602     static QByteArray toUpper_helper(ref const(QByteArray) a);
603     static QByteArray toUpper_helper(ref QByteArray a);
604     static QByteArray trimmed_helper(ref const(QByteArray) a);
605     static QByteArray trimmed_helper(ref QByteArray a);
606     static QByteArray simplified_helper(ref const(QByteArray) a);
607     static QByteArray simplified_helper(ref QByteArray a);
608 
609     /+ friend class QString; +/
610     /+ friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, qsizetype nbytes); +/
611     mixin(CREATE_CONVENIENCE_WRAPPERS);
612 }
613 /+pragma(inline, true) QFlags!(QByteArray.Base64Options.enum_type) operator |(QByteArray.Base64Options.enum_type f1, QByteArray.Base64Options.enum_type f2)/+noexcept+/{return QFlags!(QByteArray.Base64Options.enum_type)(f1)|f2;}+/
614 /+pragma(inline, true) QFlags!(QByteArray.Base64Options.enum_type) operator |(QByteArray.Base64Options.enum_type f1, QFlags!(QByteArray.Base64Options.enum_type) f2)/+noexcept+/{return f2|f1;}+/
615 /+pragma(inline, true) QFlags!(QByteArray.Base64Options.enum_type) operator &(QByteArray.Base64Options.enum_type f1, QByteArray.Base64Options.enum_type f2)/+noexcept+/{return QFlags!(QByteArray.Base64Options.enum_type)(f1)&f2;}+/
616 /+pragma(inline, true) QFlags!(QByteArray.Base64Options.enum_type) operator &(QByteArray.Base64Options.enum_type f1, QFlags!(QByteArray.Base64Options.enum_type) f2)/+noexcept+/{return f2&f1;}+/
617 /+pragma(inline, true) void operator +(QByteArray.Base64Options.enum_type f1, QByteArray.Base64Options.enum_type f2)/+noexcept+/;+/
618 /+pragma(inline, true) void operator +(QByteArray.Base64Options.enum_type f1, QFlags!(QByteArray.Base64Options.enum_type) f2)/+noexcept+/;+/
619 /+pragma(inline, true) void operator +(int f1, QFlags!(QByteArray.Base64Options.enum_type) f2)/+noexcept+/;+/
620 /+pragma(inline, true) void operator -(QByteArray.Base64Options.enum_type f1, QByteArray.Base64Options.enum_type f2)/+noexcept+/;+/
621 /+pragma(inline, true) void operator -(QByteArray.Base64Options.enum_type f1, QFlags!(QByteArray.Base64Options.enum_type) f2)/+noexcept+/;+/
622 /+pragma(inline, true) void operator -(int f1, QFlags!(QByteArray.Base64Options.enum_type) f2)/+noexcept+/;+/
623 /+pragma(inline, true) QIncompatibleFlag operator |(QByteArray.Base64Options.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
624 /+pragma(inline, true) void operator +(int f1, QByteArray.Base64Options.enum_type f2)/+noexcept+/;+/
625 /+pragma(inline, true) void operator +(QByteArray.Base64Options.enum_type f1, int f2)/+noexcept+/;+/
626 /+pragma(inline, true) void operator -(int f1, QByteArray.Base64Options.enum_type f2)/+noexcept+/;+/
627 /+pragma(inline, true) void operator -(QByteArray.Base64Options.enum_type f1, int f2)/+noexcept+/;+/
628 
629 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options)#ifndef QT_NO_CAST_FROM_BYTEARRAY
630 #endif +/
631 version(QT_USE_QSTRINGBUILDER){}else
632 {
633 /+pragma(inline, true) const(QByteArray) operator +(ref const(QByteArray) a1, ref const(QByteArray) a2)
634 { return QByteArray(a1) ~= a2; }+/
635 /+pragma(inline, true) const(QByteArray) operator +(ref const(QByteArray) a1, const(char)* a2)
636 { return QByteArray(a1) ~= a2; }+/
637 /+pragma(inline, true) const(QByteArray) operator +(ref const(QByteArray) a1, char a2)
638 { return QByteArray(a1) ~= a2; }+/
639 /+pragma(inline, true) const(QByteArray) operator +(const(char)* a1, ref const(QByteArray) a2)
640 { return QByteArray(a1) ~= a2; }+/
641 /+pragma(inline, true) const(QByteArray) operator +(char a1, ref const(QByteArray) a2)
642 { return QByteArray(&a1, 1) ~= a2; }+/
643 }
644 
645 /+ inline std::string QByteArray::toStdString() const
646 { return std::string(constData(), length()); }
647 
648 inline QByteArray QByteArray::fromStdString(const std::string &s)
649 { return QByteArray(s.data(), qsizetype(s.size())); }
650 
651 #if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED)
652 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &);
653 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QByteArray &);
654 #endif +/
655 
656 version(QT_NO_COMPRESS){}else
657 {
658 /+ Q_CORE_EXPORT +/ QByteArray qCompress(const(uchar)* data, qsizetype nbytes, int compressionLevel = -1);
659 /+ Q_CORE_EXPORT +/ QByteArray qUncompress(const(uchar)* data, qsizetype nbytes);
660 pragma(inline, true) QByteArray qCompress(ref const(QByteArray) data, int compressionLevel = -1)
661 { return qCompress(reinterpret_cast!(const(uchar)*)(data.constData()), data.size(), compressionLevel); }
662 pragma(inline, true) QByteArray qUncompress(ref const(QByteArray) data)
663 { return qUncompress(reinterpret_cast!(const(uchar)*)(data.constData()), data.size()); }
664 }
665 
666 /+ Q_DECLARE_SHARED(QByteArray)
667 
668 Q_DECLARE_SHARED(QByteArray::FromBase64Result)
669 
670 
671 Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray::FromBase64Result &key, size_t seed = 0) noexcept; +/
672 
673 qsizetype erase(T)(ref QByteArray ba, ref const(T) t)
674 {
675     import qt.core.containertools_impl;
676 
677     return /+ QtPrivate:: +/qt.core.containertools_impl.sequential_erase(ba, t);
678 }
679 
680 qsizetype erase_if(Predicate)(ref QByteArray ba, Predicate pred)
681 {
682     import qt.core.containertools_impl;
683 
684     return /+ QtPrivate:: +/qt.core.containertools_impl.sequential_erase_if(ba, pred);
685 }
686 
687 /+ inline namespace QtLiterals {
688 } +/ // QtLiterals
689