代码拉取完成,页面将自动刷新
/* YUView - YUV player with advanced analytics toolset
* Copyright (C) 2015 Institut für Nachrichtentechnik
* RWTH Aachen University, GERMANY
*
* YUView is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* YUView is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YUView. If not, see <http://www.gnu.org/licenses/>.
*/
// Own includes
#include "plistparser.h"
// Qt includes
#include <QDomNode>
#include <QDomDocument>
#include <QDateTime>
#include <QDebug>
QVariant PListParser::parsePList(QIODevice *device) {
QVariantMap result;
QDomDocument doc;
QString errorMessage;
int errorLine;
int errorColumn;
bool success = doc.setContent(device, false, &errorMessage, &errorLine, &errorColumn);
if (!success) {
qDebug() << "PListParser Warning: Could not parse PList file!";
qDebug() << "Error message: " << errorMessage;
qDebug() << "Error line: " << errorLine;
qDebug() << "Error column: " << errorColumn;
return result;
}
QDomElement root = doc.documentElement();
if (root.attribute(QStringLiteral("version"), QStringLiteral("1.0")) != QLatin1String("1.0")) {
qDebug() << "PListParser Warning: plist is using an unknown format version, parsing might fail unexpectedly";
}
return parseElement(root.firstChild().toElement());
}
QVariant PListParser::parseElement(const QDomElement &e) {
QString tagName = e.tagName();
QVariant result;
if (tagName == QLatin1String("dict")) {
result = parseDictElement(e);
}
else if (tagName == QLatin1String("array")) {
result = parseArrayElement(e);
}
else if (tagName == QLatin1String("string")) {
result = e.text();
}
else if (tagName == QLatin1String("data")) {
result = QByteArray::fromBase64(e.text().toUtf8());
}
else if (tagName == QLatin1String("integer")) {
result = e.text().toInt();
}
else if (tagName == QLatin1String("real")) {
result = e.text().toFloat();
}
else if (tagName == QLatin1String("true")) {
result = true;
}
else if (tagName == QLatin1String("false")) {
result = false;
}
else if (tagName == QLatin1String("date")) {
result = QDateTime::fromString(e.text(), Qt::ISODate);
}
else {
qDebug() << "PListParser Warning: Invalid tag found: " << e.tagName() << e.text();
}
return result;
}
QVariantList PListParser::parseArrayElement(const QDomElement& element) {
QVariantList result;
QDomNodeList children = element.childNodes();
for (int i = 0; i < children.count(); i++) {
QDomNode child = children.at(i);
QDomElement e = child.toElement();
if (!e.isNull()) {
result.append(parseElement(e));
}
}
return result;
}
QVariantMap PListParser::parseDictElement(const QDomElement& element) {
QVariantMap result;
QDomNodeList children = element.childNodes();
QString currentKey;
for (int i = 0; i < children.count(); i++) {
QDomNode child = children.at(i);
QDomElement e = child.toElement();
if (!e.isNull()) {
QString tagName = e.tagName();
if (tagName == QLatin1String("key")) {
currentKey = e.text();
}
else if (!currentKey.isEmpty()) {
result[currentKey] = parseElement(e);
}
}
}
return result;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。