4#include <QtCore/qstring.h>
6#ifndef QSTRINGBUILDER_H
7#define QSTRINGBUILDER_H
12#pragma qt_class(QStringBuilder)
13#pragma qt_sync_stop_processing
16#include <QtCore/qbytearray.h>
26 static void convertFromUtf8(QByteArrayView in, QChar *&out)
noexcept;
27 static inline void convertFromAscii(
char a, QChar *&out)
noexcept
29 *out++ = QLatin1Char(a);
31 static void appendLatin1To(QLatin1StringView in, QChar *out)
noexcept;
34template <
typename T>
struct QConcatenable;
37using QConcatenableEx = QConcatenable<q20::remove_cvref_t<T>>;
45 template <
typename T>
using HasIsNull =
decltype(
std::declval<
const T &>().isNull());
46 template <
typename T>
bool isNull(
const T &t)
48 if constexpr (qxp::is_detected_v<HasIsNull, T>)
55template<
typename Builder,
typename T>
62 T
resolved()
const {
return *
static_cast<
const Builder*>(
this); }
65template<
typename Builder,
typename T>
70template<
typename Builder>
71struct QStringBuilderBase<Builder, QString> :
public QStringBuilderCommon<Builder, QString>
73 QByteArray toLatin1()
const {
return this->resolved().toLatin1(); }
74 QByteArray toUtf8()
const {
return this->resolved().toUtf8(); }
75 QByteArray toLocal8Bit()
const {
return this->resolved().toLocal8Bit(); }
78template <
typename A,
typename B>
96 template <
typename T> T convertTo()
const
104 const qsizetype len = Concatenable::size(*
this);
105 T s(len, Qt::Uninitialized);
111 auto d =
reinterpret_cast<
typename T::iterator>(s.data_ptr().data());
112 const auto start = d;
113 Concatenable::appendTo(*
this, d);
115 if constexpr (Concatenable::ExactSize) {
118 if (len != d - start) {
147template <>
struct QConcatenable<
char> :
private QAbstractConcatenable
153#ifndef QT_NO_CAST_FROM_ASCII
156 QAbstractConcatenable::convertFromAscii(c, out);
159 static inline void appendTo(
const char c,
char *&out)
163template <>
struct QConcatenable<QByteArrayView> :
private QAbstractConcatenable
165 typedef QByteArrayView type;
166 typedef QByteArray ConvertTo;
167 enum { ExactSize =
true };
168 static qsizetype size(QByteArrayView bav) {
return bav.size(); }
169#ifndef QT_NO_CAST_FROM_ASCII
170 QT_ASCII_CAST_WARN
static inline void appendTo(QByteArrayView bav, QChar *&out)
172 QAbstractConcatenable::convertFromUtf8(bav, out);
175 static inline void appendTo(QByteArrayView bav,
char *&out)
177 qsizetype n = bav.size();
179 memcpy(out, bav.data(), n);
184template <>
struct QConcatenable<
char16_t> :
private QAbstractConcatenable
190 static inline void appendTo(
char16_t c, QChar *&out)
194template <>
struct QConcatenable<QLatin1Char>
196 typedef QLatin1Char type;
197 typedef QString ConvertTo;
198 enum { ExactSize =
true };
199 static qsizetype size(
const QLatin1Char) {
return 1; }
200 static inline void appendTo(
const QLatin1Char c, QChar *&out)
202 static inline void appendTo(
const QLatin1Char c,
char *&out)
203 { *out++ = c.toLatin1(); }
206template <>
struct QConcatenable<QChar> :
private QAbstractConcatenable
209 typedef QString ConvertTo;
210 enum { ExactSize =
true };
211 static qsizetype size(
const QChar) {
return 1; }
212 static inline void appendTo(
const QChar c, QChar *&out)
216template <>
struct QConcatenable<QChar::SpecialCharacter> :
private QAbstractConcatenable
218 typedef QChar::SpecialCharacter type;
219 typedef QString ConvertTo;
220 enum { ExactSize =
true };
221 static qsizetype size(
const QChar::SpecialCharacter) {
return 1; }
222 static inline void appendTo(
const QChar::SpecialCharacter c, QChar *&out)
226template <>
struct QConcatenable<QLatin1StringView> :
private QAbstractConcatenable
228 typedef QLatin1StringView type;
229 typedef QString ConvertTo;
230 enum { ExactSize =
true };
231 static qsizetype size(
const QLatin1StringView a) {
return a.size(); }
232 static inline void appendTo(
const QLatin1StringView a, QChar *&out)
234 appendLatin1To(a, out);
237 static inline void appendTo(
const QLatin1StringView a,
char *&out)
239 if (
const char *data = a.data()) {
240 memcpy(out, data, a.size());
246template <>
struct QConcatenable<QString> :
private QAbstractConcatenable
248 typedef QString type;
249 typedef QString ConvertTo;
250 enum { ExactSize =
true };
251 static qsizetype size(
const QString &a) {
return a.size(); }
252 static inline void appendTo(
const QString &a, QChar *&out)
254 const qsizetype n = a.size();
256 memcpy(out,
reinterpret_cast<
const char*>(a.constData()),
sizeof(QChar) * n);
261template <>
struct QConcatenable<QStringView> :
private QAbstractConcatenable
263 typedef QStringView type;
264 typedef QString ConvertTo;
265 enum { ExactSize =
true };
266 static qsizetype size(QStringView a) {
return a.size(); }
267 static inline void appendTo(QStringView a, QChar *&out)
269 const auto n = a.size();
271 memcpy(out, a.data(),
sizeof(QChar) * n);
276template <qsizetype N>
struct QConcatenable<
const char[N]> :
private QAbstractConcatenable
282#ifndef QT_NO_CAST_FROM_ASCII
285 QAbstractConcatenable::convertFromUtf8(QByteArrayView(a, N - 1), out);
288 static inline void appendTo(
const char a[N],
char *&out)
295template <qsizetype N>
struct QConcatenable<
char[N]> : QConcatenable<
const char[N]>
300template <>
struct QConcatenable<
const char *> :
private QAbstractConcatenable
306#ifndef QT_NO_CAST_FROM_ASCII
308 { QAbstractConcatenable::convertFromUtf8(QByteArrayView(a), out); }
310 static inline void appendTo(
const char *a,
char *&out)
319template <>
struct QConcatenable<
char *> : QConcatenable<
const char*>
324template <qsizetype N>
struct QConcatenable<
const char16_t[N]> :
private QAbstractConcatenable
326 using type =
const char16_t[N];
327 using ConvertTo = QString;
330 static void appendTo(
const char16_t a[N], QChar *&out)
332 memcpy(
static_cast<
void *>(out), a, (N - 1) *
sizeof(
char16_t));
337template <qsizetype N>
struct QConcatenable<
char16_t[N]> : QConcatenable<
const char16_t[N]>
339 using type =
char16_t[N];
342template <>
struct QConcatenable<
const char16_t *> :
private QAbstractConcatenable
344 using type =
const char16_t *;
345 using ConvertTo = QString;
357template <>
struct QConcatenable<
char16_t *> : QConcatenable<
const char16_t*>
362template <>
struct QConcatenable<QByteArray> :
private QAbstractConcatenable
364 typedef QByteArray type;
365 typedef QByteArray ConvertTo;
366 enum { ExactSize =
false };
367 static qsizetype size(
const QByteArray &ba) {
return ba.size(); }
368#ifndef QT_NO_CAST_FROM_ASCII
369 QT_ASCII_CAST_WARN
static inline void appendTo(
const QByteArray &ba, QChar *&out)
371 QAbstractConcatenable::convertFromUtf8(ba, out);
374 static inline void appendTo(
const QByteArray &ba,
char *&out)
376 const qsizetype n = ba.size();
378 memcpy(out, ba.begin(), n);
384template <
typename A,
typename B>
388 using ConvertTo =
typename QtStringBuilder::ConvertToTypeHelper<
389 typename QConcatenableEx<A>::ConvertTo,
390 typename QConcatenableEx<B>::ConvertTo
392 enum {
ExactSize = QConcatenableEx<A>::ExactSize && QConcatenableEx<B>::ExactSize };
395 return QConcatenableEx<A>::size(p.a) + QConcatenableEx<B>::size(p.b);
397 template<
typename T>
static inline void appendTo(
const type &p, T *&out)
399 QConcatenableEx<A>::appendTo(p.a, out);
400 QConcatenableEx<B>::appendTo(p.b, out);
404template <
typename A,
typename B,
405 typename = std::void_t<
typename QConcatenableEx<A>::type,
typename QConcatenableEx<B>::type>>
406auto operator%(A &&a, B &&b)
408 return QStringBuilder<A, B>(std::forward<A>(a), std::forward<B>(b));
413#if defined(QT_USE_FAST_OPERATOR_PLUS) || defined(QT_USE_QSTRINGBUILDER)
414template <
typename A,
typename B,
415 typename = std::void_t<
typename QConcatenableEx<A>::type,
typename QConcatenableEx<B>::type>>
416auto operator+(A &&a, B &&b)
418 return std::forward<A>(a) % std::forward<B>(b);
423template <
typename A,
typename B>
427 qsizetype len = a.size() + QConcatenable< QStringBuilder<A, B> >::size(b);
429 if (len > a.data_ptr().freeSpaceAtEnd())
430 a.reserve(qMax(len, 2 * a.capacity()));
431 char *it = a.data() + a.size();
437#ifndef QT_NO_CAST_TO_ASCII
438template <
typename A,
typename B>
441 return a += QString(b).toUtf8();
446template <
typename A,
typename B>
450 typename QConcatenable<
QStringBuilder<A, B> >::ConvertTo::value_type());
453template <
typename A,
typename B>
456 qsizetype len = a.size() + QConcatenable< QStringBuilder<A, B> >::size(b);
458 if (len > a.data_ptr().freeSpaceAtEnd())
459 a.reserve(qMax(len, 2 * a.capacity()));
460 QChar *it = a.data() + a.size();
463 a.resize(it - a.constData());
~QAbstractFileEngineHandlerList()
\inmodule QtCore\reentrant
QDateTime birthTime(const QTimeZone &tz) const
QDateTime metadataChangeTime(const QTimeZone &tz) const
Q_CORE_EXPORT bool isReadable() const
Q_CORE_EXPORT bool isHidden() const
Q_CORE_EXPORT bool isWritable() const
Q_CORE_EXPORT bool isExecutable() const
Q_CORE_EXPORT bool isFile() const
Q_CORE_EXPORT bool exists() const
Q_CORE_EXPORT bool isSymLink() const
Q_CORE_EXPORT bool isDir() const
QDateTime lastRead(const QTimeZone &tz) const
See the QFileInfo methods with the same names.
QDateTime lastModified(const QTimeZone &tz) const
const_iterator(const_iterator &&) noexcept=default
reference operator*() const
Returns a {const QDirListing::DirEntry &} of the directory entry this iterator points to.
friend bool operator==(sentinel, const const_iterator &rhs) noexcept
const_iterator & operator=(const_iterator &&) noexcept=default
pointer operator->() const
Returns a {const QDirListing::DirEntry *} to the directory entry this iterator points to.
friend bool operator!=(sentinel, const const_iterator &rhs) noexcept
friend bool operator!=(const const_iterator &lhs, sentinel) noexcept
const_iterator & operator++()
Pre-increment operator.
friend bool operator==(const const_iterator &lhs, sentinel) noexcept
\typealias QDirListing::const_iterator::reference
friend constexpr bool operator==(sentinel, sentinel) noexcept
friend constexpr bool operator!=(sentinel, sentinel) noexcept
IteratorFlag
This enum class describes flags that can be used to configure the behavior of QDirListing.
const_iterator cbegin() const
QDirListing(QDirListing &&other) noexcept
const_iterator constBegin() const
sentinel constEnd() const
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QStringBuilder(A &&a_, B &&b_)
Concatenable::ConvertTo ConvertTo
operator ConvertTo() const
QStringBuilder(QStringBuilder &&)=default
QStringBuilder(const QStringBuilder &)=default
~QStringBuilder()=default
Emulated const pointer to QVariant based on a pointer.
QVariantPointer is a template class that emulates a pointer to QVariant based on a pointer.
QVariantPointer(const Pointer *pointer)
Constructs a QVariantPointer from the given pointer.
QVariantRef< Pointer > operator*() const
Dereferences the QVariantPointer to a QVariantRef.
Pointer operator->() const
Dereferences and returns the pointer.
The QVariantRef acts as a non-const reference to a QVariant.
operator QVariant() const
Resolves the QVariantRef to an actual QVariant.
QVariantRef & operator=(const QVariantRef &value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
QVariantRef & operator=(const QVariant &value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
QVariantRef(const QVariantRef &)=default
QVariantRef(QVariantRef &&)=default
friend void swap(QVariantRef a, QVariantRef b)
QVariantRef & operator=(QVariantRef &&value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
QVariantRef(const Pointer *reference)
Creates a QVariantRef from an pointer.
Combined button and popup list for selecting options.
QByteArray & appendToByteArray(QByteArray &a, const QStringBuilder< A, B > &b, QChar)
QByteArray & appendToByteArray(QByteArray &a, const QStringBuilder< A, B > &b, char)
static QString appendSlashIfNeeded(const QString &path)
QByteArray & operator+=(QByteArray &a, const QStringBuilder< A, B > &b)
T qvariant_cast(QVariant &&v)
T qvariant_cast(const QVariant &)
void swap(QVariant &value1, QVariant &value2) noexcept
static void appendTo(const type &p, T *&out)
static qsizetype size(const type &p)
QStringBuilder< A, B > type
static void appendTo(char16_t c, QChar *&out)
static constexpr qsizetype size(char16_t)
static QT_ASCII_CAST_WARN void appendTo(const char c, QChar *&out)
static qsizetype size(const char)
static void appendTo(const char c, char *&out)
static QT_ASCII_CAST_WARN void appendTo(const char16_t *a, QChar *&out)
static qsizetype size(const char16_t *a)
static qsizetype size(const char16_t[N])
static void appendTo(const char16_t a[N], QChar *&out)
static QT_ASCII_CAST_WARN void appendTo(const char *a, QChar *&out)
static void appendTo(const char *a, char *&out)
static qsizetype size(const char *a)
static void appendTo(const char a[N], char *&out)
static qsizetype size(const char[N])
static QT_ASCII_CAST_WARN void appendTo(const char a[N], QChar *&out)