diff options
author | Ran Benita <ran234@gmail.com> | 2013-10-14 18:59:53 +0300 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2013-10-14 18:59:53 +0300 |
commit | dcdd4e103035e17350b8b6ecf7df2d02b4d29822 (patch) | |
tree | 43909667fdae1b75b73d2ccba56a5688374ad574 /src/utils.h | |
parent | 14382a62ab1430223490516cb84b181456999dc7 (diff) | |
download | libxkbcommon-dcdd4e103035e17350b8b6ecf7df2d02b4d29822.tar.gz libxkbcommon-dcdd4e103035e17350b8b6ecf7df2d02b4d29822.tar.bz2 libxkbcommon-dcdd4e103035e17350b8b6ecf7df2d02b4d29822.zip |
Replace ctype.h functions with ascii ones
ctype.h is locale-dependent, so using it in our scanners is not optimal.
Let's be deterministic with our own simple functions.
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/utils.h')
-rw-r--r-- | src/utils.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h index 5cd6e57..0f4a388 100644 --- a/src/utils.h +++ b/src/utils.h @@ -117,6 +117,47 @@ max(int misc, int other) return (misc > other) ? misc : other; } +/* ctype.h is locale-dependent and has other oddities. */ +static inline bool +is_space(char ch) +{ + return ch == ' ' || (ch >= '\t' && ch <= '\r'); +} + +static inline bool +is_alpha(char ch) +{ + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); +} + +static inline bool +is_digit(char ch) +{ + return ch >= '0' && ch <= '9'; +} + +static inline bool +is_alnum(char ch) +{ + return is_alpha(ch) || is_digit(ch); +} + +static inline bool +is_xdigit(char ch) +{ + return + (ch >= '0' && ch <= '9') || + (ch >= 'a' && ch <= 'f') || + (ch >= 'A' && ch <= 'F'); +} + +static inline bool +is_graph(char ch) +{ + /* See table in ascii(7). */ + return ch >= '!' && ch <= '~'; +} + bool map_file(FILE *file, const char **string_out, size_t *size_out); |