diff options
author | David Robillard <d@drobilla.net> | 2019-10-19 12:44:21 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-20 10:26:55 -0500 |
commit | 52a14ae9053046a5148451364f8a77989e93b8bb (patch) | |
tree | 7fe225b76273fc9c8051d93463c50dc8884026d7 | |
parent | 69bb2b4312a2c353fb6ee5e11faf8efd947db883 (diff) | |
download | serd-52a14ae9053046a5148451364f8a77989e93b8bb.tar.gz serd-52a14ae9053046a5148451364f8a77989e93b8bb.tar.bz2 serd-52a14ae9053046a5148451364f8a77989e93b8bb.zip |
Avoid use of ctype.h macros entirely
Some of these cause warnings, and should never have been used in the first
place since they depend on locale.
-rw-r--r-- | src/n3.c | 3 | ||||
-rw-r--r-- | src/string_utils.h | 16 |
2 files changed, 15 insertions, 4 deletions
@@ -25,7 +25,6 @@ #include "serd/serd.h" #include <assert.h> -#include <ctype.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -675,7 +674,7 @@ read_IRIREF(SerdReader* reader, SerdNode** dest) break; default: if (c <= 0x20) { - if (isprint(c)) { + if (is_print(c)) { r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid IRI character `%c' (escape %%%02X)\n", c, (unsigned)c); diff --git a/src/string_utils.h b/src/string_utils.h index 7663736d..6595ca2f 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -20,7 +20,6 @@ #include "serd/serd.h" #include <assert.h> -#include <ctype.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -76,6 +75,13 @@ is_space(const int c) } static inline bool +is_print(const int c) +{ + return c >= 0x20 && c <= 0x7E; +} + +/** Return true iff `c` is a valid encoded base64 character. */ +static inline bool is_base64(const int c) { return is_alpha(c) || is_digit(c) || c == '+' || c == '/' || c == '='; @@ -116,11 +122,17 @@ serd_substrlen(const char* const str, return i; } +static inline char +serd_to_upper(const char c) +{ + return (char)((c >= 'a' && c <= 'z') ? c - 32 : c); +} + static inline int serd_strncasecmp(const char* s1, const char* s2, size_t n) { for (; n > 0 && *s2; s1++, s2++, --n) { - if (toupper(*s1) != toupper(*s2)) { + if (serd_to_upper(*s1) != serd_to_upper(*s2)) { return ((*(const uint8_t*)s1 < *(const uint8_t*)s2) ? -1 : +1); } } |