aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2021-08-18 15:26:07 +0200
committerAhmad Samir <a.samirh78@gmail.com>2021-08-18 15:41:16 +0200
commit4f8ed9b7815584afc59a9ea73bb401d9b4006d68 (patch)
tree5ac5cd59212c11e07fcb5574c2ed57f6af3d9281 /src/gui
parent98e74c201c760c17fd6b7143f649ae42d3e0667f (diff)
downloadkconfig-4f8ed9b7815584afc59a9ea73bb401d9b4006d68.tar.gz
kconfig-4f8ed9b7815584afc59a9ea73bb401d9b4006d68.tar.bz2
Port to QStrinView
Now that KF requires Qt 5.15.2; this basically reverts commit 2e8742e64fc0 with some trivial changes. NO_CHANGELOG
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kconfigloader.cpp68
-rw-r--r--src/gui/kconfigloaderhandler_p.h5
2 files changed, 30 insertions, 43 deletions
diff --git a/src/gui/kconfigloader.cpp b/src/gui/kconfigloader.cpp
index bc1751f4..ac39a12f 100644
--- a/src/gui/kconfigloader.cpp
+++ b/src/gui/kconfigloader.cpp
@@ -49,20 +49,14 @@ bool ConfigLoaderHandler::parse(QIODevice *input)
switch (reader.tokenType()) {
case QXmlStreamReader::StartElement:
- if (!startElement(reader.name(), reader.attributes())) {
- return false;
- }
+ startElement(reader.name(), reader.attributes());
break;
case QXmlStreamReader::EndElement:
- if (!endElement(reader.name())) {
- return false;
- }
+ endElement(reader.name());
break;
case QXmlStreamReader::Characters:
if (!reader.isWhitespace() && !reader.text().trimmed().isEmpty()) {
- if (!characters(reader.text())) {
- return false;
- }
+ m_cdata.append(reader.text());
}
break;
default:
@@ -77,15 +71,19 @@ bool ConfigLoaderHandler::parse(QIODevice *input)
return true;
}
-bool ConfigLoaderHandler::startElement(const QStringRef &localName, const QXmlStreamAttributes &attrs)
+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)
{
// qDebug() << "ConfigLoaderHandler::startElement(" << localName << qName;
- const QString tag = localName.toString().toLower();
- if (tag == QLatin1String("group")) {
+ if (caseInsensitiveCompare(localName, QLatin1String("group"))) {
QString group;
for (const auto &attr : attrs) {
- const QStringRef name = attr.name();
- if (name.compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) {
+ const auto attrName = attr.name();
+ if (caseInsensitiveCompare(attrName, QLatin1String("name"))) {
// qDebug() << "set group to" << attrs.value(i);
group = attr.value().toString();
}
@@ -102,71 +100,61 @@ bool ConfigLoaderHandler::startElement(const QStringRef &localName, const QXmlSt
if (m_config) {
m_config->setCurrentGroup(group);
}
- } else if (tag == QLatin1String("entry")) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("entry"))) {
for (const auto &attr : attrs) {
- const QStringRef name = attr.name();
- if (name.compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) {
+ const auto attrName = attr.name();
+ if (caseInsensitiveCompare(attrName, QLatin1String("name"))) {
m_name = attr.value().trimmed().toString();
- } else if (name.compare(QLatin1String("type"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(attrName, QLatin1String("type"))) {
m_type = attr.value().toString().toLower();
- } else if (name.compare(QLatin1String("key"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(attrName, QLatin1String("key"))) {
m_key = attr.value().trimmed().toString();
}
}
- } else if (tag == QLatin1String("choice")) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("choice"))) {
m_choice.name.clear();
m_choice.label.clear();
m_choice.whatsThis.clear();
for (const auto &attr : attrs) {
- const QStringRef name = attr.name();
- if (name.compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) {
+ const auto attrName = attr.name();
+ if (caseInsensitiveCompare(attrName, QLatin1String("name"))) {
m_choice.name = attr.value().toString();
}
}
m_inChoice = true;
}
-
- return true;
-}
-
-bool ConfigLoaderHandler::characters(const QStringRef &ch)
-{
- m_cdata.append(ch.toString());
- return true;
}
-bool ConfigLoaderHandler::endElement(const QStringRef &localName)
+void ConfigLoaderHandler::endElement(const QStringView localName)
{
// qDebug() << "ConfigLoaderHandler::endElement(" << localName << qName;
- const QStringRef tag = localName;
- if (tag.compare(QLatin1String("entry"), Qt::CaseInsensitive) == 0) {
+ if (caseInsensitiveCompare(localName, QLatin1String("entry"))) {
addItem();
resetState();
- } else if (tag.compare(QLatin1String("label"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("label"))) {
if (m_inChoice) {
m_choice.label = m_cdata.trimmed();
} else {
m_label = m_cdata.trimmed();
}
- } else if (tag.compare(QLatin1String("whatsthis"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("whatsthis"))) {
if (m_inChoice) {
m_choice.whatsThis = m_cdata.trimmed();
} else {
m_whatsThis = m_cdata.trimmed();
}
- } else if (tag.compare(QLatin1String("default"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("default"))) {
m_default = m_cdata.trimmed();
- } else if (tag.compare(QLatin1String("min"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("min"))) {
m_min = m_cdata.toInt(&m_haveMin);
- } else if (tag.compare(QLatin1String("max"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("max"))) {
m_max = m_cdata.toInt(&m_haveMax);
- } else if (tag.compare(QLatin1String("choice"), Qt::CaseInsensitive) == 0) {
+ } else if (caseInsensitiveCompare(localName, QLatin1String("choice"))) {
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 bc199e0e..297e5462 100644
--- a/src/gui/kconfigloaderhandler_p.h
+++ b/src/gui/kconfigloaderhandler_p.h
@@ -17,9 +17,8 @@ public:
bool parse(QIODevice *input);
- bool startElement(const QStringRef &localName, const QXmlStreamAttributes &attrs);
- bool endElement(const QStringRef &localName);
- bool characters(const QStringRef &ch);
+ void startElement(const QStringView localName, const QXmlStreamAttributes &attrs);
+ void endElement(const QStringView localName);
private:
void addItem();