keysym: fix locale dependence in xkb_keysym_from_name()
authorRan Benita <ran234@gmail.com>
Fri, 2 Dec 2016 20:15:19 +0000 (22:15 +0200)
committerRan Benita <ran234@gmail.com>
Fri, 2 Dec 2016 21:46:56 +0000 (23:46 +0200)
commitb5586a6c4294b46eb23d1fc527ff63dcd27e23ac
treea567b29fe33c258006e6ec9b4d51a9acda4d0514
parent327364d277609600aa19aabd6dc55f2fc7dfb8cf
keysym: fix locale dependence in xkb_keysym_from_name()

We currently use strcasecmp, which is locale-dependent. In particular,
one well-known surprise even if restricted just ASCII input is found in
the tr_TR (Turkish) locale, see e.g.
https://msdn.microsoft.com/en-us/library/ms973919.aspx#stringsinnet20_topic5

We have known to avoid locale-dependent functions before, but in this
case, we forgot.

Fix it by implementing our own simple ASCII-only strcasecmp/strncasecmp.
Might have been possible to use strcasecmp_l() with the C locale, but
went the easy route.

Side advantage is that even this non-optimized version is faster than
the optimized libc one (__strcasecmp_l_sse42) since it doesn't need to
do the locale stuff. xkb_keysym_from_name(), which uses strcasecmp
heavily, becomes faster, and so for example Compose file parsing, which
uses xkb_keysym_from_name() heavily, becomes ~20% faster.

Resolves https://github.com/xkbcommon/libxkbcommon/issues/42
Signed-off-by: Ran Benita <ran234@gmail.com>
configure.ac
src/keysym.c
src/utils.c
src/utils.h
test/keysym.c