QStringBuilder: add support for QStringView
[ChangeLog][QtCore][QStringBuilder] Added support for QStringView. Change-Id: I5b6803397b107ef69d198a935b3ba4339ac95087 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
641e010cc7
commit
9c53f4d33a
@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE
|
||||
For building QStrings:
|
||||
|
||||
\list
|
||||
\li QString, QStringRef,
|
||||
\li QString, QStringRef, (since 5.10:) QStringView
|
||||
\li QChar, QCharRef, QLatin1Char, (since 5.10:) \c char16_t,
|
||||
\li QLatin1String,
|
||||
\li (since 5.10:) \c{const char16_t[]} (\c{u"foo"}),
|
||||
|
@ -289,6 +289,20 @@ template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct QConcatenable<QStringView> : private QAbstractConcatenable
|
||||
{
|
||||
typedef QStringView type;
|
||||
typedef QString ConvertTo;
|
||||
enum { ExactSize = true };
|
||||
static int size(QStringView a) { return a.length(); }
|
||||
static inline void appendTo(QStringView a, QChar *&out)
|
||||
{
|
||||
const auto n = a.size();
|
||||
memcpy(out, a.data(), sizeof(QChar) * n);
|
||||
out += n;
|
||||
}
|
||||
};
|
||||
|
||||
template <int N> struct QConcatenable<const char[N]> : private QAbstractConcatenable
|
||||
{
|
||||
typedef const char type[N];
|
||||
|
@ -60,6 +60,7 @@ template <typename T> QString toQString(const T &t);
|
||||
|
||||
template <> QString toQString(const QString &s) { return s; }
|
||||
template <> QString toQString(const QStringRef &r) { return r.toString(); }
|
||||
template <> QString toQString(const QStringView &v) { return v.toString(); }
|
||||
template <> QString toQString(const QLatin1String &l) { return l; }
|
||||
template <> QString toQString(const QLatin1Char &l) { return QChar(l); }
|
||||
template <> QString toQString(const QChar &c) { return c; }
|
||||
@ -84,6 +85,7 @@ void runScenario()
|
||||
QLatin1String l1string(LITERAL);
|
||||
QString string(l1string);
|
||||
QStringRef stringref(&string, 2, 10);
|
||||
QStringView stringview(stringref);
|
||||
QLatin1Char lchar('c');
|
||||
QChar qchar(lchar);
|
||||
QChar::SpecialCharacter special(QChar::Nbsp);
|
||||
@ -108,6 +110,7 @@ void runScenario()
|
||||
CHECK(P, l1string, l1string);
|
||||
CHECK(P, l1string, string);
|
||||
CHECK(P, l1string, stringref);
|
||||
CHECK(Q, l1string, stringview);
|
||||
CHECK(P, l1string, lchar);
|
||||
CHECK(P, l1string, qchar);
|
||||
CHECK(P, l1string, special);
|
||||
@ -118,6 +121,7 @@ void runScenario()
|
||||
|
||||
CHECK(P, string, string);
|
||||
CHECK(P, string, stringref);
|
||||
CHECK(Q, string, stringview);
|
||||
CHECK(P, string, lchar);
|
||||
CHECK(P, string, qchar);
|
||||
CHECK(P, string, special);
|
||||
@ -127,6 +131,7 @@ void runScenario()
|
||||
CHECK(Q, string, u16charstar);
|
||||
|
||||
CHECK(P, stringref, stringref);
|
||||
CHECK(Q, stringref, stringview);
|
||||
CHECK(P, stringref, lchar);
|
||||
CHECK(P, stringref, qchar);
|
||||
CHECK(P, stringref, special);
|
||||
@ -135,6 +140,15 @@ void runScenario()
|
||||
CHECK(Q, stringref, u16chararray);
|
||||
CHECK(Q, stringref, u16charstar);
|
||||
|
||||
CHECK(Q, stringview, stringview);
|
||||
CHECK(Q, stringview, lchar);
|
||||
CHECK(Q, stringview, qchar);
|
||||
CHECK(Q, stringview, special);
|
||||
CHECK(P, stringview, QStringLiteral(LITERAL));
|
||||
CHECK(Q, stringview, u16char);
|
||||
CHECK(Q, stringview, u16chararray);
|
||||
CHECK(Q, stringview, u16charstar);
|
||||
|
||||
CHECK(P, lchar, lchar);
|
||||
CHECK(P, lchar, qchar);
|
||||
CHECK(P, lchar, special);
|
||||
|
Loading…
Reference in New Issue
Block a user