From 01dde070a3c2138f1ea752040823d25cc0181f8b Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 13 Aug 1996 13:38:35 +0000 Subject: simplify/speedup/extend --- lib/libc/locale/collcmp.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/libc/locale/collcmp.c b/lib/libc/locale/collcmp.c index d3a4040..b74ffaf 100644 --- a/lib/libc/locale/collcmp.c +++ b/lib/libc/locale/collcmp.c @@ -32,31 +32,35 @@ int collate_range_cmp (c1, c2) int c1, c2; { + int as1, as2, al1, al2; static char s1[2], s2[2]; c1 &= UCHAR_MAX; c2 &= UCHAR_MAX; if (c1 == c2) return (0); - if ( (isascii(c1) && isascii(c2)) - || (!isalpha(c1) && !isalpha(c2)) - ) - return (c1 - c2); - if (isalpha(c1) && !isalpha(c2)) { - if (isupper(c1)) - return ('A' - c2); - else - return ('a' - c2); - } else if (isalpha(c2) && !isalpha(c1)) { - if (isupper(c2)) - return (c1 - 'A'); - else - return (c1 - 'a'); + + as1 = isascii(c1); + as2 = isascii(c2); + al1 = isalpha(c1); + al2 = isalpha(c2); + + if (as1 || as2 || al1 || al2) { + if ((as1 && as2) || (!al1 && !al2)) + return (c1 - c2); + if (al1 && !al2) { + if (isupper(c1)) + return ('A' - c2); + else + return ('a' - c2); + } else if (al2 && !al1) { + if (isupper(c2)) + return (c1 - 'A'); + else + return (c1 - 'a'); + } } - if (isupper(c1) && islower(c2)) - return (-1); - else if (islower(c1) && isupper(c2)) - return (1); + s1[0] = c1; s2[0] = c2; return strcoll(s1, s2); -- cgit v1.1