mirror of
https://github.com/samba-team/samba.git
synced 2025-11-21 12:23:50 +03:00
r14612: added strncasecmp_m() and fixed strcasecmp_m() for invalid codepoints
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
549b1eec40
commit
12b533450b
@@ -101,7 +101,7 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
|
||||
if (c1 == INVALID_CODEPOINT ||
|
||||
c2 == INVALID_CODEPOINT) {
|
||||
/* what else can we do?? */
|
||||
return c1 - c2;
|
||||
return strcasecmp(s1, s2);
|
||||
}
|
||||
|
||||
if (toupper_w(c1) != toupper_w(c2)) {
|
||||
@@ -112,6 +112,45 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare 2 strings.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user