diff options
Diffstat (limited to 'src/ellinika/utf8.c')
-rw-r--r-- | src/ellinika/utf8.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/ellinika/utf8.c b/src/ellinika/utf8.c index 952af07..b946a3b 100644 --- a/src/ellinika/utf8.c +++ b/src/ellinika/utf8.c @@ -1933,6 +1933,15 @@ utf8_wc_strcasecmp(const unsigned *a, const unsigned *b) } const unsigned * +utf8_wc_strnchr(const unsigned *str, unsigned chr, size_t len) +{ + for (; len; str++, len--) + if (*str == chr) + return str; + return NULL; +} + +const unsigned * utf8_wc_strchr(const unsigned *str, unsigned chr) { for (; *str; str++) @@ -1980,6 +1989,37 @@ utf8_wc_strstr(const unsigned *haystack, const unsigned *needle) return NULL; } +const unsigned * +utf8_wc_strnstr(const unsigned *haystack, size_t hlen, + const unsigned *needle, size_t nlen) +{ + unsigned first; + + /* Is needle empty? */ + if (hlen == 0) + return haystack; + first = needle[0]; + /* Is needle nearly empty? */ + if (nlen == 1) + return utf8_wc_strnchr(haystack, first, hlen); + for (; hlen; haystack++, hlen--) + if (*haystack == first) { + /* Compare with needle's remaining units. */ + const unsigned *hptr = haystack + 1; + size_t len = 1; + for (;;) { + if (*hptr != needle[len]) + break; + hptr++; + len++; + if (len == nlen) + return haystack; + } + } + + return NULL; +} + unsigned * utf8_wc_quote(const unsigned *s) { |