aboutsummaryrefslogtreecommitdiffstats
path: root/src/string_utils.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-10-19 12:44:21 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:59 +0100
commit3c5ccf16e7dc0eef903c3c49958559cb4a3a370b (patch)
treeb400a96bb7bab785f9cb196facd33c0831e96b94 /src/string_utils.h
parentab1b7a2b2e7de0cf0b0ff66d3814ccecd3b9a859 (diff)
downloadserd-3c5ccf16e7dc0eef903c3c49958559cb4a3a370b.tar.gz
serd-3c5ccf16e7dc0eef903c3c49958559cb4a3a370b.tar.bz2
serd-3c5ccf16e7dc0eef903c3c49958559cb4a3a370b.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.
Diffstat (limited to 'src/string_utils.h')
-rw-r--r--src/string_utils.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/string_utils.h b/src/string_utils.h
index 3f3d8c12..362dfcc1 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,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 == '=';
@@ -90,11 +96,17 @@ is_windows_path(const char* path)
size_t
serd_substrlen(const char* str, size_t len, 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);
}
}