localed: introduce helper function to simplify matching
This commit is contained in:
+10
-12
@@ -101,6 +101,12 @@ static void free_and_replace(char **s, char *v) {
|
|||||||
*s = v;
|
*s = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool startswith_comma(const char *s, const char *prefix) {
|
||||||
|
const char *t;
|
||||||
|
|
||||||
|
return s && (t = startswith(s, prefix)) && (*t == ',');
|
||||||
|
}
|
||||||
|
|
||||||
static void context_free_x11(Context *c) {
|
static void context_free_x11(Context *c) {
|
||||||
free_and_replace(&c->x11_layout, NULL);
|
free_and_replace(&c->x11_layout, NULL);
|
||||||
free_and_replace(&c->x11_model, NULL);
|
free_and_replace(&c->x11_model, NULL);
|
||||||
@@ -679,26 +685,18 @@ static int find_legacy_keymap(Context *c, char **new_keymap) {
|
|||||||
/* If we got an exact match, this is best */
|
/* If we got an exact match, this is best */
|
||||||
matching = 10;
|
matching = 10;
|
||||||
else {
|
else {
|
||||||
size_t x;
|
|
||||||
|
|
||||||
x = strcspn(c->x11_layout, ",");
|
|
||||||
|
|
||||||
/* We have multiple X layouts, look for an
|
/* We have multiple X layouts, look for an
|
||||||
* entry that matches our key with everything
|
* entry that matches our key with everything
|
||||||
* but the first layout stripped off. */
|
* but the first layout stripped off. */
|
||||||
if (x > 0 &&
|
if (startswith_comma(c->x11_layout, a[1]))
|
||||||
strlen(a[1]) == x &&
|
|
||||||
strneq(c->x11_layout, a[1], x))
|
|
||||||
matching = 5;
|
matching = 5;
|
||||||
else {
|
else {
|
||||||
size_t w;
|
char *x;
|
||||||
|
|
||||||
/* If that didn't work, strip off the
|
/* If that didn't work, strip off the
|
||||||
* other layouts from the entry, too */
|
* other layouts from the entry, too */
|
||||||
w = strcspn(a[1], ",");
|
x = strndupa(a[1], strcspn(a[1], ","));
|
||||||
|
if (startswith_comma(c->x11_layout, x))
|
||||||
if (x > 0 && x == w &&
|
|
||||||
memcmp(c->x11_layout, a[1], x) == 0)
|
|
||||||
matching = 1;
|
matching = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user