From a8ffb15c4a0566fabb50c94524e881ba2036dd1a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 11 Aug 2021 23:28:18 -0400 Subject: Expose serd_strncasecmp in public API --- include/serd/serd.h | 12 ++++++++++++ src/string.c | 17 ++++++++++++++++- src/string_utils.h | 12 ------------ src/syntax.c | 2 -- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/include/serd/serd.h b/include/serd/serd.h index f30026ca..96890dbd 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -292,6 +292,18 @@ SERD_API char* SERD_NULLABLE serd_canonical_path(const char* SERD_NONNULL path); +/** + Compare two strings ignoring case. + + @return Less than, equal to, or greater than zero if `s1` is less than, + equal to, or greater than `s2`, respectively. +*/ +SERD_PURE_API +int +serd_strncasecmp(const char* SERD_NONNULL s1, + const char* SERD_NONNULL s2, + size_t n); + /** @} @defgroup serd_io_functions I/O Function Types diff --git a/src/string.c b/src/string.c index 6942b7b6..b9885d4f 100644 --- a/src/string.c +++ b/src/string.c @@ -1,5 +1,5 @@ /* - Copyright 2011-2020 David Robillard + Copyright 2011-2021 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -14,8 +14,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "string_utils.h" + #include "serd/serd.h" +#include #include void @@ -68,3 +71,15 @@ serd_strerror(const SerdStatus status) return "Unknown error"; } + +int +serd_strncasecmp(const char* s1, const char* s2, size_t n) +{ + for (; n > 0 && *s2; s1++, s2++, --n) { + if (serd_to_lower(*s1) != serd_to_lower(*s2)) { + return ((*(const uint8_t*)s1 < *(const uint8_t*)s2) ? -1 : +1); + } + } + + return 0; +} diff --git a/src/string_utils.h b/src/string_utils.h index 5cf7ba8c..2fb4f860 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -94,18 +94,6 @@ serd_to_lower(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 (serd_to_lower(*s1) != serd_to_lower(*s2)) { - return ((*(const uint8_t*)s1 < *(const uint8_t*)s2) ? -1 : +1); - } - } - - return 0; -} - static inline uint32_t utf8_num_bytes(const uint8_t leading) { diff --git a/src/syntax.c b/src/syntax.c index ace55ce2..fc1333a4 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -14,8 +14,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "string_utils.h" - #include "serd/serd.h" #include -- cgit v1.2.1