Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2013-11-12
14:41 • Closed ticket [1236896fff]: make -nocase behave correct with non-ASCII character... artifact: bbe86424b3 user: dkf
2013-07-03
11:12 • Pending ticket [1236896fff]. artifact: 1414850c0c user: jan.nijtmans
2008-02-29
04:48 • Ticket [1236896fff]: 4 changes artifact: 37f1406ebc user: jenglish
2005-07-19
00:45 • Ticket [1236896fff]: 4 changes artifact: ad51c286de user: rmax
00:45 • Add attachment TclUtfCasecmp-10.patch to ticket [1236896fffffffff|12368... artifact: c56b30b1ab user: rmax
00:45 • Ticket [1236896fff] make -nocase behave correct with non-ASCII characters st... artifact: e86f603f85 user: rmax
2005-07-18
21:46 • Ticket [1236896fff]: 4 changes artifact: fe1db40c92 user: dgp
21:46 • Add attachment 1236896.patch to ticket [1236896fff] artifact: 4db28c9d8d user: dgp
21:46 • Ticket [1236896fff] make -nocase behave correct with non-ASCII characters st... artifact: 5aaea0309a user: dgp
2005-07-15
05:21 • Ticket [1236896fff]: 4 changes artifact: db0f9a196e user: rmax
05:21 • Add attachment TclUtfCasecmp-4.patch to ticket [1236896fffffffff|123689... artifact: f095269521 user: rmax
05:21 • Ticket [1236896fff] make -nocase behave correct with non-ASCII characters st... artifact: c7896aeed1 user: rmax
03:15 • Ticket [1236896fff]: 4 changes artifact: 3a7bcab129 user: dgp
03:08 • Ticket [1236896fff]: 4 changes artifact: f4d9ebe987 user: dgp
02:16 • Ticket [1236896fff]: 4 changes artifact: af11f495ff user: rmax
02:16 • Add attachment TclUtfcasecmp-3.patch to ticket [1236896fffffffff|123689... artifact: 1ae97e0f97 user: rmax
02:16 • Ticket [1236896fff] make -nocase behave correct with non-ASCII characters st... artifact: 0594913814 user: rmax
2005-07-14
15:21 • Ticket [1236896fff]: 4 changes artifact: 3841d1048c user: rmax
15:16 • Ticket [1236896fff]: 4 changes artifact: 5940ac84a8 user: dkf
14:42 • Ticket [1236896fff]: 4 changes artifact: 4f43d809a3 user: mistachkin
05:07 • Ticket [1236896fff]: 4 changes artifact: e29b5f2da4 user: dgp
05:02 • Ticket [1236896fff]: 4 changes artifact: 45ba8c6485 user: dgp
2005-07-13
20:57 • Add attachment Tcl_Utfcasecmp.patch to ticket [1236896fffffffff|1236896... artifact: 637011273d user: rmax
20:57 • Ticket [1236896fff] make -nocase behave correct with non-ASCII characters st... artifact: 1bc971219d user: rmax
15:35 • Ticket [1236896fff]: 4 changes artifact: 55ce46f622 user: rmax
15:20 • Ticket [1236896fff]: 5 changes artifact: b063edf44d user: dkf
01:40 • Ticket [1236896fff]: 4 changes artifact: 0d94513b69 user: rmax
01:40 • Add attachment Tcl_Utfcasecmp.patch to ticket [1236896fffffffff|1236896... artifact: 515f49397f user: rmax
2005-07-12
18:40 • New ticket [1236896fff] make -nocase behave correct with non-ASCII characters</i... artifact: 762474e58d user: rmax

make -nocase behave correct with non-ASCII characters

Closed / Fixed1236896fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 13 years ago
Descriptionplain2005-07-12 18:40:41
This patch introduces a Tcl_UtfNcasecmp() function and
uses it as a replacement for strcasecmp in [lsearch],
[lsort], and [switch], when the -nocase option is given.

"make genstubs" is needed after applying the patch.

A TIP for this still has to be written.
rmaxplain2005-07-13 01:40:41
File Added - 141834: Tcl_Utfcasecmp.patch
dkfplain2005-07-13 15:20:12
Logged In: YES 
user_id=79902

We could try doing this in two stages.

Stage #1: Define a TclUtfNCaseCmp function (or something
similar) that is *not* in any stubs table, but which is used
to fix the guts of the various Tcl commands listed. This
part can be done now.

Stage #2: Change the name of the function to something
exported and put it in the stubs table. This is the stage
that needs documentation work and a TIP.
rmaxplain2005-07-13 15:35:05
Logged In: YES 
user_id=124643

Whoops, there is a typo in my initial comment:
Tcl_UtfNcasecmp() already exists, and my patch adds a
Tcl_Utfcasecmp() function (without "N").
rmaxplain2005-07-13 20:57:43
File Added - 141929: Tcl_Utfcasecmp.patch

Logged In: YES 
user_id=124643

I am uploading a revised version of the patch that changes
the name of the new API to Tcl_UtfCasecmp and removes a
misleading comment that was a copy-n-paste oversight.

Meanwhile I timed [lsort -nocase] and found it to take about
twice as long after adding this patch.
dgpplain2005-07-14 05:02:52
Logged In: YES 
user_id=80530


the new test cmdIL-5.6 has values
I assume are in the utf-8 encoding.

Since the *.test files get [source]d
in [encoding system], that's not
really portable.  Would be better to
use \uHHHH backslash substitution
to construct the test strings and results.
dgpplain2005-07-14 05:07:16
Logged In: YES 
user_id=80530


otherwise this looks ok.

I agree with dkf that a 
two-stage implementation
is the way to go.  Get the fix
in immediately.  Make it public
as approved.
mistachkinplain2005-07-14 14:42:00
Logged In: YES 
user_id=113501


Why does [lsort -nocase] take twice as long with this patch?
dkfplain2005-07-14 15:16:07
Logged In: YES 
user_id=79902

'cos usually strcasecmp() assumes one-byte-per-char and
probably ISO8859-* so case conversion can be done very
quickly. The updated version has to de-UTF8 each character
before case conversion.
rmaxplain2005-07-14 15:21:27
Logged In: YES 
user_id=124643

Look at the implementation of Tcl_UtfCasecmp. It has to do
much more work than strcasecmp does to give correct results
for non-ASCII characters.
rmaxplain2005-07-15 02:16:35
Logged In: YES 
user_id=124643

The new version of the patch does special-casing for ASCII
characters. It makes [lsearch] only slightly slower on lists
of pure ASCII strings, and also improves performance for
strings that contain a mix of ASCII and other characters.

It also renames follows dkf's advice and makes the function
private so that it can be applied without a TIP.
rmaxplain2005-07-15 02:16:37
File Added - 142083: TclUtfcasecmp-3.patch
dgpplain2005-07-15 03:08:05
Logged In: YES 
user_id=80530


It looks like the latest patch
doesn't limit its case-equivalencies
to alphabetic characters.

For example, the characters
'[' (\x5b) and '{' (\x7b) get treated
as -nocase equivalents because
they are the same with the 0x20
bit forced set.
dgpplain2005-07-15 03:15:31
Logged In: YES 
user_id=80530


demo session:

% lsort -nocase {@ `}
@ `
% lsort -nocase {` @}
` @
rmaxplain2005-07-15 05:21:39
Logged In: YES 
user_id=124643

OK, so this time it should really be correct, as I have
verified that TclUtfCasecmp produces exactly the same
results as strcasecmp for any combination of characters
between 0x01 and 0x7f, inclusive. I've also added dgp's demo
to the test suite.

I haven't yet timed this version, as I wrote it at home and
the code I used for the performance comparision is at work.
I'll do that tomorrow morning and report the results here.
rmaxplain2005-07-15 05:21:46
File Added - 142100: TclUtfCasecmp-4.patch
dgpplain2005-07-18 21:46:04
Logged In: YES 
user_id=80530


Here's an alternative patch.
Please check its performance
against the earlier patch.
dgpplain2005-07-18 21:46:06
File Added - 142444: 1236896.patch
rmaxplain2005-07-19 00:45:19
Logged In: YES 
user_id=124643

This is the fastest version I've been able to come up with.
The patch now adds the same ASCII optimisations to
Tcl_UtfNcmp and Tcl_UtfNcasecmp.
rmaxplain2005-07-19 00:45:20
File Added - 142464: TclUtfCasecmp-10.patch
jenglishplain2008-02-29 04:48:36
Logged In: YES 
user_id=68433
Originator: NO

See also #1902648.  This is a portability problem as well as a correctness problem.
jan.nijtmanswiki2013-07-03 11:12:52

Dup of [3613609]

Still want to write a TIP to put this function in the (public) stubs?

dkf Closed ticket [1236896fff]. [History diff]2013-11-12 14:41:00
Log in (anonymous is fine) to add a comment.

Attachments: