diff options
author | David Robillard <d@drobilla.net> | 2016-03-15 23:37:09 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 16:27:02 -0500 |
commit | d107eb486f24c0e68eff4e1b622850fca5f75d77 (patch) | |
tree | d8c2678be2739467005f5807f331ad4bcfa9790a /src/string.c | |
parent | 1c59b863d8c2c2d7b5531866586baf232c0047a2 (diff) | |
download | serd-d107eb486f24c0e68eff4e1b622850fca5f75d77.tar.gz serd-d107eb486f24c0e68eff4e1b622850fca5f75d77.tar.bz2 serd-d107eb486f24c0e68eff4e1b622850fca5f75d77.zip |
Remove useless character counting
Diffstat (limited to 'src/string.c')
-rw-r--r-- | src/string.c | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/src/string.c b/src/string.c index ecba3463..37d71c8b 100644 --- a/src/string.c +++ b/src/string.c @@ -5,9 +5,11 @@ #include "serd/serd.h" +#include <assert.h> #include <math.h> #include <stdint.h> #include <stdlib.h> +#include <string.h> void serd_free(void* const ptr) @@ -64,48 +66,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* const str, - size_t* const n_bytes, - SerdNodeFlags* const flags) +serd_strlen(const uint8_t* const str, SerdNodeFlags* const 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 double |