Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimemagicrule.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | static const char magicRuleTypes_string[] = | - | ||||||||||||||||||||||||
9 | "invalid\0" | - | ||||||||||||||||||||||||
10 | "string\0" | - | ||||||||||||||||||||||||
11 | "host16\0" | - | ||||||||||||||||||||||||
12 | "host32\0" | - | ||||||||||||||||||||||||
13 | "big16\0" | - | ||||||||||||||||||||||||
14 | "big32\0" | - | ||||||||||||||||||||||||
15 | "little16\0" | - | ||||||||||||||||||||||||
16 | "little32\0" | - | ||||||||||||||||||||||||
17 | "byte\0" | - | ||||||||||||||||||||||||
18 | "\0"; | - | ||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||
20 | static const int magicRuleTypes_indices[] = { | - | ||||||||||||||||||||||||
21 | 0, 8, 15, 22, 29, 35, 41, 50, 59, 65, 0 | - | ||||||||||||||||||||||||
22 | }; | - | ||||||||||||||||||||||||
23 | - | |||||||||||||||||||||||||
24 | QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName) | - | ||||||||||||||||||||||||
25 | { | - | ||||||||||||||||||||||||
26 | for (int i = String; i <= Byte; ++i) { | - | ||||||||||||||||||||||||
27 | if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i]) | - | ||||||||||||||||||||||||
28 | return Type(i); | - | ||||||||||||||||||||||||
29 | } | - | ||||||||||||||||||||||||
30 | return Invalid; | - | ||||||||||||||||||||||||
31 | } | - | ||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType) | - | ||||||||||||||||||||||||
34 | { | - | ||||||||||||||||||||||||
35 | return magicRuleTypes_string + magicRuleTypes_indices[theType]; | - | ||||||||||||||||||||||||
36 | } | - | ||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||
class QMimeMagicRulePrivate | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
public:bool operator==(const QMimeMagicRulePrivate &other) const;QMimeMagicRule::Type type; | ||||||||||||||||||||||||||
QByteArray value; | ||||||||||||||||||||||||||
int startPos; | ||||||||||||||||||||||||||
int endPos; | ||||||||||||||||||||||||||
QByteArray mask; | ||||||||||||||||||||||||||
QByteArray pattern; | ||||||||||||||||||||||||||
quint32 number; | ||||||||||||||||||||||||||
quint32 numberMask; | ||||||||||||||||||||||||||
typedef bool (*MatchFunction)(const QMimeMagicRulePrivate *d, const QByteArray &data); | ||||||||||||||||||||||||||
MatchFunction matchFunction; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
bool QMimeMagicRulePrivate::operator==(const QMimeMagicRulePrivateQMimeMagicRule &other) const | ||||||||||||||||||||||||||
39 | { | - | ||||||||||||||||||||||||
40 | return never executed: typem_type == other.typem_type &&return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
41 | valuem_value == other.valuem_value && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
42 | startPosm_startPos == other.startPosm_startPos && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
43 | endPosm_endPos == other.endPosm_endPos && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
44 | maskm_mask == other.maskm_mask && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
45 | patternm_pattern == other.patternm_pattern && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
46 | numberm_number == other.numberm_number && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
47 | numberMaskm_numberMask == other.numberMaskm_numberMask && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
48 | matchFunctionm_matchFunction == other.matchFunctionm_matchFunction; never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
49 | } | - | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, | - | ||||||||||||||||||||||||
53 | int valueLength, const char *valueData, const char *mask) | - | ||||||||||||||||||||||||
54 | { | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart); | - | ||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | if (!mask) { | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | bool found = false; | - | ||||||||||||||||||||||||
63 | for (int i = rangeStart; i < rangeStart + rangeLength; ++i) { | - | ||||||||||||||||||||||||
64 | if (i + valueLength > dataSize) | - | ||||||||||||||||||||||||
65 | break; | - | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | if (memcmp(valueData, dataPtr + i, valueLength) == 0) { | - | ||||||||||||||||||||||||
68 | found = true; | - | ||||||||||||||||||||||||
69 | break; | - | ||||||||||||||||||||||||
70 | } | - | ||||||||||||||||||||||||
71 | } | - | ||||||||||||||||||||||||
72 | if (!found) | - | ||||||||||||||||||||||||
73 | return false; | - | ||||||||||||||||||||||||
74 | } else { | - | ||||||||||||||||||||||||
75 | bool found = false; | - | ||||||||||||||||||||||||
76 | const char *readDataBase = dataPtr + rangeStart; | - | ||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | const int maxStartPos = dataNeeded - valueLength + 1; | - | ||||||||||||||||||||||||
82 | for (int i = 0; i < maxStartPos; ++i) { | - | ||||||||||||||||||||||||
83 | const char *d = readDataBase + i; | - | ||||||||||||||||||||||||
84 | bool valid = true; | - | ||||||||||||||||||||||||
85 | for (int idx = 0; idx < valueLength; ++idx) { | - | ||||||||||||||||||||||||
86 | if (((*d++) & mask[idx]) != (valueData[idx] & mask[idx])) { | - | ||||||||||||||||||||||||
87 | valid = false; | - | ||||||||||||||||||||||||
88 | break; | - | ||||||||||||||||||||||||
89 | } | - | ||||||||||||||||||||||||
90 | } | - | ||||||||||||||||||||||||
91 | if (valid) | - | ||||||||||||||||||||||||
92 | found = true; | - | ||||||||||||||||||||||||
93 | } | - | ||||||||||||||||||||||||
94 | if (!found) | - | ||||||||||||||||||||||||
95 | return false; | - | ||||||||||||||||||||||||
96 | } | - | ||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | return true; | - | ||||||||||||||||||||||||
99 | } | - | ||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
staticbool QMimeMagicRule::matchString(const QMimeMagicRulePrivate *d,const QByteArray &data) const | ||||||||||||||||||||||||||
102 | { | - | ||||||||||||||||||||||||
103 | const int rangeLength = d->endPosm_endPos - d->startPosm_startPos + 1; | - | ||||||||||||||||||||||||
104 | return executed 17377 times by 1 test: QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPosm_startPos, rangeLength, d->patternm_pattern.size(), d->patternm_pattern.constData(), d->maskm_mask.constData());return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData()); Executed by:
executed 17377 times by 1 test: return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData()); Executed by:
| 17377 | ||||||||||||||||||||||||
105 | } | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | template <typename T> | - | ||||||||||||||||||||||||
staticbool QMimeMagicRule::matchNumber(const QMimeMagicRulePrivate *d,const QByteArray &data) const | ||||||||||||||||||||||||||
109 | { | - | ||||||||||||||||||||||||
110 | const T value(d->numberm_number); | - | ||||||||||||||||||||||||
111 | const T mask(d->numberMaskm_numberMask); | - | ||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | const char *p = data.constData() + d->startPosm_startPos; | - | ||||||||||||||||||||||||
117 | const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), d->endPosm_endPos + 1); | - | ||||||||||||||||||||||||
118 | for ( ; p <= e
| 1854-3457 | ||||||||||||||||||||||||
119 | if ((
| 13-3444 | ||||||||||||||||||||||||
120 | return executed 13 times by 1 test: true;return true; Executed by:
executed 13 times by 1 test: return true; Executed by:
| 13 | ||||||||||||||||||||||||
121 | } executed 3444 times by 1 test: end of block Executed by:
| 3444 | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | return executed 1854 times by 1 test: false;return false; Executed by:
executed 1854 times by 1 test: return false; Executed by:
| 1854 | ||||||||||||||||||||||||
124 | } | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | static inline QByteArray makePattern(const QByteArray &value) | - | ||||||||||||||||||||||||
127 | { | - | ||||||||||||||||||||||||
128 | QByteArray pattern(value.size(), Qt::Uninitialized); | - | ||||||||||||||||||||||||
129 | char *data = pattern.data(); | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | const char *p = value.constData(); | - | ||||||||||||||||||||||||
132 | const char *e = p + value.size(); | - | ||||||||||||||||||||||||
133 | for ( ; p < e; ++p) { | - | ||||||||||||||||||||||||
134 | if (*p == '\\' && ++p < e) { | - | ||||||||||||||||||||||||
135 | if (*p == 'x') { | - | ||||||||||||||||||||||||
136 | char c = 0; | - | ||||||||||||||||||||||||
137 | for (int i = 0; i < 2 && p + 1 < e; ++i) { | - | ||||||||||||||||||||||||
138 | ++p; | - | ||||||||||||||||||||||||
139 | if (*p >= '0' && *p <= '9') | - | ||||||||||||||||||||||||
140 | c = (c << 4) + *p - '0'; | - | ||||||||||||||||||||||||
141 | else if (*p >= 'a' && *p <= 'f') | - | ||||||||||||||||||||||||
142 | c = (c << 4) + *p - 'a' + 10; | - | ||||||||||||||||||||||||
143 | else if (*p >= 'A' && *p <= 'F') | - | ||||||||||||||||||||||||
144 | c = (c << 4) + *p - 'A' + 10; | - | ||||||||||||||||||||||||
145 | else | - | ||||||||||||||||||||||||
146 | continue; | - | ||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||
148 | *data++ = c; | - | ||||||||||||||||||||||||
149 | } else if (*p >= '0' && *p <= '7') { | - | ||||||||||||||||||||||||
150 | char c = *p - '0'; | - | ||||||||||||||||||||||||
151 | if (p + 1 < e && p[1] >= '0' && p[1] <= '7') { | - | ||||||||||||||||||||||||
152 | c = (c << 3) + *(++p) - '0'; | - | ||||||||||||||||||||||||
153 | if (p + 1 < e && p[1] >= '0' && p[1] <= '7' && p[-1] <= '3') | - | ||||||||||||||||||||||||
154 | c = (c << 3) + *(++p) - '0'; | - | ||||||||||||||||||||||||
155 | } | - | ||||||||||||||||||||||||
156 | *data++ = c; | - | ||||||||||||||||||||||||
157 | } else if (*p == 'n') { | - | ||||||||||||||||||||||||
158 | *data++ = '\n'; | - | ||||||||||||||||||||||||
159 | } else if (*p == 'r') { | - | ||||||||||||||||||||||||
160 | *data++ = '\r'; | - | ||||||||||||||||||||||||
161 | } else if (*p == 't') { | - | ||||||||||||||||||||||||
162 | *data++ = '\t'; | - | ||||||||||||||||||||||||
163 | } else { | - | ||||||||||||||||||||||||
164 | *data++ = *p; | - | ||||||||||||||||||||||||
165 | } | - | ||||||||||||||||||||||||
166 | } else { | - | ||||||||||||||||||||||||
167 | *data++ = *p; | - | ||||||||||||||||||||||||
168 | } | - | ||||||||||||||||||||||||
169 | } | - | ||||||||||||||||||||||||
170 | pattern.truncate(data - pattern.data()); | - | ||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||
172 | return pattern; | - | ||||||||||||||||||||||||
173 | } | - | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | QMimeMagicRule::QMimeMagicRule(const QString &typeStr&type, | - | ||||||||||||||||||||||||
180 | const QByteArray &theValue&value, | - | ||||||||||||||||||||||||
181 | const QString &offsets, | - | ||||||||||||||||||||||||
182 | const QByteArray &theMask&mask, | - | ||||||||||||||||||||||||
183 | QString *errorString) | - | ||||||||||||||||||||||||
184 | : dm_type(new QMimeMagicRulePrivate) | - | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
d->value = theValue; | ||||||||||||||||||||||||||
d->mask = theMask; | ||||||||||||||||||||||||||
d->matchFunction = 0; | ||||||||||||||||||||||||||
d->type =QMimeMagicRule::type(typeStrtype.toLatin1());())), | ||||||||||||||||||||||||||
185 | m_value(value), | - | ||||||||||||||||||||||||
186 | m_mask(mask), | - | ||||||||||||||||||||||||
187 | m_matchFunction(nullptr) | - | ||||||||||||||||||||||||
188 | { | - | ||||||||||||||||||||||||
189 | if (d->type__builtin_expect(!!(m_type
| 0-4058 | ||||||||||||||||||||||||
190 | * never executed: errorString = ([]() -> QString { enum { Size= sizeofQLatin1String(u"" "Type %s is not supported")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData") }, u"" "Type %s+ type + QLatin1String(" is not supported"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()).arg(typeStr);*errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported"); never executed: *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported"); | 0 | ||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | }const int colonIndex = offsets.indexOf(QLatin1Char(':')); | - | ||||||||||||||||||||||||
194 | const QStringQStringRef startPosStr = colonIndex == -1 ? offsets :offsets.midmidRef(0, colonIndex); | - | ||||||||||||||||||||||||
195 | const QStringQStringRef endPosStr = colonIndex == -1 ? offsets :offsets.midmidRef(colonIndex + 1); | - | ||||||||||||||||||||||||
196 | if (!(__builtin_expect(!!(!
| 0-4058 | ||||||||||||||||||||||||
197 | !__builtin_expect(!!(!
| 0-4058 | ||||||||||||||||||||||||
198 | d->typem_type = Invalid; | - | ||||||||||||||||||||||||
199 | return; never executed: return; | 0 | ||||||||||||||||||||||||
200 | } | - | ||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||
202 | if (d->value__builtin_expect(!!(m_value
| 0-4058 | ||||||||||||||||||||||||
203 | d->typem_type = Invalid; | - | ||||||||||||||||||||||||
204 | if (errorString
| 0 | ||||||||||||||||||||||||
205 | * never executed: errorString = QLatin1String([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return*errorString = ([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }());return qstring_literal_temp; never executed: *errorString = ([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); | 0 | ||||||||||||||||||||||||
206 | return; never executed: return; | 0 | ||||||||||||||||||||||||
207 | } | - | ||||||||||||||||||||||||
208 | - | |||||||||||||||||||||||||
209 | if (d->typem_type
| 0-3431 | ||||||||||||||||||||||||
210 | bool ok; | - | ||||||||||||||||||||||||
211 | d->numberm_number = d->valuem_value.toUInt(&ok, 0); | - | ||||||||||||||||||||||||
212 | if (!(__builtin_expect(!!(!
| 2-625 | ||||||||||||||||||||||||
213 | d->typem_type = Invalid; | - | ||||||||||||||||||||||||
214 | if (errorString
| 0-2 | ||||||||||||||||||||||||
215 | * executed 2 times by 1 test: errorString = QString::fromLatin1QLatin1String("Invalid magic rule value \"%1\"").arg\"") + QLatin1String(QString::fromLatin1m_value) + QLatin1Char(d->value));'"');*errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"'); Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"'); Executed by:
| 2 | ||||||||||||||||||||||||
216 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
217 | }d->numberMask | - | ||||||||||||||||||||||||
218 | m_numberMask = !d->maskm_mask.isEmpty()
| 50-575 | ||||||||||||||||||||||||
219 | } executed 625 times by 1 test: end of block Executed by:
| 625 | ||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||
221 | switch (d->typem_type) { | - | ||||||||||||||||||||||||
222 | case executed 3431 times by 1 test: String:d->patterncase String: Executed by:
executed 3431 times by 1 test: case String: Executed by:
| 3431 | ||||||||||||||||||||||||
223 | m_pattern = makePattern(d->valuem_value);d->pattern | - | ||||||||||||||||||||||||
224 | m_pattern.squeeze(); | - | ||||||||||||||||||||||||
225 | if (!d->maskm_mask.isEmpty()
| 29-3402 | ||||||||||||||||||||||||
226 | if (d->mask__builtin_expect(!!(m_mask
| 2-27 | ||||||||||||||||||||||||
227 | m_type = Invalid; | - | ||||||||||||||||||||||||
228 | if (errorString
| 0-2 | ||||||||||||||||||||||||
229 | * executed 2 times by 1 test: errorString =QString::fromLatin1 QLatin1String("Invalid magic rule mask \"") \"%1\"").arg+ QLatin1String(QString::fromLatin1m_mask) + QLatin1Char(d->mask));'"');*errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"'); Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"'); Executed by:
| 2 | ||||||||||||||||||||||||
230 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
231 | } | - | ||||||||||||||||||||||||
232 | const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( | - | ||||||||||||||||||||||||
233 | d->maskm_mask.constData() + 2, d->maskm_mask.size() - 2)); | - | ||||||||||||||||||||||||
234 | if (__builtin_expect(!!(
| 2-25 | ||||||||||||||||||||||||
235 | d->typem_type = Invalid; | - | ||||||||||||||||||||||||
236 | if (errorString
| 0-2 | ||||||||||||||||||||||||
237 | * executed 2 times by 1 test: errorString = QString::fromLatin1QLatin1String("Invalid magic rule mask size \"%1\"").arg\"") + QLatin1String(QString::fromLatin1m_mask) + QLatin1Char(d->mask));'"');*errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"'); Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"'); Executed by:
| 2 | ||||||||||||||||||||||||
238 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
239 | }d->mask | - | ||||||||||||||||||||||||
240 | m_mask = tempMask; | - | ||||||||||||||||||||||||
241 | } executed 25 times by 1 test: else {d->maskend of block Executed by:
| 25 | ||||||||||||||||||||||||
242 | m_mask.fill(char(-1),d->pattern m_pattern.size()); | - | ||||||||||||||||||||||||
243 | } executed 3402 times by 1 test: d->maskend of block Executed by:
executed 3402 times by 1 test: end of block Executed by:
| 3402 | ||||||||||||||||||||||||
244 | m_mask.squeeze();d->matchFunction | - | ||||||||||||||||||||||||
245 | m_matchFunction = &QMimeMagicRule::matchString; | - | ||||||||||||||||||||||||
246 | break; executed 3427 times by 1 test: break; Executed by:
| 3427 | ||||||||||||||||||||||||
247 | case executed 205 times by 1 test: Byte:case Byte: Executed by:
executed 205 times by 1 test: case Byte: Executed by:
| 205 | ||||||||||||||||||||||||
248 | if (d->numberm_number
| 0-205 | ||||||||||||||||||||||||
249 | if (d->numberMaskm_numberMask
| 0-205 | ||||||||||||||||||||||||
250 | m_numberMask executed 205 times by 1 test: m_numberMask = quint8(-1); Executed by:
executed 205 times by 1 test: = quint8(-1);d->matchFunctionm_numberMask = quint8(-1); Executed by:
executed 205 times by 1 test: m_numberMask = quint8(-1); Executed by:
| 205 | ||||||||||||||||||||||||
251 | m_matchFunction = &QMimeMagicRule::matchNumber<quint8>; | - | ||||||||||||||||||||||||
252 | } executed 205 times by 1 test: end of block Executed by:
| 205 | ||||||||||||||||||||||||
253 | break; executed 205 times by 1 test: break; Executed by:
| 205 | ||||||||||||||||||||||||
254 | case executed 65 times by 1 test: Big16:case Big16: Executed by:
executed 65 times by 1 test: case Big16: Executed by:
| 65 | ||||||||||||||||||||||||
255 | case executed 20 times by 1 test: Host16:case Host16: Executed by:
executed 20 times by 1 test: case Host16: Executed by:
| 20 | ||||||||||||||||||||||||
256 | case executed 85 times by 1 test: Little16:case Little16: Executed by:
executed 85 times by 1 test: case Little16: Executed by:
| 85 | ||||||||||||||||||||||||
257 | if (d->numberm_number
| 0-170 | ||||||||||||||||||||||||
258 | m_number =d->type m_type
| 85 | ||||||||||||||||||||||||
259 | if (d->numberMaskm_numberMask
| 5-165 | ||||||||||||||||||||||||
260 | m_numberMask executed 165 times by 1 test: m_numberMask = quint16(-1); Executed by:
executed 165 times by 1 test: = quint16(-1);d->matchFunctionm_numberMask = quint16(-1); Executed by:
executed 165 times by 1 test: m_numberMask = quint16(-1); Executed by:
| 165 | ||||||||||||||||||||||||
261 | m_matchFunction = &QMimeMagicRule::matchNumber<quint16>; | - | ||||||||||||||||||||||||
262 | } executed 170 times by 1 test: end of block Executed by:
| 170 | ||||||||||||||||||||||||
263 | break; executed 170 times by 1 test: break; Executed by:
| 170 | ||||||||||||||||||||||||
264 | case executed 95 times by 1 test: Big32:case Big32: Executed by:
executed 95 times by 1 test: case Big32: Executed by:
| 95 | ||||||||||||||||||||||||
265 | case executed 20 times by 1 test: Host32:case Host32: Executed by:
executed 20 times by 1 test: case Host32: Executed by:
| 20 | ||||||||||||||||||||||||
266 | case executed 135 times by 1 test: Little32:case Little32: Executed by:
executed 135 times by 1 test: case Little32: Executed by:
| 135 | ||||||||||||||||||||||||
267 | if (d->numberm_number
| 0-250 | ||||||||||||||||||||||||
268 | m_number =d->type m_type
| 115-135 | ||||||||||||||||||||||||
269 | if (d->numberMaskm_numberMask
| 45-205 | ||||||||||||||||||||||||
270 | m_numberMask executed 205 times by 1 test: m_numberMask = quint32(-1); Executed by:
executed 205 times by 1 test: = quint32(-1);d->matchFunctionm_numberMask = quint32(-1); Executed by:
executed 205 times by 1 test: m_numberMask = quint32(-1); Executed by:
| 205 | ||||||||||||||||||||||||
271 | m_matchFunction = &QMimeMagicRule::matchNumber<quint32>; | - | ||||||||||||||||||||||||
272 | } executed 250 times by 1 test: end of block Executed by:
| 250 | ||||||||||||||||||||||||
273 | break; executed 250 times by 1 test: break; Executed by:
| 250 | ||||||||||||||||||||||||
274 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
275 | break never executed: ;break; never executed: break; | 0 | ||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
QMimeMagicRule::QMimeMagicRule(const QMimeMagicRule &other) : never executed: break; | ||||||||||||||||||||||||||
d(new QMimeMagicRulePrivate(*other.d)) never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
QMimeMagicRule::~QMimeMagicRule() never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
QMimeMagicRule &QMimeMagicRule::operator=(const QMimeMagicRule &other) never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
*d = *other.d; never executed: break; | ||||||||||||||||||||||||||
return *this; never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
return d == other.d || never executed: break; | ||||||||||||||||||||||||||
*d == *other.d; never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
QMimeMagicRule::Type QMimeMagicRule::type() const never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
return d->type; never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
QByteArray QMimeMagicRule::value() const never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
return d->value; never executed: break; | ||||||||||||||||||||||||||
} never executed: break; | ||||||||||||||||||||||||||
int QMimeMagicRule::startPos() const never executed: break; | ||||||||||||||||||||||||||
{ never executed: break; | ||||||||||||||||||||||||||
return d->startPos never executed: break; never executed: ;break; never executed: break; | ||||||||||||||||||||||||||
276 | }int QMimeMagicRule::endPos() const | - | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
return d->endPos; | ||||||||||||||||||||||||||
277 | } | - | ||||||||||||||||||||||||
278 | - | |||||||||||||||||||||||||
279 | QByteArray QMimeMagicRule::mask() const | - | ||||||||||||||||||||||||
280 | { | - | ||||||||||||||||||||||||
281 | QByteArray result =d->mask m_mask; | - | ||||||||||||||||||||||||
282 | if (d->typem_type
| 0 | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | result= = "0x" + result.toHex(); | - | ||||||||||||||||||||||||
285 | } never executed: end of block | 0 | ||||||||||||||||||||||||
286 | return never executed: result;return result; never executed: return result; | 0 | ||||||||||||||||||||||||
} never executed: return result; | ||||||||||||||||||||||||||
bool QMimeMagicRule::isValid() const never executed: return result; | ||||||||||||||||||||||||||
{ never executed: return result; | ||||||||||||||||||||||||||
return d->matchFunction never executed: return result; never executed: ;return result; never executed: return result; | ||||||||||||||||||||||||||
287 | } | - | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | bool QMimeMagicRule::matches(const QByteArray &data) const | - | ||||||||||||||||||||||||
290 | { | - | ||||||||||||||||||||||||
291 | const bool ok =d->matchFunction m_matchFunction &&d->matchFunction (
| 59-19185 | ||||||||||||||||||||||||
292 | if (!ok
| 59-19185 | ||||||||||||||||||||||||
293 | return executed 19185 times by 1 test: false;return false; Executed by:
executed 19185 times by 1 test: return false; Executed by:
| 19185 | ||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||
296 | if (m_subMatches.isEmpty()
| 22-37 | ||||||||||||||||||||||||
297 | return executed 37 times by 1 test: true;return true; Executed by:
executed 37 times by 1 test: return true; Executed by:
| 37 | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||
301 | for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ; | - | ||||||||||||||||||||||||
302 | it != end
| 18-22 | ||||||||||||||||||||||||
303 | if ((*
| 4-18 | ||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||
305 | return executed 4 times by 1 test: true;return true; Executed by:
executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||||||||
306 | } | - | ||||||||||||||||||||||||
307 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||||||||
308 | return executed 18 times by 1 test: false;return false; Executed by:
executed 18 times by 1 test: return false; Executed by:
| 18 | ||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | } | - | ||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||
Switch to Source code | Preprocessed file |