MCPcopy Create free account
hub / github.com/KDE/kdevelop / SubstringCache

Class SubstringCache

plugins/quickopen/projectitemquickopen.cpp:33–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32namespace {
33struct SubstringCache
34{
35 explicit SubstringCache(const QString& string = QString())
36 : substring(string)
37 {
38 }
39
40 inline int containedIn(const Identifier& id) const
41 {
42 int index = id.index();
43 QHash<int, int>::const_iterator it = cache.constFind(index);
44 if (it != cache.constEnd()) {
45 return *it;
46 }
47
48 const QString idStr = id.identifier().str();
49
50 int result = idStr.lastIndexOf(substring, -1, Qt::CaseInsensitive);
51 if (result < 0 && !idStr.isEmpty() && !substring.isEmpty()) {
52 // no match; try abbreviations
53 result = matchesAbbreviation(idStr, substring) ? 0 : -1;
54 }
55
56 //here we shift the values if the matched string is bigger than the substring,
57 //so closer matches will appear first
58 if (result >= 0) {
59 result = result + (idStr.size() - substring.size());
60 }
61
62 cache[index] = result;
63
64 return result;
65 }
66
67 QString substring;
68 mutable QHash<int, int> cache;
69};
70
71struct ClosestMatchToText
72{

Callers 1

setFilterTextMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected