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>
This commit is contained in:
Marc Mutz 2020-05-09 16:19:28 +02:00
parent 3bc9f35771
commit 255cc55d74
3 changed files with 28 additions and 32 deletions

View File

@ -1458,36 +1458,40 @@ inline int QXmlStreamReaderPrivate::fastScanNMTOKEN()
return n; 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()); putStack.reserve(s.size());
for (int i = s.size()-1; i >= from; --i) for (auto it = s.rbegin(), end = s.rend(); it != end; ++it)
putStack.rawPush() = s.at(i).unicode(); putStack.rawPush() = it->unicode();
} }
void QXmlStreamReaderPrivate::putStringLiteral(const QString &s) void QXmlStreamReaderPrivate::putStringLiteral(QStringView s)
{ {
putStack.reserve(s.size()); putStack.reserve(s.size());
for (int i = s.size()-1; i >= 0; --i) for (auto it = s.rbegin(), end = s.rend(); it != end; ++it)
putStack.rawPush() = ((LETTER << 16) | s.at(i).unicode()); putStack.rawPush() = ((LETTER << 16) | it->unicode());
} }
void QXmlStreamReaderPrivate::putReplacement(const QString &s) void QXmlStreamReaderPrivate::putReplacement(QStringView s)
{ {
putStack.reserve(s.size()); putStack.reserve(s.size());
for (int i = s.size()-1; i >= 0; --i) { for (auto it = s.rbegin(), end = s.rend(); it != end; ++it) {
ushort c = s.at(i).unicode(); char16_t c = it->unicode();
if (c == '\n' || c == '\r') if (c == '\n' || c == '\r')
putStack.rawPush() = ((LETTER << 16) | c); putStack.rawPush() = ((LETTER << 16) | c);
else else
putStack.rawPush() = c; putStack.rawPush() = c;
} }
} }
void QXmlStreamReaderPrivate::putReplacementInAttributeValue(const QString &s) void QXmlStreamReaderPrivate::putReplacementInAttributeValue(QStringView s)
{ {
putStack.reserve(s.size()); putStack.reserve(s.size());
for (int i = s.size()-1; i >= 0; --i) { for (auto it = s.rbegin(), end = s.rend(); it != end; ++it) {
ushort c = s.at(i).unicode(); char16_t c = it->unicode();
if (c == '&' || c == ';') if (c == '&' || c == ';')
putStack.rawPush() = c; putStack.rawPush() = c;
else if (c == '\n' || c == '\r') else if (c == '\n' || c == '\r')

View File

@ -497,10 +497,10 @@ public:
inline uint peekChar(); inline uint peekChar();
inline void putChar(uint c) { putStack.push() = c; } inline void putChar(uint c) { putStack.push() = c; }
inline void putChar(QChar c) { putStack.push() = c.unicode(); } inline void putChar(QChar c) { putStack.push() = c.unicode(); }
void putString(const QString &s, int from = 0); void putString(QStringView s, qsizetype from = 0);
void putStringLiteral(const QString &s); void putStringLiteral(QStringView s);
void putReplacement(const QString &s); void putReplacement(QStringView s);
void putReplacementInAttributeValue(const QString &s); void putReplacementInAttributeValue(QStringView s);
uint getChar_helper(); uint getChar_helper();
bool scanUntil(const char *str, short tokenToInject = -1); 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; char_ref ::= AMPERSAND HASH char_ref_value SEMICOLON;
/. /.
case $rule_number: { case $rule_number: {
if (uint s = resolveCharRef(3)) { if (char32_t s = resolveCharRef(3)) {
if (s >= 0xffff) putStringLiteral(QChar::fromUcs4(s));
putStringLiteral(QString::fromUcs4(&s, 1));
else
putChar((LETTER << 16) | s);
textBuffer.chop(3 + sym(3).len); textBuffer.chop(3 + sym(3).len);
clearSym(); clearSym();
} else { } else {

View File

@ -986,10 +986,10 @@ public:
inline uint peekChar(); inline uint peekChar();
inline void putChar(uint c) { putStack.push() = c; } inline void putChar(uint c) { putStack.push() = c; }
inline void putChar(QChar c) { putStack.push() = c.unicode(); } inline void putChar(QChar c) { putStack.push() = c.unicode(); }
void putString(const QString &s, int from = 0); void putString(QStringView s, qsizetype from = 0);
void putStringLiteral(const QString &s); void putStringLiteral(QStringView s);
void putReplacement(const QString &s); void putReplacement(QStringView s);
void putReplacementInAttributeValue(const QString &s); void putReplacementInAttributeValue(QStringView s);
uint getChar_helper(); uint getChar_helper();
bool scanUntil(const char *str, short tokenToInject = -1); bool scanUntil(const char *str, short tokenToInject = -1);
@ -1919,12 +1919,8 @@ bool QXmlStreamReaderPrivate::parse()
} break; } break;
case 244: { case 244: {
if (uint s = resolveCharRef(3)) { if (char32_t s = resolveCharRef(3)) {
if (s >= 0xffff) putStringLiteral(QChar::fromUcs4(s));
putStringLiteral(QString::fromUcs4(&s, 1));
else
putChar((LETTER << 16) | s);
textBuffer.chop(3 + sym(3).len); textBuffer.chop(3 + sym(3).len);
clearSym(); clearSym();
} else { } else {