Added range test in new fl_ascii_strcasecmp to avoid potential false positives.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9390 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
e2d3d400cd
commit
9011c77c0e
@ -94,14 +94,18 @@ fl_strlcpy(char *dst, /* O - Destination string */
|
||||
* locale independent ascii oriented case cmp
|
||||
* returns 0 if string successfully compare, non zero otherwise
|
||||
*/
|
||||
#define C_RANGE(c,l,r) ( (c) >= (l) && (c) <= (r) )
|
||||
|
||||
int fl_ascii_strcasecmp(const char *s, const char *t) {
|
||||
if (!s || !t) return (s!=t);
|
||||
if (strlen(s) != strlen(t)) return -1;
|
||||
for(;*s; s++,t++) {
|
||||
if ( *s != *t) {
|
||||
if (*s<*t && (*s+0x20)!=*t ) return -1;
|
||||
if (*s>*t && *s!=(*t+0x20) ) return +1;
|
||||
}
|
||||
if (*s == *t) continue;
|
||||
if (*s < *t) {
|
||||
if ( (*s+0x20)!=*t || !C_RANGE(*s,'A','Z') ) return -1;
|
||||
} else { // *s > *t
|
||||
if ( (*s-0x20)!=*t || !C_RANGE(*s,'a','z') ) return +1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user