aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2018-07-27 23:51:12 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2018-07-27 23:51:12 -0400
commitfeda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (patch)
tree1e50f5f666f419143f510d5ded00fe2006b7bd85 /SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp
parentd9aa870e5d509cc7309ab82dd102a937ab58613a (diff)
New upstream version 3.2.1+dfsg1upstream/3.2.1+dfsg1
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp b/SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp
new file mode 100644
index 0000000..7c86088
--- /dev/null
+++ b/SQLiteStudio3/coreSQLiteStudio/common/xmldeserializer.cpp
@@ -0,0 +1,84 @@
+/*#include "xmldeserializer.h"
+#include "unused.h"
+#include <QDebug>
+
+XmlDeserializer::XmlDeserializer()
+{
+}
+
+QHash<QString, QVariant> XmlDeserializer::deserialize(QIODevice *input)
+{
+ QXmlStreamReader reader(input);
+ return deserialize(reader);
+}
+
+QHash<QString, QVariant> XmlDeserializer::deserialize(const QString &input)
+{
+ QXmlStreamReader reader(input);
+ return deserialize(reader);
+}
+
+QHash<QString, QVariant> XmlDeserializer::deserialize(QXmlStreamReader &reader)
+{
+ ctxStack.clear();
+ output.clear();
+ ctx = &output;
+
+ QXmlStreamReader::TokenType tokenType;
+ while ((tokenType = reader.readNext()) != QXmlStreamReader::EndDocument)
+ handleTokenType(reader, tokenType);
+
+ return output;
+}
+
+void XmlDeserializer::handleTokenType(QXmlStreamReader& reader, QXmlStreamReader::TokenType tokenType)
+{
+ switch (tokenType)
+ {
+ case QXmlStreamReader::Comment:
+ case QXmlStreamReader::EndDocument:
+ case QXmlStreamReader::DTD:
+ case QXmlStreamReader::NoToken:
+ case QXmlStreamReader::ProcessingInstruction:
+ case QXmlStreamReader::StartDocument:
+ case QXmlStreamReader::EntityReference:
+ break;
+ case QXmlStreamReader::Invalid:
+ qDebug() << "Invalid token while parsing XML:" << reader.errorString();
+ break;
+ case QXmlStreamReader::StartElement:
+ handleStartElement(reader);
+ break;
+ case QXmlStreamReader::Characters:
+ handleText(reader);
+ break;
+ case QXmlStreamReader::EndElement:
+ handleEndElement(reader);
+ break;
+ }
+}
+
+void XmlDeserializer::handleStartElement(QXmlStreamReader &reader)
+{
+ QString key = reader.name().toString();
+ QHash<QString, QVariant> newCtx;
+ ctx->insertMulti(key, newCtx);
+
+ for (const QXmlStreamAttribute& attr : reader.attributes())
+ ctx->insertMulti(attr.name().toString(), attr.value().toString());
+
+ ctxStack.push(ctx);
+ ctx = &((*ctx)[key]);
+}
+
+void XmlDeserializer::handleText(QXmlStreamReader &reader)
+{
+ ctx->insertMulti(QString(), reader.text().toString());
+}
+
+void XmlDeserializer::handleEndElement(QXmlStreamReader &reader)
+{
+ UNUSED(reader);
+ ctx = ctxStack.pop();
+}
+*/