From bd82d030011cd8b9655e5ded6b6df9343b42a6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 4 Feb 2015 14:09:54 +0100 Subject: Imported Upstream version 3.22 --- include/libHX/ctype_helper.h | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 include/libHX/ctype_helper.h (limited to 'include/libHX/ctype_helper.h') diff --git a/include/libHX/ctype_helper.h b/include/libHX/ctype_helper.h new file mode 100644 index 0000000..2ba0a7a --- /dev/null +++ b/include/libHX/ctype_helper.h @@ -0,0 +1,86 @@ +#ifndef _LIBHX_CTYPE_H +#define _LIBHX_CTYPE_H 1 + +#ifdef __cplusplus +# include +#else +# include +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * ctype.h workarounds. The is*() functions takes an int, but people + * commonly pass in a char. Because char can technically be signed, the + * value would be sign-extended during promotion to the int type which the + * ctype family functions take. + * + * The HX_ ctype related functions therefore explicitly take an unsigned char, + * and thus knowingly make it impossible to pass in stdio's "EOF" (-1). + * [When was the last time you did a isalpha(EOF) anyway?] + * + * Because, again, this all works due to implicit type conversion, these + * wrappers look rather plain. Oh, also note we are returning the much + * more modern "bool". + * + * And not all ctype functions are provided - no need so far, and I do not + * want to clutter it before needing it. + */ +static __inline__ bool HX_isalnum(unsigned char c) +{ + return isalnum(c); +} + +static __inline__ bool HX_isalpha(unsigned char c) +{ + return isalpha(c); +} + +static __inline__ bool HX_isdigit(unsigned char c) +{ + return isdigit(c); +} + +static __inline__ bool HX_islower(unsigned char c) +{ + return islower(c); +} + +static __inline__ bool HX_isprint(unsigned char c) +{ + return isprint(c); +} + +static __inline__ bool HX_isspace(unsigned char c) +{ + return isspace(c); +} + +static __inline__ bool HX_isupper(unsigned char c) +{ + return isupper(c); +} + +static __inline__ bool HX_isxdigit(unsigned char c) +{ + return isxdigit(c); +} + +static __inline__ unsigned char HX_tolower(unsigned char c) +{ + return tolower(c); +} + +static __inline__ unsigned char HX_toupper(unsigned char c) +{ + return toupper(c); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _LIBHX_CTYPE_H */ -- cgit v1.2.3