diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-06-09 15:32:37 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-07-01 14:54:21 +0200 |
commit | e87334da5304d7569404139133e9e1530189109e (patch) | |
tree | e1d79f3168de190cceaa9b9509e4f38d65931b09 | |
parent | cb484f6774889c068c3caca9ad40f9ceb7da4f02 (diff) |
Qt6: Port QtScxml to QStringView
Task-number: QTBUG-84319
Change-Id: Ibb3af127a50adba9345540ea39c1c8cc17b72d06
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
-rw-r--r-- | src/scxml/qscxmlcompiler.cpp | 30 | ||||
-rw-r--r-- | src/scxml/qscxmlcompiler_p.h | 2 | ||||
-rw-r--r-- | src/scxml/qscxmlexecutablecontent.cpp | 4 | ||||
-rw-r--r-- | src/scxml/qscxmlstatemachine.cpp | 4 | ||||
-rw-r--r-- | tools/qscxmlc/scxmlcppdumper.cpp | 15 |
5 files changed, 27 insertions, 28 deletions
diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp index 25a8a88..60e7197 100644 --- a/src/scxml/qscxmlcompiler.cpp +++ b/src/scxml/qscxmlcompiler.cpp @@ -1008,7 +1008,7 @@ bool QScxmlCompilerPrivate::ParserState::isExecutableContent(ParserState::Kind k return false; } -QScxmlCompilerPrivate::ParserState::Kind QScxmlCompilerPrivate::ParserState::nameToParserStateKind(const QStringRef &name) +QScxmlCompilerPrivate::ParserState::Kind QScxmlCompilerPrivate::ParserState::nameToParserStateKind(QStringView name) { static QMap<QString, ParserState::Kind> nameToKind; if (nameToKind.isEmpty()) { @@ -1407,7 +1407,7 @@ bool QScxmlCompilerPrivate::preReadElementScxml() scxml->initial += initial.split(QChar::Space, Qt::SkipEmptyParts); } - const QStringRef datamodel = attributes.value(QLatin1String("datamodel")); + const QStringView datamodel = attributes.value(QLatin1String("datamodel")); if (datamodel.isEmpty() || datamodel == QLatin1String("null")) { scxml->dataModel = DocumentModel::Scxml::NullDataModel; } else if (datamodel == QLatin1String("ecmascript")) { @@ -1431,7 +1431,7 @@ bool QScxmlCompilerPrivate::preReadElementScxml() addError(QStringLiteral("Unsupported data model '%1' in scxml") .arg(datamodel.toString())); } - const QStringRef binding = attributes.value(QLatin1String("binding")); + const QStringView binding = attributes.value(QLatin1String("binding")); if (binding.isEmpty() || binding == QLatin1String("early")) { scxml->binding = DocumentModel::Scxml::EarlyBinding; } else if (binding == QLatin1String("late")) { @@ -1441,7 +1441,7 @@ bool QScxmlCompilerPrivate::preReadElementScxml() .arg(binding.toString())); return false; } - const QStringRef name = attributes.value(QLatin1String("name")); + const QStringView name = attributes.value(QLatin1String("name")); if (!name.isEmpty()) { scxml->name = name.toString(); } @@ -1529,7 +1529,7 @@ bool QScxmlCompilerPrivate::preReadElementTransition() transition->targets = attributes.value(QLatin1String("target")).toString().split(QLatin1Char(' '), Qt::SkipEmptyParts); if (attributes.hasAttribute(QStringLiteral("cond"))) transition->condition.reset(new QString(attributes.value(QLatin1String("cond")).toString())); - QStringRef type = attributes.value(QLatin1String("type")); + QStringView type = attributes.value(QLatin1String("type")); if (type.isEmpty() || type == QLatin1String("external")) { transition->type = DocumentModel::Transition::External; } else if (type == QLatin1String("internal")) { @@ -1565,7 +1565,7 @@ bool QScxmlCompilerPrivate::preReadElementHistory() if (!maybeId(attributes, &newState->id)) return false; - const QStringRef type = attributes.value(QLatin1String("type")); + const QStringView type = attributes.value(QLatin1String("type")); if (type.isEmpty() || type == QLatin1String("shallow")) { newState->type = DocumentModel::HistoryState::Shallow; } else if (type == QLatin1String("deep")) { @@ -1845,11 +1845,11 @@ bool QScxmlCompilerPrivate::preReadElementInvoke() invoke->idLocation = attributes.value(QLatin1String("idlocation")).toString(); invoke->type = attributes.value(QLatin1String("type")).toString(); invoke->typeexpr = attributes.value(QLatin1String("typeexpr")).toString(); - QStringRef autoforwardS = attributes.value(QLatin1String("autoforward")); - if (QStringRef::compare(autoforwardS, QLatin1String("true"), Qt::CaseInsensitive) == 0 - || QStringRef::compare(autoforwardS, QLatin1String("yes"), Qt::CaseInsensitive) == 0 - || QStringRef::compare(autoforwardS, QLatin1String("t"), Qt::CaseInsensitive) == 0 - || QStringRef::compare(autoforwardS, QLatin1String("y"), Qt::CaseInsensitive) == 0 + QStringView autoforwardS = attributes.value(QLatin1String("autoforward")); + if (autoforwardS.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 + || autoforwardS.compare(QLatin1String("yes"), Qt::CaseInsensitive) == 0 + || autoforwardS.compare(QLatin1String("t"), Qt::CaseInsensitive) == 0 + || autoforwardS.compare(QLatin1String("y"), Qt::CaseInsensitive) == 0 || autoforwardS == QLatin1String("1")) invoke->autoforward = true; else @@ -2113,7 +2113,7 @@ bool QScxmlCompilerPrivate::readDocument() for (bool finished = false; !finished && !m_reader->hasError();) { switch (m_reader->readNext()) { case QXmlStreamReader::StartElement : { - const QStringRef newTag = m_reader->name(); + const QStringView newTag = m_reader->name(); const ParserState::Kind newElementKind = ParserState::nameToParserStateKind(newTag); auto ns = m_reader->namespaceUri(); @@ -2154,7 +2154,7 @@ bool QScxmlCompilerPrivate::readDocument() bool QScxmlCompilerPrivate::readElement() { - const QStringRef currentTag = m_reader->name(); + const QStringView currentTag = m_reader->name(); const QXmlStreamAttributes attributes = m_reader->attributes(); const ParserState::Kind elementKind = ParserState::nameToParserStateKind(currentTag); @@ -2219,7 +2219,7 @@ bool QScxmlCompilerPrivate::readElement() for (bool finished = false; !finished && !m_reader->hasError();) { switch (m_reader->readNext()) { case QXmlStreamReader::StartElement : { - const QStringRef newTag = m_reader->name(); + const QStringView newTag = m_reader->name(); const ParserState::Kind newElementKind = ParserState::nameToParserStateKind(newTag); auto ns = m_reader->namespaceUri(); @@ -2416,7 +2416,7 @@ bool QScxmlCompilerPrivate::checkAttributes(const QXmlStreamAttributes &attribut { QStringList required = requiredNames; for (const QXmlStreamAttribute &attribute : attributes) { - const QStringRef ns = attribute.namespaceUri(); + const QStringView ns = attribute.namespaceUri(); if (!ns.isEmpty() && ns != scxmlNamespace && ns != qtScxmlNamespace) continue; diff --git a/src/scxml/qscxmlcompiler_p.h b/src/scxml/qscxmlcompiler_p.h index 26f8061..703e410 100644 --- a/src/scxml/qscxmlcompiler_p.h +++ b/src/scxml/qscxmlcompiler_p.h @@ -694,7 +694,7 @@ private: bool validChild(ParserState::Kind child) const; static bool validChild(ParserState::Kind parent, ParserState::Kind child); static bool isExecutableContent(ParserState::Kind kind); - static Kind nameToParserStateKind(const QStringRef &name); + static Kind nameToParserStateKind(QStringView name); static QStringList requiredAttributes(Kind kind); static QStringList optionalAttributes(Kind kind); }; diff --git a/src/scxml/qscxmlexecutablecontent.cpp b/src/scxml/qscxmlexecutablecontent.cpp index 45079d7..c9f4b41 100644 --- a/src/scxml/qscxmlexecutablecontent.cpp +++ b/src/scxml/qscxmlexecutablecontent.cpp @@ -234,7 +234,7 @@ using namespace QScxmlExecutableContent; #ifndef BUILD_QSCXMLC -static int parseTime(const QString &t, bool *ok = nullptr) +static int parseTime(QStringView t, bool *ok = nullptr) { if (t.isEmpty()) { if (ok) @@ -259,7 +259,7 @@ static int parseTime(const QString &t, bool *ok = nullptr) if (ok) *ok = false; return -1; } - int value = t.midRef(startPos, pos - startPos).toInt(ok); + int value = t.mid(startPos, pos - startPos).toInt(ok); if (ok && !*ok) return -1; if (t.length() == pos + 1 && t[pos] == QLatin1Char('s')) { value *= 1000; diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index 819f6d1..8a0afd7 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -529,7 +529,7 @@ void QScxmlStateMachinePrivate::routeEvent(QScxmlEvent *event) } } else if (origin.startsWith(QStringLiteral("#_")) && origin != QStringLiteral("#_internal")) { // route to children - auto originId = origin.midRef(2); + auto originId = QStringView{origin}.mid(2); for (const auto &invokedService : m_invokedServices) { auto service = invokedService.service; if (service == nullptr) @@ -2206,7 +2206,7 @@ bool QScxmlStateMachine::isDispatchableTarget(const QString &target) const return true; // that's the current state machine if (target.startsWith(QStringLiteral("#_"))) { - QStringRef targetId = target.midRef(2); + QStringView targetId = QStringView{target}.mid(2); for (auto invokedService : d->m_invokedServices) { if (invokedService.service && invokedService.service->id() == targetId) return true; diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp index 8bf8ce7..4919604 100644 --- a/tools/qscxmlc/scxmlcppdumper.cpp +++ b/tools/qscxmlc/scxmlcppdumper.cpp @@ -109,27 +109,26 @@ static void genTemplate(QTextStream &out, const QString &filename, const Replace qFatal("Unable to open template '%s'", qPrintable(filename)); } Q_ASSERT(file.compressionAlgorithm() == QResource::NoCompression); - QByteArray data; - data = QByteArray::fromRawData(reinterpret_cast<const char *>(file.data()), - int(file.size())); - const QString t = QString::fromLatin1(data); - data.clear(); + const QString data = QString::fromLatin1( + QByteArray::fromRawData(reinterpret_cast<const char *>(file.data()), int(file.size())) + ); + const QStringView t { data }; int start = 0; for (int openIdx = t.indexOf(QStringLiteral("${"), start); openIdx >= 0; openIdx = t.indexOf(QStringLiteral("${"), start)) { - out << t.midRef(start, openIdx - start); + out << t.mid(start, openIdx - start); openIdx += 2; const int closeIdx = t.indexOf(QLatin1Char('}'), openIdx); Q_ASSERT(closeIdx >= openIdx); - QString key = t.mid(openIdx, closeIdx - openIdx); + QString key = t.mid(openIdx, closeIdx - openIdx).toString(); if (!replacements.contains(key)) { qFatal("Replacing '%s' failed: no replacement found", qPrintable(key)); } out << replacements.value(key); start = closeIdx + 1; } - out << t.midRef(start); + out << t.mid(start); } static const char *headerStart = |