mirror of https://github.com/qt/qtbase.git
QString: add char8_t overload of fromUtf8()
Use the overload-with-template trick from P1423 to avoid ambiguities when existing callers pass 0 or nullptr. Add a qdoc-ignored macro to hide the fact that the overload is a template. [ChangeLog][QtCore][QString] Added char8_t overload of fromUtf8(). Change-Id: Iaa2d365bfa161ef36cc73fa3bad50aabf34d01db Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1304040e5d
commit
44da43e8e4
|
@ -132,6 +132,7 @@ Cpp.ignoretokens += \
|
||||||
Q_SVG_EXPORT \
|
Q_SVG_EXPORT \
|
||||||
Q_TESTLIB_EXPORT \
|
Q_TESTLIB_EXPORT \
|
||||||
Q_TYPENAME \
|
Q_TYPENAME \
|
||||||
|
Q_WEAK_OVERLOAD \
|
||||||
Q_WIDGETS_EXPORT \
|
Q_WIDGETS_EXPORT \
|
||||||
Q_WINEXTRAS_EXPORT \
|
Q_WINEXTRAS_EXPORT \
|
||||||
Q_XML_EXPORT \
|
Q_XML_EXPORT \
|
||||||
|
|
|
@ -1232,6 +1232,12 @@
|
||||||
# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) (x)
|
# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) (x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "Weak overloads" - makes an otherwise confliciting overload weaker
|
||||||
|
* (by making it a template)
|
||||||
|
*/
|
||||||
|
#define Q_WEAK_OVERLOAD template <typename = void>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Warning/diagnostic handling
|
* Warning/diagnostic handling
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5097,6 +5097,14 @@ QString QString::fromLocal8Bit_helper(const char *str, int size)
|
||||||
\sa toUtf8(), fromLatin1(), fromLocal8Bit()
|
\sa toUtf8(), fromLatin1(), fromLocal8Bit()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QString QString::fromUtf8(const char8_t *str, qsizetype size)
|
||||||
|
\overload
|
||||||
|
\since 6.0
|
||||||
|
|
||||||
|
This overload is only available when compiling in C++20 mode.
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QString QString::fromUtf8(const QByteArray &str)
|
\fn QString QString::fromUtf8(const QByteArray &str)
|
||||||
\overload
|
\overload
|
||||||
|
|
|
@ -658,6 +658,11 @@ public:
|
||||||
{
|
{
|
||||||
return fromUtf8_helper(str, (str && size == -1) ? int(strlen(str)) : size);
|
return fromUtf8_helper(str, (str && size == -1) ? int(strlen(str)) : size);
|
||||||
}
|
}
|
||||||
|
#ifdef __cpp_char8_t
|
||||||
|
Q_WEAK_OVERLOAD
|
||||||
|
static inline QString fromUtf8(const char8_t *str, qsizetype size = -1)
|
||||||
|
{ return fromUtf8(reinterpret_cast<const char *>(str), int(size)); }
|
||||||
|
#endif
|
||||||
static inline QString fromLocal8Bit(const char *str, int size = -1)
|
static inline QString fromLocal8Bit(const char *str, int size = -1)
|
||||||
{
|
{
|
||||||
return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size);
|
return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size);
|
||||||
|
|
|
@ -3,7 +3,8 @@ TARGET = tst_qstring
|
||||||
QT = core-private testlib
|
QT = core-private testlib
|
||||||
SOURCES = tst_qstring.cpp
|
SOURCES = tst_qstring.cpp
|
||||||
# DEFINES += QT_NO_CAST_TO_ASCII # actively #undef-ed by tst_qstring.cpp
|
# DEFINES += QT_NO_CAST_TO_ASCII # actively #undef-ed by tst_qstring.cpp
|
||||||
qtConfig(c++11): CONFIG += c++11
|
qtConfig(c++1z): CONFIG += c++1z
|
||||||
|
qtConfig(c++2a): CONFIG += c++2a
|
||||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
||||||
|
|
||||||
!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) {
|
!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) {
|
||||||
|
|
|
@ -4216,9 +4216,15 @@ void tst_QString::nullFromUtf8()
|
||||||
a = QString::fromUtf8(0);
|
a = QString::fromUtf8(0);
|
||||||
QVERIFY(a.isNull());
|
QVERIFY(a.isNull());
|
||||||
QVERIFY(a.isEmpty());
|
QVERIFY(a.isEmpty());
|
||||||
|
a = QString::fromUtf8(nullptr);
|
||||||
|
QVERIFY(a.isNull());
|
||||||
|
QVERIFY(a.isEmpty());
|
||||||
a = QString::fromUtf8("");
|
a = QString::fromUtf8("");
|
||||||
QVERIFY(!a.isNull());
|
QVERIFY(!a.isNull());
|
||||||
QVERIFY(a.isEmpty());
|
QVERIFY(a.isEmpty());
|
||||||
|
a = QString::fromUtf8(u8""); // char in C++17 / char8_t in C++20
|
||||||
|
QVERIFY(!a.isNull());
|
||||||
|
QVERIFY(a.isEmpty());
|
||||||
a = QString::fromUtf8(QByteArray());
|
a = QString::fromUtf8(QByteArray());
|
||||||
QVERIFY(a.isNull());
|
QVERIFY(a.isNull());
|
||||||
QVERIFY(a.isEmpty());
|
QVERIFY(a.isEmpty());
|
||||||
|
|
Loading…
Reference in New Issue