diff options
author | ache <ache@FreeBSD.org> | 1996-08-13 13:38:35 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1996-08-13 13:38:35 +0000 |
commit | 01dde070a3c2138f1ea752040823d25cc0181f8b (patch) | |
tree | 02c42f971741a7fe72147d677c4c15c2b785c4d2 | |
parent | 36270d5e2550534254809640b4c0c000bc5f2900 (diff) | |
download | FreeBSD-src-01dde070a3c2138f1ea752040823d25cc0181f8b.zip FreeBSD-src-01dde070a3c2138f1ea752040823d25cc0181f8b.tar.gz |
simplify/speedup/extend
-rw-r--r-- | lib/libc/locale/collcmp.c | 40 |
1 files changed, 22 insertions, 18 deletions
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); |