[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-optimize
Subject: Re: Mimetype optimization
From: Jakub Stachowski <qbast () go2 ! pl>
Date: 2008-04-23 17:48:18
Message-ID: 200804231948.19155.qbast () go2 ! pl
[Download RAW message or body]
Dnia wtorek, 22 kwietnia 2008, Olivier Goffart napisał:
> Le mardi 22 avril 2008, Jakub Stachowski a écrit :
> > Index: kmimetypefactory.cpp
> > ===================================================================
> > --- kmimetypefactory.cpp (wersja 799070)
> > +++ kmimetypefactory.cpp (kopia robocza)
> > @@ -190,8 +190,10 @@
> > int len = filename.length();
> >
> > // Patterns like "*~", "*.extension"
> > - if (pattern[0] == '*' && len + 1 >= pattern_len &&
> > pattern.indexOf('[') == -1) + if (pattern[0] == '*' &&
> > pattern.indexOf('[') == -1)
> > {
> > + if ( len + 1 < pattern_len ) return false;
> > +
>
> What about patern like *foo*bar*
> this will not match "foobar" anymore.
> I think you should search for '*' in the pattern
Right.
>
> (oh, and is there some escaping in regexp? such as "*foo\?\?" )
Right. Current parser is somehow limited - it does not detect ? or '\'. There
are no pattern with these chars yet, but they may be added.
Attached is a patch to fix these problems.
I added some static QChar() vars (conversion char* -> QChar took ~10% of
matchFileName). Is it a problem?
["mimematchfix.patch" (text/x-diff)]
Index: kmimetypefactory.cpp
===================================================================
--- kmimetypefactory.cpp (wersja 799923)
+++ kmimetypefactory.cpp (kopia robocza)
@@ -182,15 +182,24 @@
return mimeList;
}
+inline static bool specialChars( const QString& pattern )
+{
+ static QChar bracket('[');
+ static QChar question('?');
+ static QChar slash('\\');
+ return ( pattern.contains(bracket) || pattern.contains(question) || \
pattern.contains(slash) ); +}
+
static bool matchFileName( const QString &filename, const QString &pattern )
{
int pattern_len = pattern.length();
if (!pattern_len)
return false;
int len = filename.length();
-
+
+ static QChar asterisk('*');
// Patterns like "*~", "*.extension"
- if (pattern[0] == '*' && pattern.indexOf('[') == -1)
+ if (pattern[0] == asterisk && !specialChars(pattern) && \
pattern.indexOf(asterisk, 1) == -1) {
if ( len + 1 < pattern_len ) return false;
@@ -203,11 +212,11 @@
}
// Patterns like "README*" (well this is currently the only one like that...)
- if (pattern[pattern_len - 1] == '*') {
- if ( len + 1 < pattern_len ) return false;
- if (pattern[0] == '*')
+ if (pattern[pattern_len - 1] == asterisk && !specialChars(pattern) && \
pattern.lastIndexOf(asterisk, -2) < 1 ) { + if (pattern[0] == asterisk)
return filename.indexOf(pattern.mid(1, pattern_len - 2)) != -1;
+ if ( len + 1 < pattern_len ) return false;
const QChar *c1 = pattern.unicode();
const QChar *c2 = filename.unicode();
int cnt = 1;
@@ -217,7 +226,7 @@
}
// Names without any wildcards like "README"
- if (pattern.indexOf('[') == -1 && pattern.indexOf('*') == -1 && \
pattern.indexOf('?')) + if (!pattern.contains(asterisk) && \
!specialChars(pattern)) return (pattern == filename);
// Other patterns, like "[Mm]akefile": use slow but correct method
_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic