diff options
-rw-r--r-- | generic/tclUtf.c | 37 | ||||
-rw-r--r-- | tests/cmdIL.test | 3 |
2 files changed, 28 insertions, 12 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index a7a2091..f3d1758 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1101,31 +1101,44 @@ Tcl_UtfNcasecmp( } return 0; } + +/* + *---------------------------------------------------------------------- + * + * Tcl_UtfNcasecmp -- + * + * Compare UTF chars of string cs to string ct case insensitively. + * Replacement for strcasecmp in Tcl core, in places where UTF-8 should + * be handled. + * + * Results: + * Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ - -/* Replacement for strcasecmp in Tcl core, in places where UTF-8 should be handled. */ int TclUtfCasecmp( CONST char *cs, /* UTF string to compare to ct. */ CONST char *ct) /* UTF string cs is compared to. */ { - Tcl_UniChar ch1, ch2; - int goOn; - - do { - - /* If *cs == '\0' or *ct == '\0', loop should end. */ - goOn = *cs && *ct; + while (*cs && *ct) { + Tcl_UniChar ch1, ch2; cs += TclUtfToUniChar(cs, &ch1); ct += TclUtfToUniChar(ct, &ch2); if (ch1 != ch2) { ch1 = Tcl_UniCharToLower(ch1); ch2 = Tcl_UniCharToLower(ch2); - if (ch1 != ch2) break; + if (ch1 != ch2) { + return ch1 - ch2; + } } - } while (goOn); - return (ch1 - ch2); + } + return UCHAR(*cs) - UCHAR(*ct); } diff --git a/tests/cmdIL.test b/tests/cmdIL.test index 192c10c..6fab269 100644 --- a/tests/cmdIL.test +++ b/tests/cmdIL.test @@ -400,6 +400,9 @@ test cmdIL-4.36 {SortCompare procedure, UTF-8 with -nocase option} { test cmdIL-4.37 {SortCompare procedure, UTF-8 with -nocase option} { scan [lsort -ascii -nocase [list a\u0000a a]] %c%c%c%c%c } {97 32 97 0 97} +test cmdIL-4.38 {SortCompare procedure, UTF-8 with -nocase option} { + scan [lsort -ascii -nocase [list a a\u0000a]] %c%c%c%c%c +} {97 32 97 0 97} test cmdIL-5.1 {lsort with list style index} { lsort -ascii -decreasing -index {0 1} { |