[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kate/mode
From: Sebastian Pipping <webmaster () hartwork ! org>
Date: 2007-10-16 17:13:17
Message-ID: 1192554797.416535.26818.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 725946 by sping:
Speed up mode detection, review wanted
M +26 -22 katemodemanager.cpp
M +6 -0 katemodemanager.h
--- trunk/KDE/kdelibs/kate/mode/katemodemanager.cpp #725945:725946
@@ -277,40 +277,44 @@
return "";
}
+/*static*/ QString KateModeManager::reverse(const QString & text) {
+ const int len = text.length();
+ QString res;
+ res.reserve(len);
+ for (int i = len - 1; i >= 0; i--) {
+ res.append(text[i]);
+ }
+ return res;
+}
+
QString KateModeManager::wildcardsFind (const QString &fileName)
{
- QList<KateFileType*> types;
+ const QString reversedFilename = reverse(fileName);
+ QRegExp re;
+ re.setCaseSensitivity(Qt::CaseSensitive);
+ re.setPatternSyntax(QRegExp::Wildcard);
+
+ KateFileType * match = NULL;
+ int minPrio = -1;
foreach (KateFileType *type, m_types)
{
- foreach (QString wildcard, type->wildcards)
- {
- // anders: we need to be sure to match the end of string, as eg a css file
- // would otherwise end up with the c hl
- QRegExp re(wildcard, Qt::CaseSensitive, QRegExp::Wildcard);
- if ( ( re.indexIn( fileName ) > -1 ) && ( re.matchedLength() == (int)fileName.length() ) )
- types.append (type);
+ if (type->priority <= minPrio) {
+ continue;
}
- }
- if ( !types.isEmpty() )
- {
- int pri = -1;
- QString name;
-
- foreach (KateFileType *type, types)
+ foreach (QString wildcard, type->wildcards)
{
- if (type->priority > pri)
- {
- pri = type->priority;
- name = type->name;
+ re.setPattern(reverse(wildcard));
+ if (re.exactMatch(reversedFilename)) {
+ match = type;
+ minPrio = type->priority;
+ break;
}
}
-
- return name;
}
- return "";
+ return (match == NULL) ? "" : match->name;
}
const KateFileType& KateModeManager::fileType(const QString &name) const
--- trunk/KDE/kdelibs/kate/mode/katemodemanager.h #725945:725946
@@ -77,6 +77,12 @@
private:
QList<KateFileType *> m_types;
QHash<QString, KateFileType *> m_name2Type;
+
+ /**
+ * Reverses a string on char level, i.e. "abc" becomes "cba".
+ */
+ static QString reverse(const QString & text);
+
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic