summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2024-10-31 13:45:42 +0100
committerMarc Mutz <[email protected]>2025-06-30 17:45:40 +0000
commite9f91f049cb710b97d50a12306eca577be09b6ab (patch)
tree661923389a419b20b72ac06116ce87aeb7d45537 /src
parent6b968b3f1393fa510d93a5e7e63a20648ad8baae (diff)
QAnyStringView: support single wchar_t arguments also on UnixHEADdev
We support char32_t, so there's no reason to not support a 4-byte-wchar_t. This also fixes a nasty asymmery between QString::arg(L'ä') (integral output) and QL1SV::arg(L'ä') or QString::arg(L'ä', L'ä') (characters) [ChangeLog][Important Behavior Changes][QtCore][QString] The unary arg() function now treats wchar_t as a character (string-like; was: integer), so u"%1".arg(L'ø') will now return "ø" and not '248". This makes the function consistent with both QString multi-arg() and QLatin1StringView::arg(). [ChangeLog][QtCore][QAnyStringView] Supports construction from a single wchar_t on all platforms now (was: only on Windows). Fixes: QTBUG-126054 Pick-to: 6.10 Change-Id: I21b7a9782f03d04686207db30d1b1c9d50bc8169 Reviewed-by: Thiago Macieira <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qanystringview.cpp1
-rw-r--r--src/corelib/text/qanystringview.h12
-rw-r--r--src/corelib/text/qstring.h3
3 files changed, 12 insertions, 4 deletions
diff --git a/src/corelib/text/qanystringview.cpp b/src/corelib/text/qanystringview.cpp
index 717b53f06c2..7bf8a3fa1fd 100644
--- a/src/corelib/text/qanystringview.cpp
+++ b/src/corelib/text/qanystringview.cpp
@@ -138,6 +138,7 @@ QT_BEGIN_NAMESPACE
\list
\li \c QLatin1Char
\li \c QChar::SpecialCharacter
+ \li \c wchar_t (where it's a 32-bit type, i.e. Unix) (since 6.10)
\li \c char32_t
\endlist
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h
index 4b89fa6edbf..079cf751af1 100644
--- a/src/corelib/text/qanystringview.h
+++ b/src/corelib/text/qanystringview.h
@@ -25,6 +25,11 @@ struct wrapped { using type = Result; };
template <typename Tag, typename Result>
using wrapped_t = typename wrapped<Tag, Result>::type;
+template <typename Char>
+struct is_compatible_utf32_char : std::false_type {};
+template <> struct is_compatible_utf32_char<char32_t> : std::true_type {};
+template <> struct is_compatible_utf32_char<wchar_t> : std::bool_constant<sizeof(wchar_t) == 4> {};
+
} // namespace QtPrivate
class QAnyStringView
@@ -60,6 +65,11 @@ private:
};
template <typename Char>
+ using if_compatible_utf32_char = std::enable_if_t<
+ QtPrivate::is_compatible_utf32_char<Char>::value
+ , bool>;
+
+ template <typename Char>
using is_compatible_char = std::disjunction<
QtPrivate::IsCompatibleCharType<Char>,
QtPrivate::IsCompatibleChar8Type<Char>
@@ -220,7 +230,7 @@ public:
constexpr QAnyStringView(Char ch, QCharContainer &&capacity = QCharContainer()) noexcept
: QAnyStringView{&(capacity.ch = ch), 1} {}
template <typename Char, typename Container = decltype(QChar::fromUcs4(U'x')),
- std::enable_if_t<std::is_same_v<Char, char32_t>, bool> = true>
+ if_compatible_utf32_char<Char> = true>
constexpr QAnyStringView(Char c, Container &&capacity = {}) noexcept
: QAnyStringView(capacity = QChar::fromUcs4(c)) {}
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 09cfbdfe94d..e4f06835bd1 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -66,9 +66,6 @@ template <> struct treat_as_integral_arg<unsigned short> : std::true_type {};
template <> struct treat_as_integral_arg< signed short> : std::true_type {};
template <> struct treat_as_integral_arg<unsigned char> : std::true_type {};
template <> struct treat_as_integral_arg< signed char> : std::true_type {};
-// QTBUG-126054, keep until we can fix it for all platforms, not just Windows
-// (where wchar_t does convert to QAnyStringView):
-template <> struct treat_as_integral_arg<wchar_t> : std::true_type {};
}
// Qt 4.x compatibility