View/Edit #29:match_stringlist match_string_list

Switch to edit mode.

Name(s): match_stringlist match_string_list
1:  "Copied from Puff (#1449):match_stringlist Tue Oct 19 08:18:13 1993 PDT"
2:  "$string_utils:match_stringlist(string, {list of strings})"
3:  "The list of strings should be just that, a list of strings.  The first string is matched against the list of strings."
4:  "If it exactly matches exactly one of them, the index of the match is returned. If it exactly matches more than one of them, $ambiguous_match is returned."
5:  "If there are no exact matches, then partial matches are considered, ones in which the given string is a prefix of one of the strings."
6:  "Again, if exactly one match is found, the index of that string is returned, and if more than one match is found, $ambiguous match is returned."
7:  "Finally, if there are no exact or partial matches, then $failed_match is returned."
8:  if (length(args) < 2 || args[1] == "" || length(args[2]) < 1)
9:    return $nothing
10: endif
11: subject = args[1]
12: stringlist = args[2]
13: matches = {}
14: "First check for exact matches."
15: for i in [1..length(stringlist)]
16:   if (subject == stringlist[i])
17:     matches = {@matches, i}
18:   endif
19: endfor
20: "Now return a match, or $ambiguous, or check for partial matches."
21: if (length(matches) == 1)
22:   return matches[1]
23: elseif (length(matches) > 1)
24:   return $ambiguous_match
25: elseif (length(matches) == 0)
26:   "Checking for partial matches is almost identical to checking for exact matches, but we use index(list[i], target) instead of list[i] == target to see if they match."
27:   for i in [1..length(stringlist)]
28:     if (index(stringlist[i], subject) == 1)
29:       matches = {@matches, i}
30:     endif
31:   endfor
32:   if (length(matches) == 1)
33:     return matches[1]
34:   elseif (length(matches) > 1)
35:     return $ambiguous_match
36:   elseif (length(matches) == 0)
37:     return $failed_match
38:   endif
39: endif

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Hacker (#60)

You are not logged in.

[home | help | who | search | setup | code]