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) | |||
1933 | } | 1933 | } |
1934 | 1934 | ||
1935 | const unsigned * | 1935 | const unsigned * |
1936 | utf8_wc_strnchr(const unsigned *str, unsigned chr, size_t len) | ||
1937 | { | ||
1938 | for (; len; str++, len--) | ||
1939 | if (*str == chr) | ||
1940 | return str; | ||
1941 | return NULL; | ||
1942 | } | ||
1943 | |||
1944 | const unsigned * | ||
1936 | utf8_wc_strchr(const unsigned *str, unsigned chr) | 1945 | utf8_wc_strchr(const unsigned *str, unsigned chr) |
1937 | { | 1946 | { |
1938 | for (; *str; str++) | 1947 | for (; *str; str++) |
@@ -1980,6 +1989,37 @@ utf8_wc_strstr(const unsigned *haystack, const unsigned *needle) | |||
1980 | return NULL; | 1989 | return NULL; |
1981 | } | 1990 | } |
1982 | 1991 | ||
1992 | const unsigned * | ||
1993 | utf8_wc_strnstr(const unsigned *haystack, size_t hlen, | ||
1994 | const unsigned *needle, size_t nlen) | ||
1995 | { | ||
1996 | unsigned first; | ||
1997 | |||
1998 | /* Is needle empty? */ | ||
1999 | if (hlen == 0) | ||
2000 | return haystack; | ||
2001 | first = needle[0]; | ||
2002 | /* Is needle nearly empty? */ | ||
2003 | if (nlen == 1) | ||
2004 | return utf8_wc_strnchr(haystack, first, hlen); | ||
2005 | for (; hlen; haystack++, hlen--) | ||
2006 | if (*haystack == first) { | ||
2007 | /* Compare with needle's remaining units. */ | ||
2008 | const unsigned *hptr = haystack + 1; | ||
2009 | size_t len = 1; | ||
2010 | for (;;) { | ||
2011 | if (*hptr != needle[len]) | ||
2012 | break; | ||
2013 | hptr++; | ||
2014 | len++; | ||
2015 | if (len == nlen) | ||
2016 | return haystack; | ||
2017 | } | ||
2018 | } | ||
2019 | |||
2020 | return NULL; | ||
2021 | } | ||
2022 | |||
1983 | unsigned * | 2023 | unsigned * |
1984 | utf8_wc_quote(const unsigned *s) | 2024 | utf8_wc_quote(const unsigned *s) |
1985 | { | 2025 | { |