text.segmented-match
- Segmented string matching ¶Sometimes you want to search for a group of words concatenated with
a delimiter, using only the prefixes of each words. For example:
you want to search call-with-current-continuation
using
c-w-c-c
. One of its popular applications is symbol completion,
which Gauche provides on REPL (see Input editing).
This module provides basic parts to perform such searching.
{text.segmented-match
}
The pattern and word arguments must be a string, and
separator must be either a character, a character set,
a regexp, a predicate taking a character, or a string.
When separator is omitted, #\-
is assumed.
First, pattern and word are splitted into segments
by separator,
using string-split
(see String utilities). If every
segments from pattern consist a prefix of the corresponding
segments from word, it returns #t
. It is allowed
for word to have more segments than pattern.
(segmented-match? "a-b-c" "alpha-bravo-charlie") ⇒ #t (segmented-match? "a-b" "alpha-bravo-charlie") ⇒ #t (segmented-match? "al-br-char" "alpha-bravo-charlie") ⇒ #t (segmented-match? "a-b" "alpha-delta-charlie") ⇒ #t
{text.segmented-match
}
This is a subfunction of segmented-match?
.
Returns a procedure that takes a string word, and sees if
each segment of pattern is a prefix of corresponding segment
of word. If any of the pattern’s segment is not a
prefix of the corresponding word’s segment, #f
is
returned. Otherwise, it returns a true value: If the number of
word’s segments is the same as the pattern’s, #t
is retured; if word has more segments, the remaining part
of the word (exclusing leading separator) is returned.
((make-segmented-prefix-matcher "a-b-c" #\-) "alpha-bravo-charlie") ⇒ #t ((make-segmented-prefix-matcher "a-b" #\-) "alpha-bravo-charlie-delta") ⇒ "charlie-delta" ((make-segmented-prefix-matcher "a-b" #\-) "alpha-charlie-delta") ⇒ #f
This preprocesses pattern, so if you want to match
many words against a single pattern, it is faster to get
predicates with this procedure than applying segmented-prefix?
repeatedly.