5228fe88d0
Characters should be casted as unsigned before use in functions from <ctype.h>. Otherwise the compiler treats 8-bit characters (eg UTF-8) as negative values (since it expects signed integers) and they no longer match the comparison tables. Worse, the character 0xff gets interpreted as -1 (like EOF). In turn, it helps to explicitly cast the result as a signed integer, since this is what is expected. Characters in the range 0x80-0xff do keep their original values. See the manual page for ctype(3) for more details (eg from NetBSD)