diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-06-09 17:30:54 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-06-09 17:30:54 +0300 |
commit | da6e958319e95fe564d3b30c931492dd666bfaff (patch) | |
tree | 16ac1556a573daeba5c9c4b795f86aa166ffe467 /src/xml/dom/qdom.cpp | |
parent | 29400a683f96867133b28299c0d0bd6bcf40df35 (diff) | |
parent | a96fc76fa78f3500266b3a34016f9e1bd29b319c (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.11' into tqtc/lts-5.15-opensourcev5.15.11-lts-lgpl
Change-Id: Iac056a5e9f59fc8d1929171c18039aeb45be22b8
Diffstat (limited to 'src/xml/dom/qdom.cpp')
-rw-r--r-- | src/xml/dom/qdom.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 104ed1b48e..45da7f961d 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -62,7 +62,7 @@ #include <qdebug.h> #include <qxmlstream.h> #include <private/qduplicatetracker_p.h> - +#include <private/qstringiterator_p.h> #include <stdio.h> #include <limits> @@ -192,11 +192,26 @@ static QString fixedCharData(const QString &data, bool *ok) return data; } + // Copied from QChar::fromUcs4() implementation in Qt 6 + auto fromUcs4 = [](char32_t c) noexcept { + struct R { + char16_t chars[2]; + operator QStringView() const noexcept { return {begin(), end()}; } + qsizetype size() const noexcept { return chars[1] ? 2 : 1; } + const char16_t *begin() const noexcept { return chars; } + const char16_t *end() const noexcept { return begin() + size(); } + }; + if (QChar::requiresSurrogates(c)) + return R{{QChar::highSurrogate(c), QChar::lowSurrogate(c)}}; + return R{{char16_t(c), u'\0'}}; + }; + QString result; - for (int i = 0; i < data.size(); ++i) { - QChar c = data.at(i); + QStringIterator it(data); + while (it.hasNext()) { + const char32_t c = it.next(QChar::Null); if (QXmlUtils::isChar(c)) { - result.append(c); + result.append(fromUcs4(c)); } else if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) { *ok = false; return QString(); |