summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Costantini <fabien@onepost.net>2012-04-24 01:12:54 +0000
committerFabien Costantini <fabien@onepost.net>2012-04-24 01:12:54 +0000
commit9011c77c0eaac7200bc784be7dcffc9c56c8fc70 (patch)
treee729d3a73058c8e86f10743c9250df898235f410
parente2d3d400cdc2c8fdf51cb171109e06ecf41410b5 (diff)
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
-rw-r--r--src/flstring.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/flstring.c b/src/flstring.c
index fcab1a765..25346b360 100644
--- a/src/flstring.c
+++ b/src/flstring.c
@@ -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;
}