summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes/qmimetypeparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/mimetypes/qmimetypeparser.cpp')
-rw-r--r--src/corelib/mimetypes/qmimetypeparser.cpp40
1 files changed, 9 insertions, 31 deletions
diff --git a/src/corelib/mimetypes/qmimetypeparser.cpp b/src/corelib/mimetypes/qmimetypeparser.cpp
index 9610162c4f..8a8b97655a 100644
--- a/src/corelib/mimetypes/qmimetypeparser.cpp
+++ b/src/corelib/mimetypes/qmimetypeparser.cpp
@@ -153,8 +153,8 @@ QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState curren
return ParseError;
}
-// Parse int number from an (attribute) string)
-static bool parseNumber(const QString &n, int *target, QString *errorMessage)
+// Parse int number from an (attribute) string
+bool QMimeTypeParserBase::parseNumber(const QString &n, int *target, QString *errorMessage)
{
bool ok;
*target = n.toInt(&ok);
@@ -165,37 +165,14 @@ static bool parseNumber(const QString &n, int *target, QString *errorMessage)
return true;
}
-// Evaluate a magic match rule like
-// <match value="must be converted with BinHex" type="string" offset="11"/>
-// <match value="0x9501" type="big16" offset="0:64"/>
#ifndef QT_NO_XMLSTREAMREADER
-static bool createMagicMatchRule(const QXmlStreamAttributes &atts,
- QString *errorMessage, QMimeMagicRule *&rule)
+static QMimeMagicRule *createMagicMatchRule(const QXmlStreamAttributes &atts, QString *errorMessage)
{
const QString type = atts.value(QLatin1String(matchTypeAttributeC)).toString();
- QMimeMagicRule::Type magicType = QMimeMagicRule::type(type.toLatin1());
- if (magicType == QMimeMagicRule::Invalid) {
- qWarning("%s: match type %s is not supported.", Q_FUNC_INFO, type.toUtf8().constData());
- return true;
- }
const QString value = atts.value(QLatin1String(matchValueAttributeC)).toString();
- if (value.isEmpty()) {
- *errorMessage = QString::fromLatin1("Empty match value detected.");
- return false;
- }
- // Parse for offset as "1" or "1:10"
- int startPos, endPos;
- const QString offsetS = atts.value(QLatin1String(matchOffsetAttributeC)).toString();
- const int colonIndex = offsetS.indexOf(QLatin1Char(':'));
- const QString startPosS = colonIndex == -1 ? offsetS : offsetS.mid(0, colonIndex);
- const QString endPosS = colonIndex == -1 ? offsetS : offsetS.mid(colonIndex + 1);
- if (!parseNumber(startPosS, &startPos, errorMessage) || !parseNumber(endPosS, &endPos, errorMessage))
- return false;
+ const QString offsets = atts.value(QLatin1String(matchOffsetAttributeC)).toString();
const QString mask = atts.value(QLatin1String(matchMaskAttributeC)).toString();
-
- rule = new QMimeMagicRule(magicType, value.toUtf8(), startPos, endPos, mask.toLatin1());
-
- return true;
+ return new QMimeMagicRule(type, value.toUtf8(), offsets, mask.toLatin1(), errorMessage);
}
#endif
@@ -283,9 +260,10 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}
break;
case ParseMagicMatchRule: {
- QMimeMagicRule *rule = 0;
- if (!createMagicMatchRule(atts, errorMessage, rule))
- return false;
+ QString magicErrorMessage;
+ QMimeMagicRule *rule = createMagicMatchRule(atts, &magicErrorMessage);
+ if (!rule->isValid())
+ qWarning("QMimeDatabase: Error parsing %s\n%s", qPrintable(fileName), qPrintable(magicErrorMessage));
QList<QMimeMagicRule> *ruleList;
if (currentRules.isEmpty())
ruleList = &rules;