Commit 18d331b86b4942ba54fe087ca07e47c9383d768b

Ran Benita 2012-05-18T11:01:20

rules: rewrite MatchOneOf Signed-off-by: Ran Benita <ran234@gmail.com>

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;
     }