Bugfix termkey_strpkey parsing unicode with trailing content
This commit is contained in:
parent
c626393aeb
commit
0a101ff71e
|
@ -9,7 +9,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
#define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0)
|
#define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0)
|
||||||
|
|
||||||
plan_tests(48);
|
plan_tests(53);
|
||||||
|
|
||||||
tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS);
|
tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS);
|
||||||
|
|
||||||
|
@ -21,6 +21,14 @@ int main(int argc, char *argv[])
|
||||||
is_str(key.utf8, "A", "key.utf8 for unicode/A/0");
|
is_str(key.utf8, "A", "key.utf8 for unicode/A/0");
|
||||||
is_str(endp, "", "consumed entire input for unicode/A/0");
|
is_str(endp, "", "consumed entire input for unicode/A/0");
|
||||||
|
|
||||||
|
CLEAR_KEY;
|
||||||
|
endp = termkey_strpkey(tk, "A and more", &key, 0);
|
||||||
|
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/A/0 trailing");
|
||||||
|
is_int(key.code.codepoint, 'A', "key.code.codepoint for unicode/A/0 trailing");
|
||||||
|
is_int(key.modifiers, 0, "key.modifiers for unicode/A/0 trailing");
|
||||||
|
is_str(key.utf8, "A", "key.utf8 for unicode/A/0 trailing");
|
||||||
|
is_str(endp, " and more", "points at string tail for unicode/A/0 trailing");
|
||||||
|
|
||||||
CLEAR_KEY;
|
CLEAR_KEY;
|
||||||
endp = termkey_strpkey(tk, "C-b", &key, 0);
|
endp = termkey_strpkey(tk, "C-b", &key, 0);
|
||||||
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL");
|
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL");
|
||||||
|
|
14
termkey.c
14
termkey.c
|
@ -1124,13 +1124,7 @@ char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyForm
|
||||||
size_t nbytes;
|
size_t nbytes;
|
||||||
char *endstr;
|
char *endstr;
|
||||||
|
|
||||||
if(parse_utf8((unsigned char *)str, strlen(str), &key->code.codepoint, &nbytes) == TERMKEY_RES_KEY &&
|
if((endstr = termkey_lookup_keyname(tk, str, &key->code.sym))) {
|
||||||
nbytes == strlen(str)) {
|
|
||||||
key->type = TERMKEY_TYPE_UNICODE;
|
|
||||||
fill_utf8(key);
|
|
||||||
str += nbytes;
|
|
||||||
}
|
|
||||||
else if((endstr = termkey_lookup_keyname(tk, str, &key->code.sym))) {
|
|
||||||
key->type = TERMKEY_TYPE_KEYSYM;
|
key->type = TERMKEY_TYPE_KEYSYM;
|
||||||
str = endstr;
|
str = endstr;
|
||||||
}
|
}
|
||||||
|
@ -1138,6 +1132,12 @@ char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyForm
|
||||||
key->type = TERMKEY_TYPE_FUNCTION;
|
key->type = TERMKEY_TYPE_FUNCTION;
|
||||||
str += nbytes;
|
str += nbytes;
|
||||||
}
|
}
|
||||||
|
// Unicode must be last
|
||||||
|
else if(parse_utf8((unsigned char *)str, strlen(str), &key->code.codepoint, &nbytes) == TERMKEY_RES_KEY) {
|
||||||
|
key->type = TERMKEY_TYPE_UNICODE;
|
||||||
|
fill_utf8(key);
|
||||||
|
str += nbytes;
|
||||||
|
}
|
||||||
// TODO: Consider mouse events?
|
// TODO: Consider mouse events?
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue