diff options
author | David Robillard <d@drobilla.net> | 2020-11-13 11:47:36 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-13 12:53:18 +0100 |
commit | 353b92d13d3ab6276998239c827287151e16bc8d (patch) | |
tree | a655eb89d8ccc1d90fe393c09c26b67a2dcc54f5 | |
parent | 3558d21c9239c3eb43a2229e1fbfd45dbd2a56ef (diff) | |
download | serd-353b92d13d3ab6276998239c827287151e16bc8d.tar.gz serd-353b92d13d3ab6276998239c827287151e16bc8d.tar.bz2 serd-353b92d13d3ab6276998239c827287151e16bc8d.zip |
Remove use of C character class functions that may use locale
Some of these cause warnings, and should never have been used in the first
place since they depend on locale.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/n3.c | 3 | ||||
-rw-r--r-- | src/serd_internal.h | 1 | ||||
-rw-r--r-- | src/string_utils.h | 15 |
4 files changed, 16 insertions, 6 deletions
@@ -2,10 +2,11 @@ serd (0.30.7) unstable; * Fix potential memory error when serialising URIs * Move headers to an include directory + * Remove use of C character class functions that may use locale * Split up and reorganize unit tests * Use aligned allocation via C11 or Windows API where possible - -- David Robillard <d@drobilla.net> Thu, 12 Nov 2020 19:18:33 +0000 + -- David Robillard <d@drobilla.net> Fri, 13 Nov 2020 11:53:07 +0000 serd (0.30.6) stable; @@ -24,7 +24,6 @@ #include "serd/serd.h" #include <assert.h> -#include <ctype.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -714,7 +713,7 @@ read_IRIREF(SerdReader* reader, Ref* 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/serd_internal.h b/src/serd_internal.h index 03d4edbd..2090476e 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -20,7 +20,6 @@ #include "serd/serd.h" #include <assert.h> -#include <ctype.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> diff --git a/src/string_utils.h b/src/string_utils.h index b80bf5aa..b4c2702e 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> @@ -75,6 +74,12 @@ is_space(const char c) } static inline bool +is_print(const int c) +{ + return c >= 0x20 && c <= 0x7E; +} + +static inline bool is_base64(const uint8_t c) { return is_alpha(c) || is_digit(c) || c == '+' || c == '/' || c == '='; @@ -93,11 +98,17 @@ serd_substrlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags); +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); } } |