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/string/new.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/string') diff --git a/src/string/new.c b/src/string/new.c index 50b47cf..28d2b22 100644 --- a/src/string/new.c +++ b/src/string/new.c @@ -729,3 +729,79 @@ char* (strcnends)(const char* string, const char* desired, int stop, size_t maxl return (memcmp)(string + (n - m), desired, m) ? NULL : (string + n); } +int strlowercmp(const char* a, const char* b) /* slibc */ +{ + return strnlowercmp(a, b, SIZE_MAX); +} + +int struppercmp(const char* a, const char* b) /* slibc: completeness */ +{ + return strnuppercmp(a, b, SIZE_MAX); +} + +int strnlowercmp(const char* a, const char* b, size_t length) /* slibc: completeness */ +{ + int c1, c2; + for (; length--; a++, b++) + if (*a != *b) + { + c1 = isalpha(*a) ? tolower(*a) : (int)*a; + c2 = *b; + if ((c1 -= c2)) + return c1; + } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; + return 0; +} + +int strnuppercmp(const char* a, const char* b, size_t length) /* slibc: completeness */ +{ + int c1, c2; + for (; length--; a++, b++) + if (*a != *b) + { + c1 = isalpha(*a) ? toupper(*a) : (int)*a; + c2 = *b; + if ((c1 -= c2)) + return c1; + } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; + return 0; +} + +int memlowercmp(const void* a, const void* b, size_t size) /* slibc: completeness */ +{ + const signed char* s1 = a; + const signed char* s2 = b; + int c1, c2; + for (; size--; s1++, s2++) + if (*s1 != *s2) + { + c1 = isalpha(*s1) ? tolower(*s1) : (int)*s1; + c2 = *s2; + if ((c1 -= c2)) + return c1; + } + return 0; +} + +int memuppercmp(const void* a, const void* b, size_t size) /* slibc: completeness */ +{ + const signed char* s1 = a; + const signed char* s2 = b; + int c1, c2; + for (; size--; s1++, s2++) + if (*s1 != *s2) + { + c1 = isalpha(*s1) ? toupper(*s1) : (int)*s1; + c2 = *s2; + if ((c1 -= c2)) + return c1; + } + return 0; +} + -- cgit v1.2.3-70-g09d2