Monday, November 08, 2010 at 12:06 AM.

system.verbs.builtins.string.wildcardMatch

on wildcardMatch (s, pattern, flCaseSensitive=true) {
	<<Changes
		<<11/15/02; 2:11:08 PM by JES
			<<Created. Returns true if s matches the wildcard pattern.
	if pattern == "*" {
		return (true)};
	if not flCaseSensitive {
		s = string.lower (s);
		pattern = string.lower (pattern)};
	local (ctparts = string.countFields (pattern, '*'));
	if ctparts == 1 {
		if pattern endswith '*' {
			return (s beginsWith string.mid (pattern, 1, sizeOf (pattern) - 1))};
		return (s == pattern)};
	local (i, endix = 0, sizestring = sizeOf (s));
	for i = 1 to ctparts {
		local (onepart = string.nthField (pattern, '*', i));
		if onepart == "" {
			continue};
		local (ix = string.patternMatch (onepart, string.mid (s, endix, infinity)) );
		if i == 1 {
			if not (s beginsWith onepart) {
				return (false)}};
		if ix == 0 {
			return (false)};
		local (sizepart = sizeOf (onepart));
		if i == ctparts {
			if pattern endswith '*' {
				return (true)};
			return (s endswith onepart)};
		endix = ix + sizepart};
	return (true)}
<<bundle //testing
	<<string.wildcardMatch ("this is a wildcard test", "is*test")
		<<false
	<<string.wildcardMatch ("this is a wildcard test", "*is*test")
		<<true



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.