diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2021-05-03 01:49:43 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2021-05-09 07:50:25 +0000 |
commit | 2e8742e64fc02477296335c39b0485895321855b (patch) | |
tree | 3aab8862899b9805bd8261a6e14c52d86118d15d | |
parent | f3e8853abf53a80cbe7d7a0de21070505b1ee5fb (diff) | |
download | kconfig-2e8742e64fc02477296335c39b0485895321855b.tar.gz kconfig-2e8742e64fc02477296335c39b0485895321855b.tar.bz2 |
Revert QStringView port
QStringView has some bits of API that were only added in 5.15.2, whereas KF
requires 5.15.0.
This reverts commit 1780fb2a237af80ddc1f9cfb70cb892b53b91990.
-rw-r--r-- | src/core/kconfig.cpp | 10 | ||||
-rw-r--r-- | src/gui/kconfigloader.cpp | 68 | ||||
-rw-r--r-- | src/gui/kconfigloaderhandler_p.h | 5 | ||||
-rw-r--r-- | src/kconf_update/kconfigutils.cpp | 4 |
4 files changed, 48 insertions, 39 deletions
diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp index 8118ea51..cc3700e1 100644 --- a/src/core/kconfig.cpp +++ b/src/core/kconfig.cpp @@ -174,21 +174,21 @@ QString KConfigPrivate::expandString(const QString &value) int nDollarPos = aValue.indexOf(QLatin1Char('$')); while (nDollarPos != -1 && nDollarPos + 1 < aValue.length()) { // there is at least one $ - if (aValue.at(nDollarPos + 1) != QLatin1Char('$')) { + if (aValue[nDollarPos + 1] != QLatin1Char('$')) { int nEndPos = nDollarPos + 1; // the next character is not $ - QStringView aVarName; - if (aValue.at(nEndPos) == QLatin1Char('{')) { + QStringRef aVarName; + if (aValue[nEndPos] == QLatin1Char('{')) { while ((nEndPos <= aValue.length()) && (aValue[nEndPos] != QLatin1Char('}'))) { ++nEndPos; } ++nEndPos; - aVarName = QStringView(aValue).mid(nDollarPos + 2, nEndPos - nDollarPos - 3); + aVarName = aValue.midRef(nDollarPos + 2, nEndPos - nDollarPos - 3); } else { while (nEndPos < aValue.length() && (aValue[nEndPos].isNumber() || aValue[nEndPos].isLetter() || aValue[nEndPos] == QLatin1Char('_'))) { ++nEndPos; } - aVarName = QStringView(aValue).mid(nDollarPos + 1, nEndPos - nDollarPos - 1); + aVarName = aValue.midRef(nDollarPos + 1, nEndPos - nDollarPos - 1); } QString env; if (!aVarName.isEmpty()) { diff --git a/src/gui/kconfigloader.cpp b/src/gui/kconfigloader.cpp index 940613b8..bc1751f4 100644 --- a/src/gui/kconfigloader.cpp +++ b/src/gui/kconfigloader.cpp @@ -49,14 +49,20 @@ bool ConfigLoaderHandler::parse(QIODevice *input) switch (reader.tokenType()) { case QXmlStreamReader::StartElement: - startElement(reader.name(), reader.attributes()); + if (!startElement(reader.name(), reader.attributes())) { + return false; + } break; case QXmlStreamReader::EndElement: - endElement(reader.name()); + if (!endElement(reader.name())) { + return false; + } break; case QXmlStreamReader::Characters: if (!reader.isWhitespace() && !reader.text().trimmed().isEmpty()) { - m_cdata.append(reader.text()); + if (!characters(reader.text())) { + return false; + } } break; default: @@ -71,19 +77,15 @@ bool ConfigLoaderHandler::parse(QIODevice *input) return true; } -static bool caseInsensitiveCompare(const QStringView a, const QLatin1String b) -{ - return a.compare(b, Qt::CaseInsensitive) == 0; -} - -void ConfigLoaderHandler::startElement(const QStringView localName, const QXmlStreamAttributes &attrs) +bool ConfigLoaderHandler::startElement(const QStringRef &localName, const QXmlStreamAttributes &attrs) { // qDebug() << "ConfigLoaderHandler::startElement(" << localName << qName; - if (caseInsensitiveCompare(localName, QLatin1String("group"))) { + const QString tag = localName.toString().toLower(); + if (tag == QLatin1String("group")) { QString group; for (const auto &attr : attrs) { - const auto name = attr.name(); - if (caseInsensitiveCompare(name, QLatin1String("name"))) { + const QStringRef name = attr.name(); + if (name.compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) { // qDebug() << "set group to" << attrs.value(i); group = attr.value().toString(); } @@ -100,61 +102,71 @@ void ConfigLoaderHandler::startElement(const QStringView localName, const QXmlSt if (m_config) { m_config->setCurrentGroup(group); } - } else if (caseInsensitiveCompare(localName, QLatin1String("entry"))) { + } else if (tag == QLatin1String("entry")) { for (const auto &attr : attrs) { - const auto name = attr.name(); - if (caseInsensitiveCompare(name, QLatin1String("name"))) { + const QStringRef name = attr.name(); + if (name.compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) { m_name = attr.value().trimmed().toString(); - } else if (caseInsensitiveCompare(name, QLatin1String("type"))) { + } else if (name.compare(QLatin1String("type"), Qt::CaseInsensitive) == 0) { m_type = attr.value().toString().toLower(); - } else if (caseInsensitiveCompare(name, QLatin1String("key"))) { + } else if (name.compare(QLatin1String("key"), Qt::CaseInsensitive) == 0) { m_key = attr.value().trimmed().toString(); } } - } else if (caseInsensitiveCompare(localName, QLatin1String("choice"))) { + } else if (tag == QLatin1String("choice")) { m_choice.name.clear(); m_choice.label.clear(); m_choice.whatsThis.clear(); for (const auto &attr : attrs) { - const auto name = attr.name(); - if (caseInsensitiveCompare(name, QLatin1String("name"))) { + const QStringRef name = attr.name(); + if (name.compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) { m_choice.name = attr.value().toString(); } } m_inChoice = true; } + + return true; +} + +bool ConfigLoaderHandler::characters(const QStringRef &ch) +{ + m_cdata.append(ch.toString()); + return true; } -void ConfigLoaderHandler::endElement(const QStringView localName) +bool ConfigLoaderHandler::endElement(const QStringRef &localName) { // qDebug() << "ConfigLoaderHandler::endElement(" << localName << qName; - if (caseInsensitiveCompare(localName, QLatin1String("entry"))) { + const QStringRef tag = localName; + if (tag.compare(QLatin1String("entry"), Qt::CaseInsensitive) == 0) { addItem(); resetState(); - } else if (caseInsensitiveCompare(localName, QLatin1String("label"))) { + } else if (tag.compare(QLatin1String("label"), Qt::CaseInsensitive) == 0) { if (m_inChoice) { m_choice.label = m_cdata.trimmed(); } else { m_label = m_cdata.trimmed(); } - } else if (caseInsensitiveCompare(localName, QLatin1String("whatsthis"))) { + } else if (tag.compare(QLatin1String("whatsthis"), Qt::CaseInsensitive) == 0) { if (m_inChoice) { m_choice.whatsThis = m_cdata.trimmed(); } else { m_whatsThis = m_cdata.trimmed(); } - } else if (caseInsensitiveCompare(localName, QLatin1String("default"))) { + } else if (tag.compare(QLatin1String("default"), Qt::CaseInsensitive) == 0) { m_default = m_cdata.trimmed(); - } else if (caseInsensitiveCompare(localName, QLatin1String("min"))) { + } else if (tag.compare(QLatin1String("min"), Qt::CaseInsensitive) == 0) { m_min = m_cdata.toInt(&m_haveMin); - } else if (caseInsensitiveCompare(localName, QLatin1String("max"))) { + } else if (tag.compare(QLatin1String("max"), Qt::CaseInsensitive) == 0) { m_max = m_cdata.toInt(&m_haveMax); - } else if (caseInsensitiveCompare(localName, QLatin1String("choice"))) { + } else if (tag.compare(QLatin1String("choice"), Qt::CaseInsensitive) == 0) { m_enumChoices.append(m_choice); m_inChoice = false; } m_cdata.clear(); + return true; } void ConfigLoaderHandler::addItem() diff --git a/src/gui/kconfigloaderhandler_p.h b/src/gui/kconfigloaderhandler_p.h index 297e5462..bc199e0e 100644 --- a/src/gui/kconfigloaderhandler_p.h +++ b/src/gui/kconfigloaderhandler_p.h @@ -17,8 +17,9 @@ public: bool parse(QIODevice *input); - void startElement(const QStringView localName, const QXmlStreamAttributes &attrs); - void endElement(const QStringView localName); + bool startElement(const QStringRef &localName, const QXmlStreamAttributes &attrs); + bool endElement(const QStringRef &localName); + bool characters(const QStringRef &ch); private: void addItem(); diff --git a/src/kconf_update/kconfigutils.cpp b/src/kconf_update/kconfigutils.cpp index 9608f21c..49d5ac3c 100644 --- a/src/kconf_update/kconfigutils.cpp +++ b/src/kconf_update/kconfigutils.cpp @@ -89,11 +89,7 @@ QString unescapeString(const QString &src, bool *ok, QString *error) break; case L'x': { if (pos + 2 < length) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - char value = QStringView(src).mid(pos + 1, 2).toInt(ok, 16); -#else char value = src.midRef(pos + 1, 2).toInt(ok, 16); -#endif if (*ok) { dst += QLatin1Char{value}; pos += 2; |