rules: rewrite MatchOneOf Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index cd87327..f65a7a6 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -745,28 +745,23 @@ CheckGroup(struct rules *rules, const char *group_name, const char *name)
return false;
}
+/* Match @needle out of @sep-seperated @haystack. */
static bool
-MatchOneOf(char *wanted, char *vals_defined)
+match_one_of(const char *haystack, const char *needle, char sep)
{
- char *str, *next;
- int want_len = strlen(wanted);
-
- for (str = vals_defined, next = NULL; str != NULL; str = next) {
- int len;
- next = strchr(str, ',');
- if (next) {
- len = next-str;
- next++;
- }
- else {
- len = strlen(str);
- }
+ const char *s = strstr(haystack, needle);
- if (len == want_len && strncmp(wanted, str, len) == 0)
- return true;
- }
+ if (s == NULL)
+ return false;
- return false;
+ if (s != haystack && *s != sep)
+ return false;
+
+ s += strlen(needle);
+ if (*s != '\0' && *s != sep)
+ return false;
+
+ return true;
}
static int
@@ -793,7 +788,7 @@ XkbRF_CheckApplyRule(struct rule *rule, struct multi_defs *mdefs,
if (rule->option != NULL) {
if (mdefs->options == NULL)
return 0;
- if ((!MatchOneOf(rule->option,mdefs->options)))
+ if ((!match_one_of(mdefs->options, rule->option, ',')))
return 0;
}