diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-06-22 11:44:34 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-06-23 06:31:28 +0000 |
commit | 44da43e8e42272c61cf12c05314387c785bd9749 (patch) | |
tree | 5a57ddebd03eb55e937e48fff310d08cedaf5f58 /src | |
parent | 1304040e5d5af0575cac43aaf1424f72472c7b23 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 6 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 8 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 5 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 7b86279670..6341d060f1 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1233,6 +1233,12 @@ #endif /* + * "Weak overloads" - makes an otherwise confliciting overload weaker + * (by making it a template) + */ +#define Q_WEAK_OVERLOAD template <typename = void> + +/* * Warning/diagnostic handling */ diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 16e9f1d63b..dff0dbce7f 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -5098,6 +5098,14 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) */ /*! + \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) \overload \since 5.0 diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index f14644d956..b77c6134d5 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -658,6 +658,11 @@ public: { 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) { return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size); |