qmimemagicrule.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimemagicrule.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8static 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-
20static const int magicRuleTypes_indices[] = {-
21 0, 8, 15, 22, 29, 35, 41, 50, 59, 65, 0-
22};-
23-
24QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName)-
25{-
26 for (int i = String; i <= Byte
i <= ByteDescription
TRUEevaluated 7377 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
; ++i) {
0-7377
27 if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i]
theTypeName ==...pes_indices[i]Description
TRUEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3319 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
3319-4058
28 return
executed 4058 times by 1 test: return Type(i);
Executed by:
  • tst_QMimeDatabase
Type(i);
executed 4058 times by 1 test: return Type(i);
Executed by:
  • tst_QMimeDatabase
4058
29 }
executed 3319 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3319
30 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
31}-
32-
33QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType)-
34{-
35 return
never executed: return magicRuleTypes_string + magicRuleTypes_indices[theType];
magicRuleTypes_string + magicRuleTypes_indices[theType];
never executed: return magicRuleTypes_string + magicRuleTypes_indices[theType];
0
36}-
37-
38bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const-
39{-
40 return
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;
m_type == other.m_type &&
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 m_value == other.m_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 m_startPos == other.m_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 m_endPos == other.m_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 m_mask == other.m_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 m_pattern == other.m_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 m_number == other.m_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 m_numberMask == other.m_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 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
49}-
50-
51-
52bool 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
!maskDescription
TRUEevaluated 9901 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 17592 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
9901-17592
60-
61-
62 bool found = false;-
63 for (int i = rangeStart; i < rangeStart + rangeLength
i < rangeStart + rangeLengthDescription
TRUEevaluated 39384 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 5928 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++i) {
5928-39384
64 if (i + valueLength > dataSize
i + valueLength > dataSizeDescription
TRUEevaluated 3928 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 35456 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
3928-35456
65 break;
executed 3928 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
3928
66-
67 if (memcmp(valueData, dataPtr + i, valueLength) == 0
memcmp(valueDa...ueLength) == 0Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 35411 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
45-35411
68 found = true;-
69 break;
executed 45 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
45
70 }-
71 }
executed 35411 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
35411
72 if (!found
!foundDescription
TRUEevaluated 9856 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
45-9856
73 return
executed 9856 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
false;
executed 9856 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
9856
74 }
executed 45 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else {
45
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 < maxStartPosDescription
TRUEevaluated 38620 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 17592 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++i) {
17592-38620
83 const char *d = readDataBase + i;-
84 bool valid = true;-
85 for (int idx = 0; idx < valueLength
idx < valueLengthDescription
TRUEevaluated 39071 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 46 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++idx) {
46-39071
86 if (((*
((*d++) & mask...] & mask[idx])Description
TRUEevaluated 38574 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 497 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
d++) & mask[idx]) != (valueData[idx] & mask[idx])
((*d++) & mask...] & mask[idx])Description
TRUEevaluated 38574 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 497 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
497-38574
87 valid = false;-
88 break;
executed 38574 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
38574
89 }-
90 }
executed 497 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
497
91 if (valid
validDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 38574 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
46-38574
92 found = true;
executed 46 times by 1 test: found = true;
Executed by:
  • tst_QMimeDatabase
46
93 }
executed 38620 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
38620
94 if (!found
!foundDescription
TRUEevaluated 17546 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 46 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
46-17546
95 return
executed 17546 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
false;
executed 17546 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
17546
96 }
executed 46 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
46
97-
98 return
executed 91 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
true;
executed 91 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
91
99}-
100-
101bool QMimeMagicRule::matchString(const QByteArray &data) const-
102{-
103 const int rangeLength = m_endPos - m_startPos + 1;-
104 return
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:
  • tst_QMimeDatabase
QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());
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:
  • tst_QMimeDatabase
17377
105}-
106-
107template <typename T>-
108bool QMimeMagicRule::matchNumber(const QByteArray &data) const-
109{-
110 const T value(m_number);-
111 const T mask(m_numberMask);-
112-
113-
114-
115-
116 const char *p = data.constData() + m_startPos;-
117 const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1);-
118 for ( ; p <= e
p <= eDescription
TRUEevaluated 3457 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 1854 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++p) {
1854-3457
119 if ((
(qFromUnaligne...(value & mask)Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3444 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
qFromUnaligned<T>(p) & mask) == (value & mask)
(qFromUnaligne...(value & mask)Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3444 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
13-3444
120 return
executed 13 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
true;
executed 13 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
13
121 }
executed 3444 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3444
122-
123 return
executed 1854 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
false;
executed 1854 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
1854
124}-
125-
126static 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 < eDescription
TRUEevaluated 33647 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3431 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++p) {
3431-33647
134 if (*
*p == '\\'Description
TRUEevaluated 2255 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 31392 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p == '\\'
*p == '\\'Description
TRUEevaluated 2255 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 31392 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& ++
++p < eDescription
TRUEevaluated 2255 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p < e
++p < eDescription
TRUEevaluated 2255 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
) {
0-31392
135 if (*
*p == 'x'Description
TRUEevaluated 775 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 1480 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p == 'x'
*p == 'x'Description
TRUEevaluated 775 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 1480 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
775-1480
136 char c = 0;-
137 for (int i = 0; i < 2
i < 2Description
TRUEevaluated 1550 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 765 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& p + 1 < e
p + 1 < eDescription
TRUEevaluated 1540 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++i) {
10-1550
138 ++p;-
139 if (*
*p >= '0'Description
TRUEevaluated 1540 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p >= '0'
*p >= '0'Description
TRUEevaluated 1540 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
&& *
*p <= '9'Description
TRUEevaluated 1260 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 280 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p <= '9'
*p <= '9'Description
TRUEevaluated 1260 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 280 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
0-1540
140 c = (c << 4) + *p - '0';
executed 1260 times by 1 test: c = (c << 4) + *p - '0';
Executed by:
  • tst_QMimeDatabase
1260
141 else if (*
*p >= 'a'Description
TRUEevaluated 220 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p >= 'a'
*p >= 'a'Description
TRUEevaluated 220 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& *
*p <= 'f'Description
TRUEevaluated 220 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p <= 'f'
*p <= 'f'Description
TRUEevaluated 220 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-220
142 c = (c << 4) + *p - 'a' + 10;
executed 220 times by 1 test: c = (c << 4) + *p - 'a' + 10;
Executed by:
  • tst_QMimeDatabase
220
143 else if (*
*p >= 'A'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p >= 'A'
*p >= 'A'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
&& *
*p <= 'F'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p <= 'F'
*p <= 'F'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-60
144 c = (c << 4) + *p - 'A' + 10;
executed 60 times by 1 test: c = (c << 4) + *p - 'A' + 10;
Executed by:
  • tst_QMimeDatabase
60
145 else-
146 continue;
never executed: continue;
0
147 }-
148 *data++ = c;-
149 }
executed 775 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else if (*
*p >= '0'Description
TRUEevaluated 1435 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p >= '0'
*p >= '0'Description
TRUEevaluated 1435 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& *
*p <= '7'Description
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 155 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p <= '7'
*p <= '7'Description
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 155 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
45-1435
150 char c = *p - '0';-
151 if (p + 1 < e
p + 1 < eDescription
TRUEevaluated 1195 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 85 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& p[1] >= '0'
p[1] >= '0'Description
TRUEevaluated 1195 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
&& p[1] <= '7'
p[1] <= '7'Description
TRUEevaluated 1060 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 135 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
0-1195
152 c = (c << 3) + *(++p) - '0';-
153 if (p + 1 < e
p + 1 < eDescription
TRUEevaluated 1055 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& p[1] >= '0'
p[1] >= '0'Description
TRUEevaluated 1055 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
&& p[1] <= '7'
p[1] <= '7'Description
TRUEevaluated 1045 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& p[-1] <= '3'
p[-1] <= '3'Description
TRUEevaluated 1045 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-1055
154 c = (c << 3) + *(++p) - '0';
executed 1045 times by 1 test: c = (c << 3) + *(++p) - '0';
Executed by:
  • tst_QMimeDatabase
1045
155 }
executed 1060 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
1060
156 *data++ = c;-
157 }
executed 1280 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else if (*
*p == 'n'Description
TRUEevaluated 75 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 125 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p == 'n'
*p == 'n'Description
TRUEevaluated 75 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 125 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
75-1280
158 *data++ = '\n';-
159 }
executed 75 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else if (*
*p == 'r'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 115 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p == 'r'
*p == 'r'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 115 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
10-115
160 *data++ = '\r';-
161 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else if (*
*p == 't'Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 100 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p == 't'
*p == 't'Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 100 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
10-100
162 *data++ = '\t';-
163 }
executed 15 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else {
15
164 *data++ = *p;-
165 }
executed 100 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
100
166 } else {-
167 *data++ = *p;-
168 }
executed 31392 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
31392
169 }-
170 pattern.truncate(data - pattern.data());-
171-
172 return
executed 3431 times by 1 test: return pattern;
Executed by:
  • tst_QMimeDatabase
pattern;
executed 3431 times by 1 test: return pattern;
Executed by:
  • tst_QMimeDatabase
3431
173}-
174-
175-
176-
177-
178-
179QMimeMagicRule::QMimeMagicRule(const QString &type,-
180 const QByteArray &value,-
181 const QString &offsets,-
182 const QByteArray &mask,-
183 QString *errorString)-
184 : m_type(QMimeMagicRule::type(type.toLatin1())),-
185 m_value(value),-
186 m_mask(mask),-
187 m_matchFunction(nullptr)-
188{-
189 if (__builtin_expect(!!(m_type == Invalid), false)
__builtin_expe...valid), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
0-4058
190 *
never executed: *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");
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 QStringRef startPosStr = offsets.midRef(0, colonIndex);-
195 const QStringRef endPosStr = offsets.midRef(colonIndex + 1);-
196 if (__builtin_expect(!!(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)), false)
__builtin_expe...ring)), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
||
0-4058
197 __builtin_expect(!!(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString)), false)
__builtin_expe...ring)), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
0-4058
198 m_type = Invalid;-
199 return;
never executed: return;
0
200 }-
201-
202 if (__builtin_expect(!!(m_value.isEmpty()), false)
__builtin_expe...pty()), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
0-4058
203 m_type = Invalid;-
204 if (errorString
errorStringDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
205 *
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; }());
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
never executed: return qstring_literal_temp;
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 (m_type >= Host16
m_type >= Host16Description
TRUEevaluated 627 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3431 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
&& m_type <= Byte
m_type <= ByteDescription
TRUEevaluated 627 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
) {
0-3431
210 bool ok;-
211 m_number = m_value.toUInt(&ok, 0);-
212 if (__builtin_expect(!!(!ok), false)
__builtin_expe...!(!ok), false)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 625 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
2-625
213 m_type = Invalid;-
214 if (errorString
errorStringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-2
215 *
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
2
216 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QMimeDatabase
2
217 }-
218 m_numberMask = !m_mask.isEmpty()
!m_mask.isEmpty()Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 575 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
? m_mask.toUInt(&ok, 0) : 0;
50-575
219 }
executed 625 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
625
220-
221 switch (m_type) {-
222 case
executed 3431 times by 1 test: case String:
Executed by:
  • tst_QMimeDatabase
String:
executed 3431 times by 1 test: case String:
Executed by:
  • tst_QMimeDatabase
3431
223 m_pattern = makePattern(m_value);-
224 m_pattern.squeeze();-
225 if (!m_mask.isEmpty()
!m_mask.isEmpty()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3402 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
29-3402
226 if (__builtin_expect(!!(m_mask.size() < 4 || !m_mask.startsWith("0x")), false)
__builtin_expe..."0x")), false)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 27 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
2-27
227 m_type = Invalid;-
228 if (errorString
errorStringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-2
229 *
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
2
230 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QMimeDatabase
2
231 }-
232 const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData(-
233 m_mask.constData() + 2, m_mask.size() - 2));-
234 if (__builtin_expect(!!(tempMask.size() != m_pattern.size()), false)
__builtin_expe...ize()), false)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
2-25
235 m_type = Invalid;-
236 if (errorString
errorStringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-2
237 *
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
2
238 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QMimeDatabase
2
239 }-
240 m_mask = tempMask;-
241 }
executed 25 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
else {
25
242 m_mask.fill(char(-1), m_pattern.size());-
243 }
executed 3402 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3402
244 m_mask.squeeze();-
245 m_matchFunction = &QMimeMagicRule::matchString;-
246 break;
executed 3427 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
3427
247 case
executed 205 times by 1 test: case Byte:
Executed by:
  • tst_QMimeDatabase
Byte:
executed 205 times by 1 test: case Byte:
Executed by:
  • tst_QMimeDatabase
205
248 if (m_number <= quint8(-1)
m_number <= quint8(-1)Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
) {
0-205
249 if (m_numberMask == 0
m_numberMask == 0Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
)
0-205
250 m_numberMask = quint8(-1);
executed 205 times by 1 test: m_numberMask = quint8(-1);
Executed by:
  • tst_QMimeDatabase
205
251 m_matchFunction = &QMimeMagicRule::matchNumber<quint8>;-
252 }
executed 205 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
205
253 break;
executed 205 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
205
254 case
executed 65 times by 1 test: case Big16:
Executed by:
  • tst_QMimeDatabase
Big16:
executed 65 times by 1 test: case Big16:
Executed by:
  • tst_QMimeDatabase
65
255 case
executed 20 times by 1 test: case Host16:
Executed by:
  • tst_QMimeDatabase
Host16:
executed 20 times by 1 test: case Host16:
Executed by:
  • tst_QMimeDatabase
20
256 case
executed 85 times by 1 test: case Little16:
Executed by:
  • tst_QMimeDatabase
Little16:
executed 85 times by 1 test: case Little16:
Executed by:
  • tst_QMimeDatabase
85
257 if (m_number <= quint16(-1)
m_number <= quint16(-1)Description
TRUEevaluated 170 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
) {
0-170
258 m_number = m_type == Little16
m_type == Little16Description
TRUEevaluated 85 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 85 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
? qFromLittleEndian<quint16>(m_number) : qFromBigEndian<quint16>(m_number);
85
259 if (m_numberMask == 0
m_numberMask == 0Description
TRUEevaluated 165 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
5-165
260 m_numberMask = quint16(-1);
executed 165 times by 1 test: m_numberMask = quint16(-1);
Executed by:
  • tst_QMimeDatabase
165
261 m_matchFunction = &QMimeMagicRule::matchNumber<quint16>;-
262 }
executed 170 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
170
263 break;
executed 170 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
170
264 case
executed 95 times by 1 test: case Big32:
Executed by:
  • tst_QMimeDatabase
Big32:
executed 95 times by 1 test: case Big32:
Executed by:
  • tst_QMimeDatabase
95
265 case
executed 20 times by 1 test: case Host32:
Executed by:
  • tst_QMimeDatabase
Host32:
executed 20 times by 1 test: case Host32:
Executed by:
  • tst_QMimeDatabase
20
266 case
executed 135 times by 1 test: case Little32:
Executed by:
  • tst_QMimeDatabase
Little32:
executed 135 times by 1 test: case Little32:
Executed by:
  • tst_QMimeDatabase
135
267 if (m_number <= quint32(-1)
m_number <= quint32(-1)Description
TRUEevaluated 250 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
) {
0-250
268 m_number = m_type == Little32
m_type == Little32Description
TRUEevaluated 135 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 115 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
? qFromLittleEndian<quint32>(m_number) : qFromBigEndian<quint32>(m_number);
115-135
269 if (m_numberMask == 0
m_numberMask == 0Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
45-205
270 m_numberMask = quint32(-1);
executed 205 times by 1 test: m_numberMask = quint32(-1);
Executed by:
  • tst_QMimeDatabase
205
271 m_matchFunction = &QMimeMagicRule::matchNumber<quint32>;-
272 }
executed 250 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
250
273 break;
executed 250 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
250
274 default
never executed: default:
:
never executed: default:
0
275 break;
never executed: break;
0
276 }-
277}-
278-
279QByteArray QMimeMagicRule::mask() const-
280{-
281 QByteArray result = m_mask;-
282 if (m_type == String
m_type == StringDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
283-
284 result = "0x" + result.toHex();-
285 }
never executed: end of block
0
286 return
never executed: return result;
result;
never executed: return result;
0
287}-
288-
289bool QMimeMagicRule::matches(const QByteArray &data) const-
290{-
291 const bool ok = m_matchFunction && (
(this->*m_matchFunction)(data)Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 19185 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
this->*m_matchFunction)(data)
(this->*m_matchFunction)(data)Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 19185 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
;
59-19185
292 if (!ok
!okDescription
TRUEevaluated 19185 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 59 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
59-19185
293 return
executed 19185 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
false;
executed 19185 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
19185
294-
295-
296 if (m_subMatches.isEmpty()
m_subMatches.isEmpty()Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
)
22-37
297 return
executed 37 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
true;
executed 37 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
37
298-
299-
300-
301 for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ;-
302 it != end
it != endDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
; ++it ) {
18-22
303 if ((*
(*it).matches(data)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
it).matches(data)
(*it).matches(data)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
) {
4-18
304-
305 return
executed 4 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
4
306 }-
307 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
18
308 return
executed 18 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
false;
executed 18 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
18
309-
310-
311}-
312-
313-
Switch to Source codePreprocessed file

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