MatchWild
by
Joe Strout
MatchWild is not a class; instead, it is a simple module
containing four functions:
- int IsWild(p): return 1 if p contains any wildcards
- int MatchWild(s,p): return 1 if s matches p,
where p may contain wildcards
- void ReplaceWild(d,n,p2): replace wild cards in p2
with stuff frem previous MatchWild; store result in d (an array of n chars)
- MatchReplaceWild(d,n,s,p1,p2): if s matches p1,
stuff matching parts into wildcards of p2 and store result in d, and
return 1; else return 0
In these functions, all parameters are character pointers (const where
appropriate) except n, which is the length of a buffer to hold the result
of a replace operation. (It's OK for this buffer to be the same as one
of the source strings.)
The only currently supported wildcard is the asterisk, which matches zero
or more characters.
Examples
MatchWild( "this is a test", "this*") returns 1
MatchWild( "is this a test", "this*") returns 0
MatchWild( "is this a test", "*this*") returns 1
char d[80]; ReplaceWild(d,80, "*that*")
stuffs "is that a test" into d (assuming previous call above)
MatchReplaceWild(d,80,"is this a test","*is*","*was*")
stuffs "was this a test" into d and returns 1
Here's the code...
Share and enjoy!
http://www-ncmir.ucsd.edu/~jstrout/classlib/MatchWild.html
Last Updated:
9/23/96
Joe Strout (
joe@strout.net )