From 2216af23c70ec8dee7162aaf35be5aed60a1a8ca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Mar 2006 11:37:11 +0000 Subject: r14612: added strncasecmp_m() and fixed strcasecmp_m() for invalid codepoints (This used to be commit 12b533450bdb31b57154940898f2f02c49e96ed1) --- source4/lib/util/util_str.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 4bb3ea1b54..8f408c00dc 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -101,14 +101,53 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (c1 == INVALID_CODEPOINT || c2 == INVALID_CODEPOINT) { /* what else can we do?? */ + return strcasecmp(s1, s2); + } + + if (toupper_w(c1) != toupper_w(c2)) { return c1 - c2; } + } + + return *s1 - *s2; +} + +/** + Case insensitive string compararison, length limited +**/ +_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + + while (*s1 && *s2 && n) { + n--; + + c1 = next_codepoint(s1, &size1); + c2 = next_codepoint(s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return strcasecmp(s1, s2); + } if (toupper_w(c1) != toupper_w(c2)) { return c1 - c2; } } + if (n == 0) { + return 0; + } + return *s1 - *s2; } -- cgit