Merge integration refs/builds/qtci/dev/1617098611
This commit is contained in:
commit
31c81e08c6
@ -4766,6 +4766,27 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA
|
||||
\sa QStringLiteral
|
||||
*/
|
||||
|
||||
/*!
|
||||
\function QtLiterals::operator""_qba(const char *str, size_t size)
|
||||
|
||||
\relates QByteArray
|
||||
\since 6.2
|
||||
|
||||
Literal operator that creates a QByteArray out of a char string literal \a
|
||||
str. Creating a QByteArray from it is free in this case, and the generated
|
||||
string data is stored in the read-only segment of the compiled object file.
|
||||
Duplicate literals may share the same read-only memory. This functionality is
|
||||
interchangeable with QByteArrayLiteral, but saves typing when many string
|
||||
literals are present in the code.
|
||||
|
||||
The following code creates a QByteArray:
|
||||
\code
|
||||
auto str = "hello"_qba;
|
||||
\endcode
|
||||
|
||||
\sa QByteArrayLiteral, QtLiterals::operator""_qs(const char16_t *str, size_t size)
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QByteArray::FromBase64Result
|
||||
\inmodule QtCore
|
||||
|
@ -756,6 +756,13 @@ QByteArray QByteArrayView::toByteArray() const
|
||||
return QByteArray(data(), size());
|
||||
}
|
||||
|
||||
inline namespace QtLiterals {
|
||||
inline QByteArray operator"" _qba(const char *str, size_t size) noexcept
|
||||
{
|
||||
return QByteArray(QByteArrayData(nullptr, const_cast<char *>(str), qsizetype(size)));
|
||||
}
|
||||
} // QtLiterals
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QBYTEARRAY_H
|
||||
|
@ -10505,6 +10505,27 @@ QString QString::toHtmlEscaped() const
|
||||
\sa QByteArrayLiteral
|
||||
*/
|
||||
|
||||
/*!
|
||||
\function QtLiterals::operator""_qs(const char16_t *str, size_t size)
|
||||
|
||||
\relates QString
|
||||
\since 6.2
|
||||
|
||||
Literal operator that creates a QString out of a char16_t string literal \a
|
||||
str. Creating a QString from it is free in this case, and the generated string
|
||||
data is stored in the read-only segment of the compiled object file. Duplicate
|
||||
literals may share the same read-only memory. This functionality is
|
||||
interchangeable with QStringLiteral, but saves typing when many string
|
||||
literals are present in the code.
|
||||
|
||||
The following code creates a QString:
|
||||
\code
|
||||
auto str = u"hello"_qs;
|
||||
\endcode
|
||||
|
||||
\sa QStringLiteral, QtLiterals::operator""_qba(const char *str, size_t size)
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
|
@ -1541,6 +1541,13 @@ qsizetype erase_if(QString &s, Predicate pred)
|
||||
return QtPrivate::sequential_erase_if(s, pred);
|
||||
}
|
||||
|
||||
inline namespace QtLiterals {
|
||||
inline QString operator"" _qs(const char16_t *str, size_t size) noexcept
|
||||
{
|
||||
return QString(QStringPrivate(nullptr, const_cast<char16_t *>(str), qsizetype(size)));
|
||||
}
|
||||
} // QtLiterals
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#if defined(QT_USE_FAST_OPERATOR_PLUS) || defined(QT_USE_QSTRINGBUILDER)
|
||||
|
@ -126,6 +126,7 @@ private slots:
|
||||
void movablity_data();
|
||||
void movablity();
|
||||
void literals();
|
||||
void userDefinedLiterals();
|
||||
void toUpperLower_data();
|
||||
void toUpperLower();
|
||||
void isUpper();
|
||||
@ -1967,7 +1968,6 @@ void tst_QByteArray::movablity()
|
||||
QVERIFY(true);
|
||||
}
|
||||
|
||||
// Only tested on c++0x compliant compiler or gcc
|
||||
void tst_QByteArray::literals()
|
||||
{
|
||||
QByteArray str(QByteArrayLiteral("abcd"));
|
||||
@ -1991,6 +1991,29 @@ void tst_QByteArray::literals()
|
||||
QVERIFY(str2.capacity() >= str2.length());
|
||||
}
|
||||
|
||||
void tst_QByteArray::userDefinedLiterals()
|
||||
{
|
||||
QByteArray str = "abcd"_qba;
|
||||
|
||||
QVERIFY(str.length() == 4);
|
||||
QCOMPARE(str.capacity(), 0);
|
||||
QVERIFY(str == "abcd");
|
||||
QVERIFY(!str.data_ptr()->isMutable());
|
||||
|
||||
const char *s = str.constData();
|
||||
QByteArray str2 = str;
|
||||
QVERIFY(str2.constData() == s);
|
||||
QCOMPARE(str2.capacity(), 0);
|
||||
|
||||
// detach on non const access
|
||||
QVERIFY(str.data() != s);
|
||||
QVERIFY(str.capacity() >= str.length());
|
||||
|
||||
QVERIFY(str2.constData() == s);
|
||||
QVERIFY(str2.data() != s);
|
||||
QVERIFY(str2.capacity() >= str2.length());
|
||||
}
|
||||
|
||||
void tst_QByteArray::toUpperLower_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("input");
|
||||
|
@ -566,9 +566,8 @@ private slots:
|
||||
#if QT_CONFIG(icu)
|
||||
void toUpperLower_icu();
|
||||
#endif
|
||||
#if !defined(QT_NO_UNICODE_LITERAL)
|
||||
void literals();
|
||||
#endif
|
||||
void userDefinedLiterals();
|
||||
void eightBitLiterals_data();
|
||||
void eightBitLiterals();
|
||||
void reserve();
|
||||
@ -6419,8 +6418,6 @@ void tst_QString::toUpperLower_icu()
|
||||
}
|
||||
#endif // icu
|
||||
|
||||
#if !defined(QT_NO_UNICODE_LITERAL)
|
||||
// Only tested on c++0x compliant compiler or gcc
|
||||
void tst_QString::literals()
|
||||
{
|
||||
QString str(QStringLiteral("abcd"));
|
||||
@ -6443,7 +6440,29 @@ void tst_QString::literals()
|
||||
QVERIFY(str2.data() != s);
|
||||
QVERIFY(str2.capacity() >= str2.length());
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QString::userDefinedLiterals()
|
||||
{
|
||||
QString str = u"abcd"_qs;
|
||||
|
||||
QVERIFY(str.length() == 4);
|
||||
QCOMPARE(str.capacity(), 0);
|
||||
QVERIFY(str == QLatin1String("abcd"));
|
||||
QVERIFY(!str.data_ptr()->isMutable());
|
||||
|
||||
const QChar *s = str.constData();
|
||||
QString str2 = str;
|
||||
QVERIFY(str2.constData() == s);
|
||||
QCOMPARE(str2.capacity(), 0);
|
||||
|
||||
// detach on non const access
|
||||
QVERIFY(str.data() != s);
|
||||
QVERIFY(str.capacity() >= str.length());
|
||||
|
||||
QVERIFY(str2.constData() == s);
|
||||
QVERIFY(str2.data() != s);
|
||||
QVERIFY(str2.capacity() >= str2.length());
|
||||
}
|
||||
|
||||
void tst_QString::eightBitLiterals_data()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user