diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-05-09 16:19:28 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-05-11 13:17:09 +0200 |
commit | 255cc55d74b55dfbecd9af0ea8d39aaf181da4ce (patch) | |
tree | 97024af77c5c83c7e075a8dd6d7661b5aee6fc61 | |
parent | 3bc9f357714ab7e59cbdf28d0b449d3069dea401 (diff) |
QXmlStreamReader: port Private::put...() to QStringView
This enables the use of QChar::fromUcs4() instead of
QString::fromUcs4() in a call to putStringLiteral().
Change-Id: I6ed933cc92bfbb70ed2b168b7deeeb466bc6bfeb
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/serialization/qxmlstream.cpp | 28 | ||||
-rw-r--r-- | src/corelib/serialization/qxmlstream.g | 16 | ||||
-rw-r--r-- | src/corelib/serialization/qxmlstream_p.h | 16 |
3 files changed, 28 insertions, 32 deletions
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp index 563fc6ff97..9391b3861a 100644 --- a/src/corelib/serialization/qxmlstream.cpp +++ b/src/corelib/serialization/qxmlstream.cpp @@ -1458,36 +1458,40 @@ inline int QXmlStreamReaderPrivate::fastScanNMTOKEN() return n; } -void QXmlStreamReaderPrivate::putString(const QString &s, int from) +void QXmlStreamReaderPrivate::putString(QStringView s, qsizetype from) { + if (from != 0) { + putString(s.mid(from)); + return; + } putStack.reserve(s.size()); - for (int i = s.size()-1; i >= from; --i) - putStack.rawPush() = s.at(i).unicode(); + for (auto it = s.rbegin(), end = s.rend(); it != end; ++it) + putStack.rawPush() = it->unicode(); } -void QXmlStreamReaderPrivate::putStringLiteral(const QString &s) +void QXmlStreamReaderPrivate::putStringLiteral(QStringView s) { putStack.reserve(s.size()); - for (int i = s.size()-1; i >= 0; --i) - putStack.rawPush() = ((LETTER << 16) | s.at(i).unicode()); + for (auto it = s.rbegin(), end = s.rend(); it != end; ++it) + putStack.rawPush() = ((LETTER << 16) | it->unicode()); } -void QXmlStreamReaderPrivate::putReplacement(const QString &s) +void QXmlStreamReaderPrivate::putReplacement(QStringView s) { putStack.reserve(s.size()); - for (int i = s.size()-1; i >= 0; --i) { - ushort c = s.at(i).unicode(); + for (auto it = s.rbegin(), end = s.rend(); it != end; ++it) { + char16_t c = it->unicode(); if (c == '\n' || c == '\r') putStack.rawPush() = ((LETTER << 16) | c); else putStack.rawPush() = c; } } -void QXmlStreamReaderPrivate::putReplacementInAttributeValue(const QString &s) +void QXmlStreamReaderPrivate::putReplacementInAttributeValue(QStringView s) { putStack.reserve(s.size()); - for (int i = s.size()-1; i >= 0; --i) { - ushort c = s.at(i).unicode(); + for (auto it = s.rbegin(), end = s.rend(); it != end; ++it) { + char16_t c = it->unicode(); if (c == '&' || c == ';') putStack.rawPush() = c; else if (c == '\n' || c == '\r') diff --git a/src/corelib/serialization/qxmlstream.g b/src/corelib/serialization/qxmlstream.g index a1a2256e0c..6f1f14442b 100644 --- a/src/corelib/serialization/qxmlstream.g +++ b/src/corelib/serialization/qxmlstream.g @@ -497,10 +497,10 @@ public: inline uint peekChar(); inline void putChar(uint c) { putStack.push() = c; } inline void putChar(QChar c) { putStack.push() = c.unicode(); } - void putString(const QString &s, int from = 0); - void putStringLiteral(const QString &s); - void putReplacement(const QString &s); - void putReplacementInAttributeValue(const QString &s); + void putString(QStringView s, qsizetype from = 0); + void putStringLiteral(QStringView s); + void putReplacement(QStringView s); + void putReplacementInAttributeValue(QStringView s); uint getChar_helper(); bool scanUntil(const char *str, short tokenToInject = -1); @@ -1761,12 +1761,8 @@ entity_ref_in_attribute_value ::= AMPERSAND name SEMICOLON; char_ref ::= AMPERSAND HASH char_ref_value SEMICOLON; /. case $rule_number: { - if (uint s = resolveCharRef(3)) { - if (s >= 0xffff) - putStringLiteral(QString::fromUcs4(&s, 1)); - else - putChar((LETTER << 16) | s); - + if (char32_t s = resolveCharRef(3)) { + putStringLiteral(QChar::fromUcs4(s)); textBuffer.chop(3 + sym(3).len); clearSym(); } else { diff --git a/src/corelib/serialization/qxmlstream_p.h b/src/corelib/serialization/qxmlstream_p.h index 330094f244..0ab92fe1a3 100644 --- a/src/corelib/serialization/qxmlstream_p.h +++ b/src/corelib/serialization/qxmlstream_p.h @@ -986,10 +986,10 @@ public: inline uint peekChar(); inline void putChar(uint c) { putStack.push() = c; } inline void putChar(QChar c) { putStack.push() = c.unicode(); } - void putString(const QString &s, int from = 0); - void putStringLiteral(const QString &s); - void putReplacement(const QString &s); - void putReplacementInAttributeValue(const QString &s); + void putString(QStringView s, qsizetype from = 0); + void putStringLiteral(QStringView s); + void putReplacement(QStringView s); + void putReplacementInAttributeValue(QStringView s); uint getChar_helper(); bool scanUntil(const char *str, short tokenToInject = -1); @@ -1919,12 +1919,8 @@ bool QXmlStreamReaderPrivate::parse() } break; case 244: { - if (uint s = resolveCharRef(3)) { - if (s >= 0xffff) - putStringLiteral(QString::fromUcs4(&s, 1)); - else - putChar((LETTER << 16) | s); - + if (char32_t s = resolveCharRef(3)) { + putStringLiteral(QChar::fromUcs4(s)); textBuffer.chop(3 + sym(3).len); clearSym(); } else { |