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

Method languagesForFileName

kdevplatform/shell/languagecontroller.cpp:85–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85QList<ILanguageSupport*> MimeTypeCache::languagesForFileName(const QString& fileName) const
86{
87 if (fileName.isEmpty()) {
88 // The file name of a remote URL that ends with a slash is empty, but such a URL can still reference a file.
89 // An empty file name cannot match a MIME type.
90 return {};
91 }
92
93 QList<ILanguageSupport*> languages;
94 // lastLanguageEquals() helps to improve performance by skipping checks for an already added language.
95 const auto lastLanguageEquals = [&languages](const ILanguageSupport* lang) {
96 return !languages.empty() && languages.constLast() == lang;
97 };
98
99 const auto lastChar = fileName.back().toLower();
100 for (auto it = m_suffixes.constFind(lastChar); it != m_suffixes.cend() && it.key() == lastChar; ++it) {
101 const auto lang = it.value().second;
102 if (!lastLanguageEquals(lang) && fileName.endsWith(it.value().first, Qt::CaseInsensitive)) {
103 languages.push_back(lang);
104 }
105 }
106
107 for (const auto& p : m_literalPatterns) {
108 if (fileName.compare(p.first, Qt::CaseInsensitive) == 0 && !lastLanguageEquals(p.second)) {
109 languages.push_back(p.second);
110 }
111 }
112
113 for (const auto& p : m_regularExpressions) {
114 if (!lastLanguageEquals(p.second) && p.first.match(fileName).hasMatch()) {
115 languages.push_back(p.second);
116 }
117 }
118
119 return languages;
120}
121
122void MimeTypeCache::addGlobPattern(const QString& pattern, ILanguageSupport* language)
123{

Callers 1

languagesForUrlMethod · 0.80

Calls 11

emptyMethod · 0.80
endsWithMethod · 0.80
hasMatchMethod · 0.80
isEmptyMethod · 0.45
backMethod · 0.45
constFindMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45
push_backMethod · 0.45
compareMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected