|
You might want to look into the PathMatchSpec() function in shlwapi.dll.
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Now _that's_ what I was looking for.
Thanks!
Steve
|
|
|
|
|
I found this very useful. thx!
Todd Smith
|
|
|
|
|
I ran the following test cases through wildcmp, all successful. (The test() function compares the pattern to the input string, and compares against the expected result).
test( "", "", true );
test( "*", "", true );
test( "*", "A", true );
test( "", "A", false );
test( "A*", "", false );
test( "A*", "AAB", true );
test( "A*", "BAA", false );
test( "A*", "A", true );
test( "A*B", "", false );
test( "A*B", "AAB", true );
test( "A*B", "AB", true );
test( "A*B", "AABA", false );
test( "A*B", "ABAB", true );
test( "A*B", "ABBBB", true );
test( "A*B*C", "", false );
test( "A*B*C", "ABC", true );
test( "A*B*C", "ABCC", true );
test( "A*B*C", "ABBBC", true );
test( "A*B*C", "ABBBBCCCC", true );
test( "A*B*C", "ABCBBBCBCCCBCBCCCC", true );
test( "A*B*", "AB", true );
test( "A*B*", "AABA", true );
test( "A*B*", "ABAB", true );
test( "A*B*", "ABBBB", true );
test( "A*B*C*", "", false );
test( "A*B*C*", "ABC", true );
test( "A*B*C*", "ABCC", true );
test( "A*B*C*", "ABBBC", true );
test( "A*B*C*", "ABBBBCCCC", true );
test( "A*B*C*", "ABCBBBCBCCCBCBCCCC", true );
test( "A?", "AAB", false );
test( "A?B", "AAB", true );
test( "A?*", "A", false );
test( "A?*", "ABBCC", true );
test( "A?*", "BAA", false );
Paul McGuire
KLA-Tencor/Process Analysis & Control Division
Austin, TX
|
|
|
|
|
Your test #7 prove the bug i found in this code:
pattern: start*end
will not match text: start___end___end
it will not since the second look will go and perform match to the first part of the string: start___end
and then will return false since we did eached the end of the pattern but not the end of the string
|
|
|
|
|
Do you have a regex formatter/matcher source code. Please reply, Thanks!
|
|
|
|
|
This is EXACTLY what I have been looking for! I have been searching the web for a simple wildcard matcher, and all I have found is regex after regex of source code. I even started reading a regex tutorial. Why waste time learning regex and bloating my program with 20k of regex code I'll never use when 20 lines of pure bliss can be inserted? Thanks!!!!!
|
|
|
|
|
Besides - smaller code = faster code.
Speed = Better Program.
Chris
|
|
|
|
|
Yes, the code is quite fine and concise (even if i prefer regexes)
BUT
> Besides - smaller code = faster code.
That's quite a wrong asumption !
Just looking at other threads in the same discussion will show you the contrary : a proposed shorter version was in fact slower.
This kind of reasoning date back to the prehistoric times of dumb-compilers
(and was not even completely true at that time !)
If you want speed use profiling / benchmarks not character counting methods !
> Speed = Better Program.
OK so the "null" program, wich executes in no time, is the best of all.
Right ?
What makes a good program is FUNCTIONNALITY : something that has to do with the real world and the people in front of the computer !
|
|
|
|
|
you're quite right in your argument.
what i do want to underline as a result of experience in building large software systems is: SMALLER IS NOT NECESSARILY BETTER/FASTER. in most cases it's not even faster to code!
what is true is that SMALL and UNREADABLE snippets IMPRESS MORE. maybe you get a hotter chick with that.
i admit this even it was me who wrote the shorter but slower wildcard matcher .
|
|
|
|
|
Guru, You're a douche bag.
And all that null program stuff is bullshit. Obviously the best program is first the one that works in all cases, then the fastest, and then smallest. Pretty simple criteria, really not necessary to be argue about. And readabillity has nothing to do with it, unless you are considering it from the computers standpoint, which I think is covered in the first criteria, no?
And small unreadable snippets are far better than bloated newb fragments if they run faster. And who said anything about impress more? you can stop taking pot shots at jack handy now, just because hes a better programmer than you doesnt mean you should try to bust his chops. Maybe if you werent such a f***ing pussy you'd "get a hotter chick". Clearly Jack Handy is able to write code that accomplishes a task more efficiently than you can. Yet you still try criticize, and then you come back with this post full of big bold text about irrelevant points... Maybe if your post is partly in bold it will IMPRESS MORE. F***ing douche.
|
|
|
|
|
wildcmp("fold","??*"); should match.
This message has been virus scanned
|
|
|
|
|
wildcmp("??*", "fold");
This matches.. you had the args reversed
|
|
|
|
|
Under DOS / Windows following line should return positive result
wildcmp("*.*", "aaaaa")
It would be nice if you would add this feature too
Miroslav Rajcic
http://www.spacetide.com
|
|
|
|
|
This would be easy to add, however if you were using it on a hostmask instead of a file and tried to match "*.*" and you really want the '.' to be there it would not give you the desired results. So here would be my workaround..
if ((strcmp(mywild, "*.*") == 0) || (wildcmp(mywild, "blah.jpg"))) {
} else {
}
P.S. There was a bug in the function that caused some conditions to fail so update your code with the current function
|
|
|
|
|
Your workaround works only for "*.*" but does not solve the problem generally.
Example:
wildcmp("a*.*", "aaaa") should return true under DOS conventions.
Miroslav Rajcic
http://www.spacetide.com
|
|
|
|
|
I stumbled upon this thread looking for something completely different, but noticed that someone needed a little help
The easiest way to make the function compatible with DOS patterns without breaking the intended functionallity of the wildcmp() function is to simply add a wrapper function that adds a dot character at the end of strings that do not already have a dot and then call the wildcmp() function.
Please note: This is a very simple 'hack', but serves it purpose well. The STL string class offers so much more security than plain old char pointers, but that was just a side-note
int doswildcmp(char *wild, char *string) {
if ( 0 == strstr( string, "." ) ) {
char *newstring = ( char* )malloc( strlen( string ) + 2 );
strcpy( newstring, string );
strcat( newstring, "." );
int result = wildcmp( wild, newstring );
free( newstring );
return result;
}
else return wildcmp( wild, string );
}
Fredrik Wangel Top Node Development AB
|
|
|
|
|
You're either trying to be funny, or you're just clueless.
The reason a command like "dir *.*" in DOS, or a Windows DOS box, will also yield files that have no extension, is that, well, even without an extension, the dot is still there. You CAN'T have a filename without a dot in it under DOS or Windows, that's just the way the file systems (FAT, NTFS, others) work.
The reason you can still do something like "type bleh" to get the contents of the file "bleh." is because DOS is so clever - it knows that there's supposed to be a dot there, even if the user forgot to type it in.
Illuminating cyberspace since 1983
[ PlanetCPP ][ home of the n00blist ]
|
|
|
|
|
Why don't use a normal regex? There are so many regex libraries floating around
which offer more functionality.
<sarcasm>
Apparently this is the Wheel Mark II.
|
|
|
|
|
I challenge you to provide a regex library in 20 lines of code
You might only want to provide basic wildcard support, particularly for tools used by people used to DOS wildcards. Regular expressions are great, but sometimes you don't want to have to work out the format of your search string!
|
|
|
|
|
You might also want very, very small code. So that it runs quickly.
Chris
|
|
|
|
|
Because regex is a complete mystery to my end users. These are not software people who want to master the intricacies of ^'s, []'s, .'s, and *'s (and don't forget the \'s!) - they just want to find every equipment in the factory that matches "DRILL*".
Actually, if you look around in the real world, there are many kinds of wheels out there. I'm glad someone came up with a nice light bicycle wheel for my small project, instead of my having to lug around a huge differential, axle, and automobile wheel assembly, just to do this basic feature.
Thanks for this nice piece of work!
Paul McGuire
KLA-Tencor/Process Analysis & Control Division
Austin, TX
|
|
|
|
|