Tcl Source Code

Check-in [93dd8bb33b]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed the weird edge case.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-3613609
Files: files | file ages | folders
SHA1: 93dd8bb33b1ac77a85c94deac4ef874105ed1334
User & Date: dkf 2013-05-22 12:55:50
Context
2013-05-22
12:59
[3613609]: Replace strcasecmp() with UTF-8-aware version. check-in: 8cc7cdfbd6 user: dkf tags: core-8-5-branch
12:55
Fixed the weird edge case. Closed-Leaf check-in: 93dd8bb33b user: dkf tags: bug-3613609
12:32
Improved tests. check-in: 1fbbe4aec3 user: dkf tags: bug-3613609
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tclUtf.c.

  1097   1097   	    if (ch1 != ch2) {
  1098   1098   		return (ch1 - ch2);
  1099   1099   	    }
  1100   1100   	}
  1101   1101       }
  1102   1102       return 0;
  1103   1103   }
         1104  +
         1105  +/*
         1106  + *----------------------------------------------------------------------
         1107  + *
         1108  + * Tcl_UtfNcasecmp --
         1109  + *
         1110  + *	Compare UTF chars of string cs to string ct case insensitively.
         1111  + *	Replacement for strcasecmp in Tcl core, in places where UTF-8 should
         1112  + *	be handled.
         1113  + *
         1114  + * Results:
         1115  + *	Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct.
         1116  + *
         1117  + * Side effects:
         1118  + *	None.
         1119  + *
         1120  + *----------------------------------------------------------------------
         1121  + */
  1104   1122   
  1105         -
  1106         -/* Replacement for strcasecmp in Tcl core, in places where UTF-8 should be handled. */
  1107   1123   int
  1108   1124   TclUtfCasecmp(
  1109   1125       CONST char *cs,		/* UTF string to compare to ct. */
  1110   1126       CONST char *ct)		/* UTF string cs is compared to. */
  1111   1127   {
  1112         -    Tcl_UniChar ch1, ch2;
  1113         -    int goOn;
  1114         -
  1115         -    do {
  1116         -
  1117         -	/* If *cs == '\0' or *ct == '\0', loop should end. */
  1118         -	goOn = *cs && *ct;
         1128  +    while (*cs && *ct) {
         1129  +	Tcl_UniChar ch1, ch2;
  1119   1130   
  1120   1131   	cs += TclUtfToUniChar(cs, &ch1);
  1121   1132   	ct += TclUtfToUniChar(ct, &ch2);
  1122   1133   	if (ch1 != ch2) {
  1123   1134   	    ch1 = Tcl_UniCharToLower(ch1);
  1124   1135   	    ch2 = Tcl_UniCharToLower(ch2);
  1125         -	    if (ch1 != ch2) break;
         1136  +	    if (ch1 != ch2) {
         1137  +		return ch1 - ch2;
         1138  +	    }
  1126   1139   	}
  1127         -    } while (goOn);
  1128         -    return (ch1 - ch2);
         1140  +    }
         1141  +    return UCHAR(*cs) - UCHAR(*ct);
  1129   1142   }
  1130   1143   
  1131   1144   
  1132   1145   /*
  1133   1146    *----------------------------------------------------------------------
  1134   1147    *
  1135   1148    * Tcl_UniCharToUpper --

Changes to tests/cmdIL.test.

   395    395       lsort -ascii -nocase {d E c B a D35 d300 100 20}
   396    396   } {100 20 a B c d d300 D35 E}
   397    397   test cmdIL-4.36 {SortCompare procedure, UTF-8 with -nocase option} {
   398    398       scan [lsort -ascii -nocase [list \u101 \u100]] %c%c%c
   399    399   } {257 32 256}
   400    400   test cmdIL-4.37 {SortCompare procedure, UTF-8 with -nocase option} {
   401    401       scan [lsort -ascii -nocase [list a\u0000a a]] %c%c%c%c%c
          402  +} {97 32 97 0 97}
          403  +test cmdIL-4.38 {SortCompare procedure, UTF-8 with -nocase option} {
          404  +    scan [lsort -ascii -nocase [list a a\u0000a]] %c%c%c%c%c
   402    405   } {97 32 97 0 97}
   403    406   
   404    407   test cmdIL-5.1 {lsort with list style index} {
   405    408       lsort -ascii -decreasing -index {0 1} {
   406    409   	{{Jim Alpha} 20000410}
   407    410   	{{Joe Bravo} 19990320}
   408    411   	{{Jacky Charlie} 19390911}