From 8154316dc5af9aff37e12629a357f245bb53611e Mon Sep 17 00:00:00 2001 From: Fabien Costantini Date: Tue, 24 Apr 2012 03:52:00 +0000 Subject: [PATCH] improved ascii strcasecmp, and use it in font sort instead of strcasecmp git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9396 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/fl_set_fonts_xft.cxx | 2 +- src/flstring.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fl_set_fonts_xft.cxx b/src/fl_set_fonts_xft.cxx index fcb217673..b4cd42d6c 100644 --- a/src/fl_set_fonts_xft.cxx +++ b/src/fl_set_fonts_xft.cxx @@ -65,7 +65,7 @@ static int name_sort(const void *aa, const void *bb) { // Also - the fontconfig listing returns some faces that are effectively duplicates // as far as fltk is concerned, e.g. where there are ko or ja variants that we // can't distinguish (since we are not yet fully UTF-*) - should we strip them here? - return strcasecmp(*(char**)aa, *(char**)bb); + return fl_ascii_strcasecmp(*(char**)aa, *(char**)bb); } // end of name_sort } // end of extern C section diff --git a/src/flstring.c b/src/flstring.c index 25346b360..c407ea833 100644 --- a/src/flstring.c +++ b/src/flstring.c @@ -98,8 +98,10 @@ fl_strlcpy(char *dst, /* O - Destination string */ 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++) { + size_t sl=strlen(s), tl=strlen(t); + if (sl!=tl) return sl< tl ? -1 : +1; + + for(;*s; s++,t++) { if (*s == *t) continue; if (*s < *t) { if ( (*s+0x20)!=*t || !C_RANGE(*s,'A','Z') ) return -1; @@ -107,6 +109,7 @@ int fl_ascii_strcasecmp(const char *s, const char *t) { if ( (*s-0x20)!=*t || !C_RANGE(*s,'a','z') ) return +1; } } + return 0; }