mirror of
https://github.com/tmux/tmux.git
synced 2026-10-10 12:14:43 +00:00
Extend match to do multiple terms.
This commit is contained in:
34
format.c
34
format.c
@@ -4507,11 +4507,14 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
return (list);
|
return (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fuzzy match strings. */
|
/* Fuzzy match a single token (no spaces). */
|
||||||
static int
|
static int
|
||||||
format_fuzzy_match(const char *pattern, const char *text, int icase)
|
format_fuzzy_match_token(const char *pattern, size_t patternlen,
|
||||||
|
const char *text, int icase)
|
||||||
{
|
{
|
||||||
while (*pattern != '\0') {
|
const char *end = pattern + patternlen;
|
||||||
|
|
||||||
|
while (pattern != end) {
|
||||||
if (*text == '\0')
|
if (*text == '\0')
|
||||||
return (0);
|
return (0);
|
||||||
if (icase) {
|
if (icase) {
|
||||||
@@ -4526,6 +4529,31 @@ format_fuzzy_match(const char *pattern, const char *text, int icase)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fuzzy match strings. The pattern is split on spaces into tokens and every
|
||||||
|
* token must match as a sequence.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
format_fuzzy_match(const char *pattern, const char *text, int icase)
|
||||||
|
{
|
||||||
|
const char *start;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
while (*pattern != '\0') {
|
||||||
|
while (*pattern == ' ')
|
||||||
|
pattern++;
|
||||||
|
if (*pattern == '\0')
|
||||||
|
break;
|
||||||
|
start = pattern;
|
||||||
|
while (*pattern != '\0' && *pattern != ' ')
|
||||||
|
pattern++;
|
||||||
|
len = pattern - start;
|
||||||
|
if (!format_fuzzy_match_token(start, len, text, icase))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Match against an fnmatch(3) pattern or regular expression. */
|
/* Match against an fnmatch(3) pattern or regular expression. */
|
||||||
static char *
|
static char *
|
||||||
format_match(struct format_modifier *fm, const char *pattern, const char *text)
|
format_match(struct format_modifier *fm, const char *pattern, const char *text)
|
||||||
|
|||||||
3
tmux.1
3
tmux.1
@@ -6385,7 +6385,8 @@ means the pattern is a regular expression instead of the default
|
|||||||
pattern,
|
pattern,
|
||||||
.Ql z
|
.Ql z
|
||||||
means the pattern is a fuzzy match, that is, it matches if its characters
|
means the pattern is a fuzzy match, that is, it matches if its characters
|
||||||
appear in the string in order but not necessarily consecutively,
|
appear in the string in order but not necessarily consecutively;
|
||||||
|
the pattern is split on spaces into separate terms which must all match,
|
||||||
and
|
and
|
||||||
.Ql i
|
.Ql i
|
||||||
means to ignore case.
|
means to ignore case.
|
||||||
|
|||||||
Reference in New Issue
Block a user