TIP 241: Case-Insensitive Switches and List Searching and Sorting

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:         Joe Mistachkin <joe@mistachkin.com>
State:          Final
Type:           Project
Vote:           Done
Created:        26-Feb-2005
Post-History:   
Keywords:       Tcl,sorted lists,matching
Tcl-Version:    8.5

Abstract

This TIP proposes a -nocase option for the lsearch, lsort and switch commands to allow for case-insensitive handling of the specified list.

Rationale

The lsearch, lsort and switch commands are very flexible and powerful. However, in certain situations the ability to perform case-insensitive searching and sorting is absolutely required (such as searching fully qualified file names on file systems that do not differentiate between upper and lower case). Without the -nocase option, various unnatural workarounds are required. In addition, the -nocase option will finally bring the lsearch command into parity with the other comparison related operations, including string compare, string match, and regexp.

Specification

Options will be added like this:

lsearch ?-nocase? list pattern

lsort ?-nocase? list

switch ?-nocase? string bodyDefinition

For lsearch, the -nocase option can be used with the -ascii, -exact, -glob, and -regexp options. It indicates that the string of the found entry of list should match pattern case-insensitively. It is compatible with the -all, -decreasing, -increasing, -inline, -not and -start options.

For lsort, the -nocase option can be used with the -ascii option. It indicates that the list should be sorted based on a case-insensitive ordering. It is compatible with the -decreasing, -increasing, -index and -unique options.

For both lsearch and lsort, the -nocase option has no effect when used with the -dictionary, -integer, or -real options. For lsort, the -nocase option has no effect when used with the -command option.

For switch, the -nocase option can be used with all three matching modes (-exact, -glob, -regexp) and indicates that the matching of string should be performed in a case-insensitive manner.

Reference Implementation

A reference implementation of this TIP is available http://sourceforge.net/tracker/index.php?func=detail&aid=1152746&group_id=10894&atid=310894 .

Copyright

This document has been placed in the public domain.

History