|
Kent C. Dorner wrote:
Jack's code would not stand a minute of our code reviews.
I suggest that your "large programmer team" stick to Java. I would be happy to see your team come up with something better. Keep in mind that no matter what your wife might say, performance does matter.
-Jack
There are 10 types of people in this world, those that understand binary and those who don't.
|
|
|
|
|
ok, for all you f***ing managed c++ bozo's out there, listen up. I challenge ANY of you to jump into stl and say its readable. No wonder IBM Billing is such a POS if they would rather have "easier" readability in code then performance.
Oh yeah, c++ guru, some f***ing guru, ever hear of inline you f***ing putz ?
I googled this wildcmp function, and bar none its the best damn wild compare I have seen yet. I can't believe some of the nonsense that is being posted here as an attempt to discredit the author for some reason unbeknownst to me.
and finally, for you babies who can't stand to manage their own pointers (et al managed c++ bozos)
if ( ( !string ) || ( !wild ) )
return( 0 );
|
|
|
|
|
YEAh this code is the sh*t. And his code does make more sense if you are able to think outsdie the box rather than whien about no recursion. The fact of the matter is that if his solution is better than you should use it, thats the whole point of a polymorphic language. And if you dont understand pointers enough to pass null pointers into functions, well... maybe you should... rewrite the code so it checks for pointers?
I am but a lowly highschool student, but i've been coding since i was 7. And anyways, if you want to know what kind of program would require intense wildcard comparing, well, I wrote a program that auto-comments a source code file using a wildcard scheme, basically checks each line based on wildcard queries it loads up from a file and if the test is successful it inserts that comment at the end of that line. Pretty mindless commenting, but its just cause i'm sick of commenting my CS homework. So yeah, Jack Handy is the man.
http://www.coxar.pwp.blueyonder.co.uk/
|
|
|
|
|
Both of you wrote good code that is simple and readable,
In any case for many of us is no problem to write something like this but I would use their code just to reduce time for development, I think we have to say a lot of thanks. So guys just be a litle bit polite to each other.
|
|
|
|
|
Thanks for the code! I was searching the web for a simple wildcard matching routine ... I don't want full blown regular expressions, I just want to do simple wildcards against a list of filenames. This is perfect!
|
|
|
|
|
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!
|
|
|
|
|