Attachment "TclUtfCasecmp-4.patch" to
ticket [1236896fff]
added by
rmax
2005-07-15 05:21:40.
--- generic/tclCmdIL.c 14 Jul 2005 12:17:35 -0000 1.77
+++ generic/tclCmdIL.c 14 Jul 2005 22:10:05 -0000
@@ -3304,7 +3304,7 @@
dataType = INTEGER;
break;
case LSEARCH_NOCASE: /* -nocase */
- strCmpFn = strcasecmp;
+ strCmpFn = TclUtfCasecmp;
noCase = 1;
break;
case LSEARCH_NOT: /* -not */
@@ -3654,7 +3654,7 @@
* compilation of memcmp
*/
if (noCase) {
- match = (strcasecmp(bytes, patternBytes) == 0);
+ match = (TclUtfCasecmp(bytes, patternBytes) == 0);
} else {
match = (memcmp(bytes, patternBytes,
(size_t) length) == 0);
@@ -4020,7 +4020,7 @@
sortInfo.sortMode = SORTMODE_INTEGER;
break;
case LSORT_NOCASE:
- sortInfo.strCmpFn = strcasecmp;
+ sortInfo.strCmpFn = TclUtfCasecmp;
break;
case LSORT_REAL:
sortInfo.sortMode = SORTMODE_REAL;
Index: generic/tclCmdMZ.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclCmdMZ.c,v
retrieving revision 1.126
diff -u -r1.126 tclCmdMZ.c
--- generic/tclCmdMZ.c 20 Jun 2005 07:49:11 -0000 1.126
+++ generic/tclCmdMZ.c 14 Jul 2005 22:10:09 -0000
@@ -2586,7 +2586,7 @@
matchVarObj = objv[i];
numMatchesSaved = -1;
} else if (index == OPT_NOCASE) {
- strCmpFn = strcasecmp;
+ strCmpFn = TclUtfCasecmp;
noCase = 1;
} else {
if ( foundmode ) {
--- generic/tclInt.decls 5 Jul 2005 18:15:55 -0000 1.90
+++ generic/tclInt.decls 14 Jul 2005 22:10:11 -0000
@@ -897,6 +897,10 @@
TclPlatformType *TclGetPlatform(void)
}
+declare 225 generic {
+ int TclUtfCasecmp( CONST char *cs, CONST char *ct )
+}
+
##############################################################################
# Define the platform specific internal Tcl interface. These functions are
--- generic/tclUtf.c 10 May 2005 18:34:51 -0000 1.34
+++ generic/tclUtf.c 14 Jul 2005 22:10:15 -0000
@@ -1103,6 +1103,72 @@
/*
*----------------------------------------------------------------------
*
+ * TclUtfCasecmp --
+ *
+ * Compare string cs to string ct case insensitively.
+ *
+ * Results:
+ * Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclUtfCasecmp(cs, ct)
+ CONST char *cs; /* UTF string to compare to ct. */
+ CONST char *ct; /* UTF string cs is compared to. */
+{
+ char s, t;
+ while ((s = *cs) != '\0' && (t = *ct) != '\0') {
+
+ if (((s | t) & 0x80) == 0) {
+ /* We have 7bit ASCII characters in both strings */
+ if (s == t) {
+ cs++; ct++;
+ } else {
+ if (s >= 'A' && s <= 'Z') {
+ s |= 0x20;
+ }
+ if (t >= 'A' && t <= 'Z') {
+ t |= 0x20;
+ }
+ if (s == t) {
+ cs++; ct++;
+ } else {
+ return (s-t);
+ }
+ }
+ } else {
+ 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) {
+ return (ch1 - ch2);
+ }
+ }
+ }
+ }
+ if ((*cs | *ct) == '\0') {
+ /* the strings are equivalent */
+ return 0;
+ } else if (*cs == '\0') {
+ /* cs is a prefix of ct */
+ return -1;
+ } else {
+ /* ct is a prefix of cs */
+ return 1;
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_UniCharToUpper --
*
* Compute the uppercase equivalent of the given Unicode character.
--- tests/cmdIL.test 1 Jun 2005 11:00:35 -0000 1.26
+++ tests/cmdIL.test 14 Jul 2005 22:10:15 -0000
@@ -431,6 +431,12 @@
} -result 0 -cleanup {
rename test_lsort ""
}
+test cmdIL-5.6 {lsort -nocase with non-ASCII characters} -body {
+ lsort -nocase {\u00c4a \u20aca \u00c4c \u00e4b Ac ab Aa}
+} -result "Aa ab Ac \u00c4a \u00e4b \u00c4c \u20aca"
+test cmdIL-5.6 {lsort -nocase with ASCII non-letter characters} {
+ list [lsort -nocase {@ `}] [lsort -nocase {` @}]
+} {{@ `} {@ `}}
# Compiled version
test cmdIL-6.1 {lassign command syntax} -body {