prefix
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | prefix [2006/08/29 16:08] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | # $EPIC: prefix.txt, | ||
+ | ======Synopsis: | ||
+ | $__prefix__(< | ||
+ | |||
+ | ======Technical: | ||
+ | * If the <word list> argument is omitted the empty string is returned. | ||
+ | * The return value of this function is whatever string is the common initial substring (CIS) of all of the words in <word list> | ||
+ | * This function uses an O(M*N) algorithm where M is the number of words in <word list> and N is the length of the first word in <word list>. Take this into consideration when planning. | ||
+ | |||
+ | ======Practical: | ||
+ | This function can be used to do pseudo-completion. | ||
+ | consider if you are working on a tab completion script and the user | ||
+ | types " | ||
+ | everything that matched " | ||
+ | word? It is considerate to the user to complete as much as possible for | ||
+ | them and then prompt them for the rest. So let's say that you had two | ||
+ | users, " | ||
+ | " | ||
+ | |||
+ | < | ||
+ | # Some code goes here to put " | ||
+ | @ users = filter($input* $onchannel()) | ||
+ | @ result = prefix($users) | ||
+ | if (numwords($users) > 1) { beep } | ||
+ | # Some code goes here to remove the ' | ||
+ | # line and paste $result in its place. | ||
+ | </ | ||
+ | |||
+ | $result will contain " | ||
+ | list (foobar foobaz). | ||
+ | string " | ||
+ | not an exact match. | ||
+ | are, if you wanted to. | ||
+ | |||
+ | If the user typed something like " | ||
+ | channel whose nickname started with " | ||
+ | empty string. | ||
+ | message. | ||
+ | |||
+ | ======Returns: | ||
+ | The Common Initial Substring (CIS) of all of the words in <word list> | ||
+ | |||
+ | ======Examples: | ||
+ | < | ||
+ | $prefix(foobar foobaz foobooya) | ||
+ | $prefix(one two three) | ||
+ | </ | ||
prefix.txt · Last modified: 2006/08/29 16:08 by 127.0.0.1