Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/interfaces/abbreviations.cpp
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | 152 | if ( matchedFragments == typedFragments.size() ) { | |||
---|---|---|---|---|---|
153 | break; | 153 | break; | ||
154 | } | 154 | } | ||
155 | } | 155 | } | ||
156 | lastSpace = isDoubleColon ? i : i+1; | 156 | lastSpace = isDoubleColon ? i : i+1; | ||
157 | } | 157 | } | ||
158 | return matchedFragments == typedFragments.size(); | 158 | return matchedFragments == typedFragments.size(); | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | PathFilterMatchQuality matchPathFilter(const Path &toFilter, const QStringList &text) | 161 | int matchPathFilter(const Path &toFilter, const QStringList &text) | ||
162 | { | 162 | { | ||
163 | enum PathFilterMatchQuality { | ||||
164 | NoMatch = -1, | ||||
165 | ExactMatch = 0, | ||||
166 | StartMatch = 1, | ||||
167 | OtherMatch = 2 // and anything higher than that | ||||
168 | }; | ||||
163 | const QVector<QString>& segments = toFilter.segments(); | 169 | const QVector<QString>& segments = toFilter.segments(); | ||
164 | 170 | | |||
165 | if (text.count() > segments.count()) { | 171 | if (text.count() > segments.count()) { | ||
166 | // number of segments mismatches, thus item cannot match | 172 | // number of segments mismatches, thus item cannot match | ||
167 | return PathFilterMatchQuality::NoMatch; | 173 | return NoMatch; | ||
168 | } | 174 | } | ||
169 | { | 175 | { | ||
170 | bool allMatched = true; | 176 | bool allMatched = true; | ||
171 | // try to put exact matches up front | 177 | // try to put exact matches up front | ||
172 | for(int i = segments.count() - 1, j = text.count() - 1; | 178 | for(int i = segments.count() - 1, j = text.count() - 1; | ||
173 | i >= 0 && j >= 0; --i, --j) | 179 | i >= 0 && j >= 0; --i, --j) | ||
174 | { | 180 | { | ||
175 | if (segments.at(i) != text.at(j)) { | 181 | if (segments.at(i) != text.at(j)) { | ||
176 | allMatched = false; | 182 | allMatched = false; | ||
177 | break; | 183 | break; | ||
178 | } | 184 | } | ||
179 | } | 185 | } | ||
180 | if (allMatched) { | 186 | if (allMatched) { | ||
181 | return PathFilterMatchQuality::ExactMatch; | 187 | return ExactMatch; | ||
182 | } | 188 | } | ||
183 | } | 189 | } | ||
184 | 190 | | |||
185 | int searchIndex = 0; | 191 | int searchIndex = 0; | ||
186 | int pathIndex = 0; | 192 | int pathIndex = 0; | ||
187 | int lastMatchIndex = -1; | 193 | int lastMatchIndex = -1; | ||
188 | // stop early if more search fragments remain than available after path index | 194 | // stop early if more search fragments remain than available after path index | ||
189 | while (pathIndex < segments.size() && searchIndex < text.size() | 195 | while (pathIndex < segments.size() && searchIndex < text.size() | ||
Show All 16 Lines | 209 | if (!isMatch) { | |||
206 | continue; | 212 | continue; | ||
207 | } | 213 | } | ||
208 | // else we matched | 214 | // else we matched | ||
209 | ++searchIndex; | 215 | ++searchIndex; | ||
210 | ++pathIndex; | 216 | ++pathIndex; | ||
211 | } | 217 | } | ||
212 | 218 | | |||
213 | if (searchIndex != text.size()) { | 219 | if (searchIndex != text.size()) { | ||
214 | return PathFilterMatchQuality::NoMatch; | 220 | return NoMatch; | ||
215 | } | 221 | } | ||
216 | 222 | | |||
217 | // prefer matches whose last element starts with the filter | 223 | // prefer matches whose last element starts with the filter | ||
218 | if (pathIndex == segments.size() && lastMatchIndex == 0) { | 224 | if (pathIndex == segments.size() && lastMatchIndex == 0) { | ||
219 | return PathFilterMatchQuality::StartMatch; | 225 | return StartMatch; | ||
220 | } else { | 226 | } else { | ||
221 | return PathFilterMatchQuality::OtherMatch; | 227 | return OtherMatch; | ||
222 | } | 228 | } | ||
223 | } | 229 | } | ||
224 | 230 | | |||
225 | } // namespace KDevelop | 231 | } // namespace KDevelop | ||
226 | 232 | | |||
227 | // kate: space-indent on; indent-width 2 | 233 | // kate: space-indent on; indent-width 2 |