| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimeglobpattern.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern) | - | ||||||||||||||||||
| 7 | { | - | ||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | if (weight < m_weight
| 6-155 | ||||||||||||||||||
| 10 | return; executed 6 times by 1 test: return;Executed by:
| 6 | ||||||||||||||||||
| 11 | bool replace = weight > m_weight; | - | ||||||||||||||||||
| 12 | if (!replace
| 13-142 | ||||||||||||||||||
| 13 | - | |||||||||||||||||||
| 14 | if (pattern.length() < m_matchingPatternLength
| 0-13 | ||||||||||||||||||
| 15 | return; never executed: return; | 0 | ||||||||||||||||||
| 16 | else if (pattern.length() > m_matchingPatternLength
| 6-7 | ||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | replace = true; | - | ||||||||||||||||||
| 19 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 20 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 21 | if (replace
| 7-148 | ||||||||||||||||||
| 22 | m_matchingMimeTypes.clear(); | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | m_matchingPatternLength = pattern.length(); | - | ||||||||||||||||||
| 25 | m_weight = weight; | - | ||||||||||||||||||
| 26 | } executed 148 times by 1 test: end of blockExecuted by:
| 148 | ||||||||||||||||||
| 27 | if (!m_matchingMimeTypes.contains(mimeType)
| 1-154 | ||||||||||||||||||
| 28 | m_matchingMimeTypes.append(mimeType); | - | ||||||||||||||||||
| 29 | if (pattern.startsWith(QLatin1String("*."))
| 26-128 | ||||||||||||||||||
| 30 | m_foundSuffix = pattern.mid(2); executed 128 times by 1 test: m_foundSuffix = pattern.mid(2);Executed by:
| 128 | ||||||||||||||||||
| 31 | } executed 154 times by 1 test: end of blockExecuted by:
| 154 | ||||||||||||||||||
| 32 | } executed 155 times by 1 test: end of blockExecuted by:
| 155 | ||||||||||||||||||
| 33 | bool QMimeGlobPattern::matchFileName(const QString &inputFilename) const | - | ||||||||||||||||||
| 34 | { | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | const QString filename = m_caseSensitivity == Qt::CaseInsensitive
| 382-6116 | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | const int pattern_len = m_pattern.length(); | - | ||||||||||||||||||
| 41 | if (!pattern_len
| 0-6498 | ||||||||||||||||||
| 42 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 43 | const int len = filename.length(); | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | const int starCount = m_pattern.count(QLatin1Char('*')); | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | if (m_pattern[0] == QLatin1Char('*')
| 0-3454 | ||||||||||||||||||
| 49 | { | - | ||||||||||||||||||
| 50 | if (len + 1 < pattern_len
executed 686 times by 1 test: false;return false;Executed by:
executed 686 times by 1 test: return false;Executed by:
| 686-2578 | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | const QChar *c1 = m_pattern.unicode() + pattern_len - 1; | - | ||||||||||||||||||
| 53 | const QChar *c2 = filename.unicode() + len - 1; | - | ||||||||||||||||||
| 54 | int cnt = 1; | - | ||||||||||||||||||
| 55 | while (cnt < pattern_len
| 10-2907 | ||||||||||||||||||
| 56 | ++ executed 339 times by 1 test: cnt;++cnt;Executed by:
executed 339 times by 1 test: ++cnt;Executed by:
| 339 | ||||||||||||||||||
| 57 | return executed 2578 times by 1 test: cnt == pattern_len;return cnt == pattern_len;Executed by:
executed 2578 times by 1 test: return cnt == pattern_len;Executed by:
| 2578 | ||||||||||||||||||
| 58 | } | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (starCount == 1
| 190-2664 | ||||||||||||||||||
| 62 | if (len + 1 < pattern_len
executed 100 times by 1 test: false;return false;Executed by:
executed 100 times by 1 test: return false;Executed by:
| 100-280 | ||||||||||||||||||
| 63 | if (m_pattern.at(0) == QLatin1Char('*')
| 0-280 | ||||||||||||||||||
| 64 | return never executed: filename.indexOf(m_pattern.mid(1, pattern_len - 2)) != -1;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 | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | const QChar *c1 = m_pattern.unicode(); | - | ||||||||||||||||||
| 67 | const QChar *c2 = filename.unicode(); | - | ||||||||||||||||||
| 68 | int cnt = 1; | - | ||||||||||||||||||
| 69 | while (cnt < pattern_len
| 20-386 | ||||||||||||||||||
| 70 | ++ executed 126 times by 1 test: cnt;++cnt;Executed by:
executed 126 times by 1 test: ++cnt;Executed by:
| 126 | ||||||||||||||||||
| 71 | return executed 280 times by 1 test: cnt == pattern_len;return cnt == pattern_len;Executed by:
executed 280 times by 1 test: return cnt == pattern_len;Executed by:
| 280 | ||||||||||||||||||
| 72 | } | - | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | if (m_pattern.indexOf(QLatin1Char('[')) == -1
| 0-2474 | ||||||||||||||||||
| 76 | return executed 2474 times by 1 test: (m_pattern == filename);return (m_pattern == filename);Executed by:
executed 2474 times by 1 test: return (m_pattern == filename);Executed by:
| 2474 | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | QRegExp rx(m_pattern, Qt::CaseSensitive, QRegExp::WildcardUnix); | - | ||||||||||||||||||
| 80 | return executed 380 times by 1 test: rx.exactMatch(filename);return rx.exactMatch(filename);Executed by:
executed 380 times by 1 test: return rx.exactMatch(filename);Executed by:
| 380 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | static bool isFastPattern(const QString &pattern) | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | return executed 4126 times by 1 test: pattern.lastIndexOf(QLatin1Char('*')) == 0return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ;Executed by:
executed 4126 times by 1 test: return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ;Executed by:
| 70-4126 | ||||||||||||||||||
| 87 | && pattern.lastIndexOf(QLatin1Char('.')) == 1
executed 4126 times by 1 test: return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ;Executed by:
| 160-4126 | ||||||||||||||||||
| 88 | 4126 | |||||||||||||||||||
| 89 | && !pattern.contains(QLatin1Char('?'))
executed 4126 times by 1 test: return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ;Executed by:
| 0-4126 | ||||||||||||||||||
| 90 | && !pattern.contains(QLatin1Char('['))
executed 4126 times by 1 test: return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ;Executed by:
| 5-4126 | ||||||||||||||||||
| 91 | ; executed 4126 times by 1 test: return pattern.lastIndexOf(QLatin1Char('*')) == 0 && pattern.lastIndexOf(QLatin1Char('.')) == 1 && !pattern.contains(QLatin1Char('?')) && !pattern.contains(QLatin1Char('[')) ;Executed by:
| 4126 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob) | - | ||||||||||||||||||
| 95 | { | - | ||||||||||||||||||
| 96 | const QString &pattern = glob.pattern(); | - | ||||||||||||||||||
| 97 | ((!(!pattern.isEmpty())) ? qt_assert("!pattern.isEmpty()",__FILE__,154) : qt_noop()); | - | ||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | if (glob.weight() == 50
| 10-4126 | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | const QString extension = pattern.mid(2).toLower(); | - | ||||||||||||||||||
| 106 | QStringList &patterns = m_fastPatterns[extension]; | - | ||||||||||||||||||
| 107 | if (!patterns.contains(glob.mimeType())
| 12-3869 | ||||||||||||||||||
| 108 | patterns.append(glob.mimeType()); executed 3869 times by 1 test: patterns.append(glob.mimeType());Executed by:
| 3869 | ||||||||||||||||||
| 109 | } executed 3881 times by 1 test: else {end of blockExecuted by:
| 3881 | ||||||||||||||||||
| 110 | if (glob.weight() > 50
| 0-255 | ||||||||||||||||||
| 111 | if (!m_highWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())
| 0 | ||||||||||||||||||
| 112 | m_highWeightGlobs.append(glob); never executed: m_highWeightGlobs.append(glob); | 0 | ||||||||||||||||||
| 113 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 114 | if (!m_lowWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())
| 0-255 | ||||||||||||||||||
| 115 | m_lowWeightGlobs.append(glob); executed 255 times by 1 test: m_lowWeightGlobs.append(glob);Executed by:
| 255 | ||||||||||||||||||
| 116 | } executed 255 times by 1 test: end of blockExecuted by:
| 255 | ||||||||||||||||||
| 117 | } | - | ||||||||||||||||||
| 118 | } | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | void QMimeAllGlobPatterns::removeMimeType(const QString &mimeType) | - | ||||||||||||||||||
| 121 | { | - | ||||||||||||||||||
| 122 | QMutableHashIterator<QString, QStringList> it(m_fastPatterns); | - | ||||||||||||||||||
| 123 | while (it.hasNext()
| 0 | ||||||||||||||||||
| 124 | it.next().value().removeAll(mimeType); | - | ||||||||||||||||||
| 125 | } never executed: end of block | 0 | ||||||||||||||||||
| 126 | m_highWeightGlobs.removeMimeType(mimeType); | - | ||||||||||||||||||
| 127 | m_lowWeightGlobs.removeMimeType(mimeType); | - | ||||||||||||||||||
| 128 | } never executed: end of block | 0 | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | void QMimeGlobPatternList::match(QMimeGlobMatchResult &result, | - | ||||||||||||||||||
| 131 | const QString &fileName) const | - | ||||||||||||||||||
| 132 | { | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | QMimeGlobPatternList::const_iterator it = this->constBegin(); | - | ||||||||||||||||||
| 135 | const QMimeGlobPatternList::const_iterator endIt = this->constEnd(); | - | ||||||||||||||||||
| 136 | for (; it != endIt
| 192-4896 | ||||||||||||||||||
| 137 | const QMimeGlobPattern &glob = *it; | - | ||||||||||||||||||
| 138 | if (glob.matchFileName(fileName)
| 26-4870 | ||||||||||||||||||
| 139 | result.addMatch(glob.mimeType(), glob.weight(), glob.pattern()); executed 26 times by 1 test: result.addMatch(glob.mimeType(), glob.weight(), glob.pattern());Executed by:
| 26 | ||||||||||||||||||
| 140 | } executed 4896 times by 1 test: end of blockExecuted by:
| 4896 | ||||||||||||||||||
| 141 | } executed 192 times by 1 test: end of blockExecuted by:
| 192 | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | QStringList QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QString *foundSuffix) const | - | ||||||||||||||||||
| 144 | { | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | QMimeGlobMatchResult result; | - | ||||||||||||||||||
| 147 | m_highWeightGlobs.match(result, fileName); | - | ||||||||||||||||||
| 148 | if (result.m_matchingMimeTypes.isEmpty()
| 0-96 | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | const int lastDot = fileName.lastIndexOf(QLatin1Char('.')); | - | ||||||||||||||||||
| 153 | if (lastDot != -1
| 25-71 | ||||||||||||||||||
| 154 | const int ext_len = fileName.length() - lastDot - 1; | - | ||||||||||||||||||
| 155 | const QString simpleExtension = fileName.right(ext_len).toLower(); | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension); | - | ||||||||||||||||||
| 159 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(matchingMimeTypes)>::type> _container_((matchingMimeTypes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &mime = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 160 | result.addMatch(mime, 50, QLatin1String("*.") + simpleExtension); | - | ||||||||||||||||||
| 161 | } executed 57 times by 1 test: end of blockExecuted by:
| 57 | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | } executed 71 times by 1 test: end of blockExecuted by:
| 71 | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | m_lowWeightGlobs.match(result, fileName); | - | ||||||||||||||||||
| 168 | } executed 96 times by 1 test: end of blockExecuted by:
| 96 | ||||||||||||||||||
| 169 | if (foundSuffix
| 8-88 | ||||||||||||||||||
| 170 | * executed 8 times by 1 test: foundSuffix = result.m_foundSuffix;*foundSuffix = result.m_foundSuffix;Executed by:
executed 8 times by 1 test: *foundSuffix = result.m_foundSuffix;Executed by:
| 8 | ||||||||||||||||||
| 171 | return executed 96 times by 1 test: result.m_matchingMimeTypes;return result.m_matchingMimeTypes;Executed by:
executed 96 times by 1 test: return result.m_matchingMimeTypes;Executed by:
| 96 | ||||||||||||||||||
| 172 | } | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | void QMimeAllGlobPatterns::clear() | - | ||||||||||||||||||
| 175 | { | - | ||||||||||||||||||
| 176 | m_fastPatterns.clear(); | - | ||||||||||||||||||
| 177 | m_highWeightGlobs.clear(); | - | ||||||||||||||||||
| 178 | m_lowWeightGlobs.clear(); | - | ||||||||||||||||||
| 179 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |