1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 04:40:59 +01:00

23152: make ztrcmp() respect MULTIBYTE

make sorting of printed hash tables more consistent
This commit is contained in:
Peter Stephenson 2007-02-06 21:47:54 +00:00
parent bae2ec88e5
commit 0108088f52
7 changed files with 110 additions and 72 deletions

View file

@ -3700,27 +3700,56 @@ unmeta(const char *file_name)
int
ztrcmp(char const *s1, char const *s2)
{
int c1, c2;
convchar_t c1 = 0, c2;
while (*s1 && *s1 == *s2) {
s1++;
s2++;
#ifdef MULTIBYTE_SUPPORT
if (isset(MULTIBYTE)) {
mb_metacharinit();
while (*s1) {
int clen = mb_metacharlenconv(s1, &c1);
if (strncmp(s1, s2, clen))
break;
s1 += clen;
s2 += clen;
}
} else
#endif
while (*s1 && *s1 == *s2) {
s1++;
s2++;
}
if (!*s1) {
if (!*s2)
return 0;
return -1;
}
if (!*s2)
return 1;
#ifdef MULTIBYTE_SUPPORT
if (isset(MULTIBYTE)) {
/* TODO: shift state for s2 might be wrong? */
mb_metacharinit();
(void)mb_metacharlenconv(s2, &c2);
if (c1 == WEOF)
c1 = STOUC(*s1 == Meta ? s1[1] ^ 32 : *s1);
if (c2 == WEOF)
c2 = STOUC(*s2 == Meta ? s2[1] ^ 32 : *s2);
}
else
#endif
{
c1 = STOUC(*s1 == Meta ? s1[1] ^ 32 : *s1);
c2 = STOUC(*s2 == Meta ? s2[1] ^ 32 : *s2);
}
if (!(c1 = STOUC(*s1)))
c1 = -1;
else if (c1 == STOUC(Meta))
c1 = STOUC(*++s1) ^ 32;
if (!(c2 = STOUC(*s2)))
c2 = -1;
else if (c2 == STOUC(Meta))
c2 = STOUC(*++s2) ^ 32;
if (c1 == c2)
return 0;
if (c1 < c2)
return -1;
return 1;
else if (c1 == c2)
return 0;
else
return 1;
}
/* Return the unmetafied length of a metafied string. */