rules: fix parsing of multiple options
This was broken by commit 18d331b86b
(where only the first option out of a comma-separated string was
matched). Do it correctly this time and add a test.
Signed-off-by: Ran Benita <ran234@gmail.com>
master
parent
8ff984871b
commit
19f814f95e
|
@ -680,19 +680,16 @@ match_group_member(struct rules *rules, const char *group_name,
|
|||
static bool
|
||||
match_one_of(const char *haystack, const char *needle, char sep)
|
||||
{
|
||||
const char *s = strstr(haystack, needle);
|
||||
const char *s = haystack;
|
||||
const size_t len = strlen(needle);
|
||||
|
||||
if (s == NULL)
|
||||
return false;
|
||||
do {
|
||||
if (strncmp(s, needle, len) == 0 && (s[len] == '\0' || s[len] == sep))
|
||||
return true;
|
||||
s = strchr(s, sep);
|
||||
} while (s++);
|
||||
|
||||
if (s != haystack && *s != sep)
|
||||
return false;
|
||||
|
||||
s += strlen(needle);
|
||||
if (*s != '\0' && *s != sep)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
! model = keycodes
|
||||
my_model = my_keycodes
|
||||
* = default_keycodes
|
||||
|
||||
! layout variant = symbols
|
||||
my_layout my_variant = my_symbols+extra_variant
|
||||
|
||||
! layout = symbols
|
||||
my_layout = my_symbols
|
||||
* = default_symbols
|
||||
|
||||
! model = types
|
||||
my_model = my_types
|
||||
* = default_types
|
||||
|
||||
! model = compat
|
||||
my_model = my_compat
|
||||
* = default_compat
|
||||
|
||||
! option = compat
|
||||
option111 = +substring
|
||||
option1 = +some:compat
|
||||
option11 = +group(bla)
|
||||
|
||||
! option = symbols
|
||||
option3 = +compose(foo)+keypad(bar)
|
||||
colon:opt = +altwin(menu)
|
|
@ -176,6 +176,18 @@ main(void)
|
|||
};
|
||||
assert(test_rules(ctx, &test6));
|
||||
|
||||
struct test_data test7 = {
|
||||
.rules = "multiple-options",
|
||||
|
||||
.model = "my_model", .layout = "my_layout", .variant = "my_variant",
|
||||
.options = "option3,option1,colon:opt,option11",
|
||||
|
||||
.keycodes = "my_keycodes", .types = "my_types",
|
||||
.compat = "my_compat+some:compat+group(bla)",
|
||||
.symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
|
||||
};
|
||||
assert(test_rules(ctx, &test7));
|
||||
|
||||
xkb_context_unref(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue