From 2ccd77c0c9bde78f3811bbc9b256197515532c88 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Nov 2015 07:07:55 +0100 Subject: add optimised variants of *casecmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/wchar/new.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/wchar') diff --git a/src/wchar/new.c b/src/wchar/new.c index e1d9c52..819b133 100644 --- a/src/wchar/new.c +++ b/src/wchar/new.c @@ -569,3 +569,75 @@ wchar_t* (wcscnends)(const wchar_t* string, const wchar_t* desired, wchar_t stop return (wmemcmp)(string + (n - m), desired, m) ? NULL : (string + n); } +int wcslowercmp(const wchar_t* a, const wchar_t* b) /* slibc: completeness */ +{ + return wcsnlowercmp(a, b, SIZE_MAX); +} + +int wcsuppercmp(const wchar_t* a, const wchar_t* b) /* slibc: completeness */ +{ + return wcsnuppercmp(a, b, SIZE_MAX); +} + +int wcsnlowercmp(const wchar_t* a, const wchar_t* b, size_t length) /* slibc: completeness */ +{ + wchar_t c1, c2; + for (; length--; a++, b++) + if (*a != *b) + { + c1 = iswalpha(*a) ? towlower(*a) : *a; + c2 = *b; + if (c1 < c2) return -1; + if (c1 > c2) return +1; + } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; + return 0; +} + +int wcsnuppercmp(const wchar_t* a, const wchar_t* b, size_t length) /* slibc: completeness */ +{ + wchar_t c1, c2; + for (; length--; a++, b++) + if (*a != *b) + { + c1 = iswalpha(*a) ? towupper(*a) : *a; + c2 = *b; + if (c1 < c2) return -1; + if (c1 > c2) return +1; + } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; + return 0; +} + +int wmemlowercmp(const wchar_t* a, const wchar_t* b, size_t size) /* slibc: completeness */ +{ + wchar_t c1, c2; + for (; size--; a++, b++) + if (*a != *b) + { + c1 = iswalpha(*a) ? towlower(*a) : *a; + c2 = *b; + if (c1 != c2) + return c1 < c2 ? -1 : +1; + } + return 0; +} + +int wmemuppercmp(const wchar_t* a, const wchar_t* b, size_t size) /* slibc: completeness */ +{ + wchar_t c1, c2; + for (; size--; a++, b++) + if (*a != *b) + { + c1 = iswalpha(*a) ? towupper(*a) : *a; + c2 = *b; + if (c1 != c2) + return c1 < c2 ? -1 : +1; + } + return 0; +} + -- cgit v1.2.3-70-g09d2