diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2013-05-22 12:55:50 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2013-05-22 12:55:50 (GMT) |
commit | 75b8011dbad373e664a676ed8e3bcfec70313838 (patch) | |
tree | 8b7d5b14cb55b6a6a4f34ebc4a422488ca364f58 | |
parent | 5689a75644f9b109581a5dc3ae15294467c657ab (diff) | |
download | tcl-75b8011dbad373e664a676ed8e3bcfec70313838.zip tcl-75b8011dbad373e664a676ed8e3bcfec70313838.tar.gz tcl-75b8011dbad373e664a676ed8e3bcfec70313838.tar.bz2 |
Fixed the weird edge case.bug_3613609
-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} { |