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 /src/gui | |
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.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kconfigloader.cpp | 68 | ||||
-rw-r--r-- | src/gui/kconfigloaderhandler_p.h | 5 |
2 files changed, 43 insertions, 30 deletions
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(); |