Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern) | - |
5 | { | - |
6 | | - |
7 | if (weight < m_weight) partially evaluated: weight < m_weight no Evaluation Count:0 | yes Evaluation Count:76 |
| 0-76 |
8 | return; | 0 |
9 | bool replace = weight > m_weight; | - |
10 | if (!replace) { evaluated: !replace yes Evaluation Count:3 | yes Evaluation Count:73 |
| 3-73 |
11 | | - |
12 | if (pattern.length() < m_matchingPatternLength) partially evaluated: pattern.length() < m_matchingPatternLength no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
13 | return; | 0 |
14 | else if (pattern.length() > m_matchingPatternLength) { partially evaluated: pattern.length() > m_matchingPatternLength no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
15 | | - |
16 | replace = true; | - |
17 | } | 0 |
18 | } | - |
19 | if (replace) { evaluated: replace yes Evaluation Count:73 | yes Evaluation Count:3 |
| 3-73 |
20 | m_matchingMimeTypes.clear(); | - |
21 | | - |
22 | m_matchingPatternLength = pattern.length(); | - |
23 | m_weight = weight; | - |
24 | } executed: } Execution Count:73 | 73 |
25 | m_matchingMimeTypes.append(mimeType); | - |
26 | if (pattern.startsWith(QLatin1String("*."))) evaluated: pattern.startsWith(QLatin1String("*.")) yes Evaluation Count:60 | yes Evaluation Count:16 |
| 16-60 |
27 | m_foundSuffix = pattern.mid(2); executed: m_foundSuffix = pattern.mid(2); Execution Count:60 | 60 |
28 | } executed: } Execution Count:76 | 76 |
29 | bool QMimeGlobPattern::matchFileName(const QString &inputFilename) const | - |
30 | { | - |
31 | | - |
32 | | - |
33 | | - |
34 | const QString filename = m_caseSensitivity == Qt::CaseInsensitive ? inputFilename.toLower() : inputFilename; evaluated: m_caseSensitivity == Qt::CaseInsensitive yes Evaluation Count:1488 | yes Evaluation Count:93 |
| 93-1488 |
35 | | - |
36 | const int pattern_len = m_pattern.length(); | - |
37 | if (!pattern_len) partially evaluated: !pattern_len no Evaluation Count:0 | yes Evaluation Count:1581 |
| 0-1581 |
38 | return false; never executed: return false; | 0 |
39 | const int len = filename.length(); | - |
40 | | - |
41 | const int starCount = m_pattern.count(QLatin1Char('*')); | - |
42 | | - |
43 | | - |
44 | if (m_pattern[0] == QLatin1Char('*') && m_pattern.indexOf(QLatin1Char('[')) == -1 && starCount == 1) evaluated: m_pattern[0] == QLatin1Char('*') yes Evaluation Count:93 | yes Evaluation Count:1488 |
partially evaluated: m_pattern.indexOf(QLatin1Char('[')) == -1 no Evaluation Count:0 | yes Evaluation Count:93 |
never evaluated: starCount == 1 | 0-1488 |
45 | { | - |
46 | if (len + 1 < pattern_len) return false; never evaluated: len + 1 < pattern_len never executed: return false; | 0 |
47 | | - |
48 | const QChar *c1 = m_pattern.unicode() + pattern_len - 1; | - |
49 | const QChar *c2 = filename.unicode() + len - 1; | - |
50 | int cnt = 1; | - |
51 | while (cnt < pattern_len && *c1-- == *c2--) never evaluated: cnt < pattern_len never evaluated: *c1-- == *c2-- | 0 |
52 | ++cnt; | 0 |
53 | return cnt == pattern_len; never executed: return cnt == pattern_len; | 0 |
54 | } | - |
55 | | - |
56 | | - |
57 | if (starCount == 1 && m_pattern.at(pattern_len - 1) == QLatin1Char('*')) { evaluated: starCount == 1 yes Evaluation Count:279 | yes Evaluation Count:1302 |
evaluated: m_pattern.at(pattern_len - 1) == QLatin1Char('*') yes Evaluation Count:186 | yes Evaluation Count:93 |
| 93-1302 |
58 | if (len + 1 < pattern_len) return false; executed: return false; Execution Count:47 evaluated: len + 1 < pattern_len yes Evaluation Count:47 | yes Evaluation Count:139 |
| 47-139 |
59 | if (m_pattern.at(0) == QLatin1Char('*')) partially evaluated: m_pattern.at(0) == QLatin1Char('*') no Evaluation Count:0 | yes Evaluation Count:139 |
| 0-139 |
60 | return filename.indexOf(m_pattern.mid(1, pattern_len - 2)) != -1; never executed: return filename.indexOf(m_pattern.mid(1, pattern_len - 2)) != -1; | 0 |
61 | | - |
62 | const QChar *c1 = m_pattern.unicode(); | - |
63 | const QChar *c2 = filename.unicode(); | - |
64 | int cnt = 1; | - |
65 | while (cnt < pattern_len && *c1++ == *c2++) evaluated: cnt < pattern_len yes Evaluation Count:192 | yes Evaluation Count:10 |
evaluated: *c1++ == *c2++ yes Evaluation Count:63 | yes Evaluation Count:129 |
| 10-192 |
66 | ++cnt; executed: ++cnt; Execution Count:63 | 63 |
67 | return cnt == pattern_len; executed: return cnt == pattern_len; Execution Count:139 | 139 |
68 | } | - |
69 | | - |
70 | | - |
71 | if (m_pattern.indexOf(QLatin1Char('[')) == -1 && starCount == 0 && m_pattern.indexOf(QLatin1Char('?'))) evaluated: m_pattern.indexOf(QLatin1Char('[')) == -1 yes Evaluation Count:1209 | yes Evaluation Count:186 |
partially evaluated: starCount == 0 yes Evaluation Count:1209 | no Evaluation Count:0 |
partially evaluated: m_pattern.indexOf(QLatin1Char('?')) yes Evaluation Count:1209 | no Evaluation Count:0 |
| 0-1209 |
72 | return (m_pattern == filename); executed: return (m_pattern == filename); Execution Count:1209 | 1209 |
73 | | - |
74 | | - |
75 | QRegExp rx(m_pattern, Qt::CaseSensitive, QRegExp::WildcardUnix); | - |
76 | return rx.exactMatch(filename); executed: return rx.exactMatch(filename); Execution Count:186 | 186 |
77 | } | - |
78 | | - |
79 | static bool isFastPattern(const QString &pattern) | - |
80 | { | - |
81 | | - |
82 | return pattern.lastIndexOf(QLatin1Char('*')) == 0 | 0 |
83 | && pattern.lastIndexOf(QLatin1Char('.')) == 1 | 0 |
84 | | 0 |
85 | && !pattern.contains(QLatin1Char('?')) | 0 |
86 | && !pattern.contains(QLatin1Char('[')) | 0 |
87 | ; never executed: return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ; | 0 |
88 | } | - |
89 | | - |
90 | void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob) | - |
91 | { | - |
92 | const QString &pattern = glob.pattern(); | - |
93 | qt_noop(); | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | if (glob.weight() == 50 && isFastPattern(pattern) && !glob.isCaseSensitive()) { never evaluated: glob.weight() == 50 never evaluated: isFastPattern(pattern) never evaluated: !glob.isCaseSensitive() | 0 |
100 | | - |
101 | const QString extension = pattern.mid(2).toLower(); | - |
102 | QStringList &patterns = m_fastPatterns[extension]; | - |
103 | if (!patterns.contains(glob.mimeType())) never evaluated: !patterns.contains(glob.mimeType()) | 0 |
104 | patterns.append(glob.mimeType()); never executed: patterns.append(glob.mimeType()); | 0 |
105 | } else { | 0 |
106 | if (glob.weight() > 50) { never evaluated: glob.weight() > 50 | 0 |
107 | if (!m_highWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())) never evaluated: !m_highWeightGlobs.hasPattern(glob.mimeType(), glob.pattern()) | 0 |
108 | m_highWeightGlobs.append(glob); never executed: m_highWeightGlobs.append(glob); | 0 |
109 | } else { | 0 |
110 | if (!m_lowWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())) never evaluated: !m_lowWeightGlobs.hasPattern(glob.mimeType(), glob.pattern()) | 0 |
111 | m_lowWeightGlobs.append(glob); never executed: m_lowWeightGlobs.append(glob); | 0 |
112 | } | 0 |
113 | } | - |
114 | } | - |
115 | | - |
116 | void QMimeAllGlobPatterns::removeMimeType(const QString &mimeType) | - |
117 | { | - |
118 | QMutableHashIterator<QString, QStringList> it(m_fastPatterns); | - |
119 | while (it.hasNext()) { never evaluated: it.hasNext() | 0 |
120 | it.next().value().removeAll(mimeType); | - |
121 | } | 0 |
122 | m_highWeightGlobs.removeMimeType(mimeType); | - |
123 | m_lowWeightGlobs.removeMimeType(mimeType); | - |
124 | } | 0 |
125 | | - |
126 | void QMimeGlobPatternList::match(QMimeGlobMatchResult &result, | - |
127 | const QString &fileName) const | - |
128 | { | - |
129 | | - |
130 | QMimeGlobPatternList::const_iterator it = this->constBegin(); | - |
131 | const QMimeGlobPatternList::const_iterator endIt = this->constEnd(); | - |
132 | for (; it != endIt; ++it) { never evaluated: it != endIt | 0 |
133 | const QMimeGlobPattern &glob = *it; | - |
134 | if (glob.matchFileName(fileName)) never evaluated: glob.matchFileName(fileName) | 0 |
135 | result.addMatch(glob.mimeType(), glob.weight(), glob.pattern()); never executed: result.addMatch(glob.mimeType(), glob.weight(), glob.pattern()); | 0 |
136 | } | 0 |
137 | } | 0 |
138 | | - |
139 | QStringList QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QString *foundSuffix) const | - |
140 | { | - |
141 | | - |
142 | QMimeGlobMatchResult result; | - |
143 | m_highWeightGlobs.match(result, fileName); | - |
144 | if (result.m_matchingMimeTypes.isEmpty()) { never evaluated: result.m_matchingMimeTypes.isEmpty() | 0 |
145 | | - |
146 | | - |
147 | | - |
148 | const int lastDot = fileName.lastIndexOf(QLatin1Char('.')); | - |
149 | if (lastDot != -1) { never evaluated: lastDot != -1 | 0 |
150 | const int ext_len = fileName.length() - lastDot - 1; | - |
151 | const QString simpleExtension = fileName.right(ext_len).toLower(); | - |
152 | | - |
153 | | - |
154 | const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension); | - |
155 | for (QForeachContainer<__typeof__(matchingMimeTypes)> _container_(matchingMimeTypes); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &mime = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
156 | result.addMatch(mime, 50, QLatin1String("*.") + simpleExtension); | - |
157 | } | 0 |
158 | | - |
159 | | - |
160 | } | 0 |
161 | | - |
162 | | - |
163 | m_lowWeightGlobs.match(result, fileName); | - |
164 | } | 0 |
165 | if (foundSuffix) never evaluated: foundSuffix | 0 |
166 | *foundSuffix = result.m_foundSuffix; never executed: *foundSuffix = result.m_foundSuffix; | 0 |
167 | return result.m_matchingMimeTypes; never executed: return result.m_matchingMimeTypes; | 0 |
168 | } | - |
169 | | - |
170 | void QMimeAllGlobPatterns::clear() | - |
171 | { | - |
172 | m_fastPatterns.clear(); | - |
173 | m_highWeightGlobs.clear(); | - |
174 | m_lowWeightGlobs.clear(); | - |
175 | } | 0 |
176 | | - |
177 | | - |
178 | | - |
| | |