From 0108088f52ee58fc8a2e83f86c9f2506165a16cd Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 6 Feb 2007 21:47:54 +0000 Subject: 23152: make ztrcmp() respect MULTIBYTE make sorting of printed hash tables more consistent --- Src/utils.c | 61 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/utils.c b/Src/utils.c index ce7b4caac..eb466278d 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -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 (!(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 (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 == 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. */ -- cgit 1.4.1