mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-16 15:11:52 +00:00
There is so many places where range comparation (using collate)
needed (much more than I think initially), so I forced to add new user-visible non-standard function to libc.
This commit is contained in:
parent
806af72bd9
commit
883a3266d1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17551
@ -26,36 +26,47 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
/* will be removed ***************************/
|
||||
#include "collate.h"
|
||||
|
||||
int __collcmp (c1, c2)
|
||||
u_char c1, c2;
|
||||
unsigned char c1, c2;
|
||||
{
|
||||
return collate_range_cmp (c1, c2);
|
||||
}
|
||||
/* will be removed ***************************/
|
||||
|
||||
int collate_range_cmp (c1, c2)
|
||||
int c1, c2;
|
||||
{
|
||||
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 (((int)c1) - ((int)c2));
|
||||
return (c1 - c2);
|
||||
if (isalpha(c1) && !isalpha(c2)) {
|
||||
if (isupper(c1))
|
||||
return ('A' - ((int)c2));
|
||||
return ('A' - c2);
|
||||
else
|
||||
return ('a' - ((int)c2));
|
||||
return ('a' - c2);
|
||||
} else if (isalpha(c2) && !isalpha(c1)) {
|
||||
if (isupper(c2))
|
||||
return (((int)c1) - 'A');
|
||||
return (c1 - 'A');
|
||||
else
|
||||
return (((int)c1) - 'a');
|
||||
return (c1 - 'a');
|
||||
}
|
||||
if (isupper(c1) && islower(c2))
|
||||
return (-1);
|
||||
else if (islower(c1) && isupper(c2))
|
||||
return (1);
|
||||
s1[0] = (char) c1;
|
||||
s2[0] = (char) c2;
|
||||
s1[0] = c1;
|
||||
s2[0] = c2;
|
||||
return strcoll(s1, s2);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user