qmimetypeparser.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimetypeparser.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10static const char mimeInfoTagC[] = "mime-info";-
11static const char mimeTypeTagC[] = "mime-type";-
12static const char mimeTypeAttributeC[] = "type";-
13static const char subClassTagC[] = "sub-class-of";-
14static const char commentTagC[] = "comment";-
15static const char genericIconTagC[] = "generic-icon";-
16static const char iconTagC[] = "icon";-
17static const char nameAttributeC[] = "name";-
18static const char globTagC[] = "glob";-
19static const char aliasTagC[] = "alias";-
20static const char patternAttributeC[] = "pattern";-
21static const char weightAttributeC[] = "weight";-
22static const char caseSensitiveAttributeC[] = "case-sensitive";-
23static const char localeAttributeC[] = "xml:lang";-
24-
25static const char magicTagC[] = "magic";-
26static const char priorityAttributeC[] = "priority";-
27-
28static const char matchTagC[] = "match";-
29static const char matchValueAttributeC[] = "value";-
30static const char matchTypeAttributeC[] = "type";-
31static const char matchOffsetAttributeC[] = "offset";-
32static const char matchMaskAttributeC[] = "mask";-
33QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState currentState, const QStringRef &startElement)-
34{-
35 switch (currentState) {-
36 case ParseBeginning:-
37 if (startElement == QLatin1String(mimeInfoTagC))-
38 return ParseMimeInfo;-
39 if (startElement == QLatin1String(mimeTypeTagC))-
40 return ParseMimeType;-
41 return ParseError;-
42 case ParseMimeInfo:-
43 return startElement == QLatin1String(mimeTypeTagC) ? ParseMimeType : ParseError;-
44 case ParseMimeType:-
45 case ParseComment:-
46 case ParseGenericIcon:-
47 case ParseIcon:-
48 case ParseGlobPattern:-
49 case ParseSubClass:-
50 case ParseAlias:-
51 case ParseOtherMimeTypeSubTag:-
52 case ParseMagicMatchRule:-
53 if (startElement == QLatin1String(mimeTypeTagC))-
54 return ParseMimeType;-
55 if (startElement == QLatin1String(commentTagC ))-
56 return ParseComment;-
57 if (startElement == QLatin1String(genericIconTagC))-
58 return ParseGenericIcon;-
59 if (startElement == QLatin1String(iconTagC))-
60 return ParseIcon;-
61 if (startElement == QLatin1String(globTagC))-
62 return ParseGlobPattern;-
63 if (startElement == QLatin1String(subClassTagC))-
64 return ParseSubClass;-
65 if (startElement == QLatin1String(aliasTagC))-
66 return ParseAlias;-
67 if (startElement == QLatin1String(magicTagC))-
68 return ParseMagic;-
69 if (startElement == QLatin1String(matchTagC))-
70 return ParseMagicMatchRule;-
71 return ParseOtherMimeTypeSubTag;-
72 case ParseMagic:-
73 if (startElement == QLatin1String(matchTagC))-
74 return ParseMagicMatchRule;-
75 break;-
76 case ParseError:-
77 break;-
78 }-
79 return ParseError;-
80}-
81-
82-
83bool QMimeTypeParserBase::parseNumber(const QStringQStringRef &n, int *target, QString *errorMessage)-
84{-
85 bool ok;-
86 *target = n.toInt(&ok);-
87 if (!(__builtin_expect(!!(!
__builtin_expe...!(!ok), false)Description
TRUEnever evaluated
FALSEevaluated 9733 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
ok)), false)
__builtin_expe...!(!ok), false)Description
TRUEnever evaluated
FALSEevaluated 9733 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
0-9733
88 *errorMessage = QString::fromLatin1QLatin1String("Not a number '%1''") + n + QLatin1String("'.").arg(n);-
89 return
never executed: return false;
false;
never executed: return false;
0
90 }-
91 return
executed 9733 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
true;
executed 9733 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
9733
92}-
93-
94-
staticstruct CreateMagicMatchRuleResult {
96 QString errorMessage;-
97 QMimeMagicRule *rule;-
98-
99 CreateMagicMatchRuleResult(const QStringRef &type, const QStringRef &value, const QStringRef &offsets, const QStringRef &mask)-
100 : errorMessage(), rule(type.toString(), value.toUtf8(), offsets.toString(), mask.toLatin1(), &errorMessage)-
101 {-
102-
103 }
executed 4058 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
4058
104};-
105-
106static CreateMagicMatchRuleResult createMagicMatchRule(const QXmlStreamAttributes &atts, QString *errorMessage)-
107{-
108 const QStringQStringRef type = atts.value(QLatin1String(matchTypeAttributeC)).toString();));-
109 const QStringQStringRef value = atts.value(QLatin1String(matchValueAttributeC)).toString();));-
110 const QStringQStringRef offsets = atts.value(QLatin1String(matchOffsetAttributeC)).toString();));-
111 const QStringQStringRef mask = atts.value(QLatin1String(matchMaskAttributeC)).toString();));-
112 return
executed 4058 times by 1 test: return CreateMagicMatchRuleResult(type, value, offsets, mask);
Executed by:
  • tst_QMimeDatabase
new QMimeMagicRuleCreateMagicMatchRuleResult(type, value.toUtf8(),, offsets, mask.toLatin1(), errorMessage);
executed 4058 times by 1 test: return CreateMagicMatchRuleResult(type, value, offsets, mask);
Executed by:
  • tst_QMimeDatabase
4058
113}-
114-
115-
116bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage)-
117{-
118-
119-
120-
121-
122-
123 QMimeTypePrivate data;-
124 int priority = 50;-
125 QStack<QMimeMagicRule *> currentRules;-
126 QList<QMimeMagicRule> rules;-
127 QXmlStreamReader reader(dev);-
128 ParseState ps = ParseBeginning;-
QXmlStreamAttributes atts;
129 while (!reader.atEnd()
!reader.atEnd()Description
TRUEevaluated 333413 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 17 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
17-333413
130 switch (reader.readNext()) {-
131 case
executed 153309 times by 1 test: case QXmlStreamReader::StartElement:
Executed by:
  • tst_QMimeDatabase
QXmlStreamReader::StartElement:
executed 153309 times by 1 test: case QXmlStreamReader::StartElement:
Executed by:
  • tst_QMimeDatabase
{
153309
132 ps = nextState(ps, reader.name());-
133 const QXmlStreamAttributes atts = reader.attributes();-
134 switch (ps) {-
135 case
executed 3319 times by 1 test: case ParseMimeType:
Executed by:
  • tst_QMimeDatabase
ParseMimeType:
executed 3319 times by 1 test: case ParseMimeType:
Executed by:
  • tst_QMimeDatabase
{
3319
136 const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString();-
137 if (name.isEmpty()
name.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 3319 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
0-3319
138 reader.raiseError((([]() -> QString ::fromLatin1{ enum { Size = sizeof(u"" "Missing '%1''type'-attribute").arg)/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Missing 'type'-attribute" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString ::fromLatin1qstring_literal_temp(mimeTypeAttributeC)));holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}()));
0
139 }
never executed: end of block
else {
0
140 data.name = name;-
141 }
executed 3319 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3319
142 }-
143 break;
executed 3319 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
3319
144 case
executed 1575 times by 1 test: case ParseGenericIcon:
Executed by:
  • tst_QMimeDatabase
ParseGenericIcon:
executed 1575 times by 1 test: case ParseGenericIcon:
Executed by:
  • tst_QMimeDatabase
1575
145 data.genericIconName = atts.value(QLatin1String(nameAttributeC)).toString();-
146 break;
executed 1575 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
1575
147 case
never executed: case ParseIcon:
ParseIcon:
never executed: case ParseIcon:
0
148 data.iconName = atts.value(QLatin1String(nameAttributeC)).toString();-
149 break;
never executed: break;
0
150 case
executed 4136 times by 1 test: case ParseGlobPattern:
Executed by:
  • tst_QMimeDatabase
ParseGlobPattern:
executed 4136 times by 1 test: case ParseGlobPattern:
Executed by:
  • tst_QMimeDatabase
{
4136
151 const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString();-
152 unsigned weight = atts.value(QLatin1String(weightAttributeC)).toString().toInt();-
153 const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)).toString())) == QLatin1String("true");-
154-
155 if (weight == 0
weight == 0Description
TRUEevaluated 4126 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
10-4126
156 weight = QMimeGlobPattern::DefaultWeight;
executed 4126 times by 1 test: weight = QMimeGlobPattern::DefaultWeight;
Executed by:
  • tst_QMimeDatabase
4126
157-
158 ((!(!data.name.isEmpty())) ? qt_assert("!data.name.isEmpty()",__FILE__,222238) : qt_noop());-
159 const QMimeGlobPattern glob(pattern, data.name, weight, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);-
160 if (!process(glob, errorMessage)
!process(glob, errorMessage)Description
TRUEnever evaluated
FALSEevaluated 4136 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
0-4136
161 return
never executed: return false;
false;
never executed: return false;
0
162 data.addGlobPattern(pattern);-
163 }-
164 break;
executed 4136 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
4136
165 case
executed 1560 times by 1 test: case ParseSubClass:
Executed by:
  • tst_QMimeDatabase
ParseSubClass:
executed 1560 times by 1 test: case ParseSubClass:
Executed by:
  • tst_QMimeDatabase
{
1560
166 const QString inheritsFrom = atts.value(QLatin1String(mimeTypeAttributeC)).toString();-
167 if (!inheritsFrom.isEmpty()
!inheritsFrom.isEmpty()Description
TRUEevaluated 1560 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-1560
168 processParent(data.name, inheritsFrom);
executed 1560 times by 1 test: processParent(data.name, inheritsFrom);
Executed by:
  • tst_QMimeDatabase
1560
169 }-
170 break;
executed 1560 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
1560
171 case
executed 134104 times by 1 test: case ParseComment:
Executed by:
  • tst_QMimeDatabase
ParseComment:
executed 134104 times by 1 test: case ParseComment:
Executed by:
  • tst_QMimeDatabase
{
134104
172-
173 QString locale = atts.value(QLatin1String(localeAttributeC)).toString();-
174 const QString comment = reader.readElementText();-
175 if (locale.isEmpty()
locale.isEmpty()Description
TRUEevaluated 3319 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 130785 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
3319-130785
176 locale = QString::fromLatin1("en_US");
executed 3319 times by 1 test: locale = QString::fromLatin1("en_US");
Executed by:
  • tst_QMimeDatabase
3319
177 data.localeComments.insert(locale, comment);-
178 }-
179 break;
executed 134104 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
134104
180 case
executed 975 times by 1 test: case ParseAlias:
Executed by:
  • tst_QMimeDatabase
ParseAlias:
executed 975 times by 1 test: case ParseAlias:
Executed by:
  • tst_QMimeDatabase
{
975
181 const QString alias = atts.value(QLatin1String(mimeTypeAttributeC)).toString();-
182 if (!alias.isEmpty()
!alias.isEmpty()Description
TRUEevaluated 975 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-975
183 processAlias(alias, data.name);
executed 975 times by 1 test: processAlias(alias, data.name);
Executed by:
  • tst_QMimeDatabase
975
184 }-
185 break;
executed 975 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
975
186 case
executed 1733 times by 1 test: case ParseMagic:
Executed by:
  • tst_QMimeDatabase
ParseMagic:
executed 1733 times by 1 test: case ParseMagic:
Executed by:
  • tst_QMimeDatabase
{
1733
187 priority = 50;-
188 const QStringQStringRef priorityS = atts.value(QLatin1String(priorityAttributeC)).toString();));-
189 if (!priorityS.isEmpty()
!priorityS.isEmpty()Description
TRUEevaluated 1617 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 116 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
116-1617
190 if (!parseNumber(priorityS, &priority, errorMessage)
!parseNumber(p... errorMessage)Description
TRUEnever evaluated
FALSEevaluated 1617 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
0-1617
191 return
never executed: return false;
false;
never executed: return false;
0
192-
193 }
executed 1617 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
1617
194 currentRules.clear();-
195-
196 }-
197 break;
executed 1733 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
1733
198 case
executed 4058 times by 1 test: case ParseMagicMatchRule:
Executed by:
  • tst_QMimeDatabase
ParseMagicMatchRule:
executed 4058 times by 1 test: case ParseMagicMatchRule:
Executed by:
  • tst_QMimeDatabase
{
4058
199 QString magicErrorMessage;-
QMimeMagicRule *ruleauto result = createMagicMatchRule(atts, &magicErrorMessage);
200 if (!(__builtin_expect(!!(!result.
__builtin_expe...lid()), false)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 4052 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
rule->.isValid())()), false)
__builtin_expe...lid()), false)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 4052 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
6-4052
201 QMessageLogger(__FILE__, 266281, __PRETTY_FUNCTION__).warning("QMimeDatabase: Error parsing %s\n%s"%ls\n%ls",
executed 6 times by 1 test: QMessageLogger(__FILE__, 281, __PRETTY_FUNCTION__).warning("QMimeDatabase: Error parsing %ls\n%ls", static_cast<const wchar_t*>(static_cast<const void*>(QString(fileName).utf16())), static_cast<const wchar_t*>(static_cast<const void*>(QString(result.errorMessage).utf16())));
Executed by:
  • tst_QMimeDatabase
6
202 static_cast<const wchar_t*>(static_cast<const void*>(QString(fileName).toLocal8Bit().constData(),utf16())), static_cast<const wchar_t*>(static_cast<const void*>(QString(magicErrorMessageresult.errorMessage).toLocal8Bit().constData());utf16())));
executed 6 times by 1 test: QMessageLogger(__FILE__, 281, __PRETTY_FUNCTION__).warning("QMimeDatabase: Error parsing %ls\n%ls", static_cast<const wchar_t*>(static_cast<const void*>(QString(fileName).utf16())), static_cast<const wchar_t*>(static_cast<const void*>(QString(result.errorMessage).utf16())));
Executed by:
  • tst_QMimeDatabase
6
203 QList<QMimeMagicRule> *ruleList;-
204 if (currentRules.isEmpty()
currentRules.isEmpty()Description
TRUEevaluated 3018 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 1040 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
1040-3018
205 ruleList = &rules;
executed 3018 times by 1 test: ruleList = &rules;
Executed by:
  • tst_QMimeDatabase
3018
206 else-
207 ruleList = &currentRules.top()->m_subMatches;
executed 1040 times by 1 test: ruleList = &currentRules.top()->m_subMatches;
Executed by:
  • tst_QMimeDatabase
1040
208 ruleList->append(*(std::move(result.rule);));-
209-
210 currentRules.push(&ruleList->last());-
211 delete rule;break;
executed 4058 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
4058
212 }-
213 case
never executed: case ParseError:
ParseError:
never executed: case ParseError:
0
214 reader.raiseError(QString::fromLatin1QLatin1String("Unexpected element <%1>").-
arg() + reader.name().toString()));() + QLatin1Char('>'));
215 break;
never executed: break;
0
216 default
executed 1849 times by 1 test: default:
Executed by:
  • tst_QMimeDatabase
:
executed 1849 times by 1 test: default:
Executed by:
  • tst_QMimeDatabase
1849
217 break;
executed 1849 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
1849
218 }-
219 }-
220 break;
executed 153309 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
153309
221-
222 case
executed 19205 times by 1 test: case QXmlStreamReader::EndElement:
Executed by:
  • tst_QMimeDatabase
QXmlStreamReader::EndElement:
executed 19205 times by 1 test: case QXmlStreamReader::EndElement:
Executed by:
  • tst_QMimeDatabase
19205
223 {-
224 const QStringRef elementName = reader.name();-
225 if (elementName == QLatin1String(mimeTypeTagC)
elementName ==...(mimeTypeTagC)Description
TRUEevaluated 3319 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 15886 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
3319-15886
226 if (!process(QMimeType(data), errorMessage)
!process(QMime... errorMessage)Description
TRUEnever evaluated
FALSEevaluated 3319 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
0-3319
227 return
never executed: return false;
false;
never executed: return false;
0
228 data.clear();-
229 }
executed 3319 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else if (elementName == QLatin1String(matchTagC)
elementName ==...ing(matchTagC)Description
TRUEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 11828 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
3319-11828
230-
231 currentRules.pop();-
232-
233 }
executed 4058 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else if (elementName == QLatin1String(magicTagC)
elementName ==...ing(magicTagC)Description
TRUEevaluated 1733 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 10095 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
1733-10095
234-
235-
236 QMimeMagicRuleMatcher ruleMatcher(data.name, priority);-
237 ruleMatcher.addRules(rules);-
238 processMagicMatcher(ruleMatcher);-
239 rules.clear();-
240 }
executed 1733 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
1733
241 break;
executed 19205 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
19205
242 }-
243 default
executed 160899 times by 1 test: default:
Executed by:
  • tst_QMimeDatabase
:
executed 160899 times by 1 test: default:
Executed by:
  • tst_QMimeDatabase
160899
244 break;
executed 160899 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
160899
245 }-
246 }-
247-
248 if (__builtin_expect(!!(
__builtin_expe...ror()), false)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
reader.hasError())()), false)
__builtin_expe...ror()), false)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
0-17
249 if (errorMessage
errorMessageDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
250 *errorMessage = QString::fromLatin1asprintf("An error has been encountered at line %1%lld of %2%ls: %3%ls:").arg(,-
251 reader.lineNumber()).arg(),-
252 static_cast<const wchar_t*>(static_cast<const void*>(QString(fileName,).utf16())),-
253 static_cast<const wchar_t*>(static_cast<const void*>(QString(reader.errorString());()).utf16())));-
254 }
never executed: end of block
0
255 return
never executed: return false;
false;
never executed: return false;
0
256 }-
257-
258 return
executed 17 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
true;
executed 17 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
17
259-
260}-
261-
262-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9