diff options
Diffstat (limited to 'src/string.c')
-rw-r--r-- | src/string.c | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/string.c b/src/string.c index b83ad58f..defbaac4 100644 --- a/src/string.c +++ b/src/string.c @@ -18,9 +18,11 @@ #include "serd/serd.h" +#include <assert.h> #include <math.h> #include <stdint.h> #include <stdlib.h> +#include <string.h> void serd_free(void* ptr) @@ -74,46 +76,32 @@ serd_update_flags(const uint8_t c, SerdNodeFlags* const flags) size_t serd_substrlen(const uint8_t* const str, const size_t len, - size_t* const n_bytes, SerdNodeFlags* const flags) { - size_t n_chars = 0; - size_t i = 0; - SerdNodeFlags f = 0; + assert(flags); + + size_t i = 0; + *flags = 0; for (; i < len && str[i]; ++i) { - if ((str[i] & 0xC0) != 0x80) { // Start of new character - ++n_chars; - serd_update_flags(str[i], &f); - } - } - if (n_bytes) { - *n_bytes = i; + serd_update_flags(str[i], flags); } - if (flags) { - *flags = f; - } - return n_chars; + + return i; } size_t -serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags) +serd_strlen(const uint8_t* str, SerdNodeFlags* flags) { - size_t n_chars = 0; - size_t i = 0; - SerdNodeFlags f = 0; - for (; str[i]; ++i) { - if ((str[i] & 0xC0) != 0x80) { // Start of new character - ++n_chars; - serd_update_flags(str[i], &f); - } - } - if (n_bytes) { - *n_bytes = i; - } if (flags) { - *flags = f; + size_t i = 0; + *flags = 0; + for (; str[i]; ++i) { + serd_update_flags(str[i], flags); + } + return i; } - return n_chars; + + return strlen((const char*)str); } static inline double |