Skip to content
Tcl Source Code Artifact [bccb4aa0bb]
Login

Artifact [bccb4aa0bb]

Artifact bccb4aa0bbcd955a6514dd1692c4f9ae48daf874:

Ticket change [bccb4aa0bb] - Ticket [1152746fffffffff|1152746fff] <i>TIP #241 -nocase option for [lsearch], [lsort], and [switch]</i> status still Closed with 4 other changes by kchansen on 2005-11-15 01:31:45.
D 2005-11-15T01:31:45
J icomment Logged\sIn:\sYES\s\nuser_id=614439\n\nA\sTcl-only\sapproach....\n\nI\sneeded\sa\s-nocase\soption\sfor\sthe\sswitch\sstatement,\sscanned\s\nthe\stips\sand\sfound\sthis\sone.\s\sHere\sis\sthe\sapproach\sI\stook\sto\s\nget\seffectively\sthe\ssame\sbehavior:\n\nproc\sCreateCaselessRegExp\s{Text}\s{\n\s\sset\sTextUpper\s[split\s[string\stoupper\s$Text]\s{}]\n\s\sset\sTextLower\s[split\s[string\stolower\s$Text]\s{}]\n\n\s\sforeach\sUpper\s$TextUpper\sLower\s$TextLower\s{\n\s\s\s\slappend\sTextResult\s"\\[$TextUpper$TextLower\\]"\n\s\s\s\s}\n\n\s\sset\sRegExp\s[join\s$TextResult\s{}]\n\n\s\sreturn\s$RegExp\n\s\s};#\sCreateCaselessRegExp\n\nWith\sthis\sproc,\sa\s"switch"\swith\s"-exact"\sand\s"-nocase"\s\nreplaces\sthose\soptions\swith\s"-regexp",\sand\sreplaces\sthe\sexact\s\nstrings\swith\sthe\sresult\sof\scalling\sCreateCaselessRegExp.\s\sYou\s\nmust\salso\scheck\sto\ssee\sif\sthe\stest\svalue\sis\s"default"\sand\snot\s\nchange\sit\swhen\sit\sis\sencountered.\n\nFor\sexample:\n\nswitch\s-exact\s-nocase\s--\s$MyText\s{\n\s\sFirst\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\sThird\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s"Another\sone\shere"\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s"Test\s#9"\s{\n\s\s\s\s}\n\s\sdefault\s{\n\s\s\s\s}\n\s\s}\n\nbecomes:\n\nswitch\s-regexp\s--\s$MyText\s{\n\s\s[Ff][Ii][Rr][Ss][Tt]\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s[Tt][Hh][Ii][Rr][Dd]\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s"[Aa][Nn][Oo][Tt][Hh][Ee][Rr][\s\s][Oo][Nn][Ee][\s\s][Hh][Ee][Rr]\n[Ee]"\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s"[Tt][Ee][Ss][Tt][\s\s][##][99]"\s{\n\s\s\s\s}\n\s\sdefault\s{\n\s\s\s\s}\n\s\s}\n\nI\sactually\sended\sup\scoding\sas:\n\neval\s{switch\s-exact\s-nocase\s--\s$MyText\s{\n\s\s[CreateCaselessRegExp\sFirst]\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s[CreateCaselessRegExp\sThird]\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s[CreateCaselessRegExp\s"Another\sone\shere"]\s{\n\s\s\s\s...\n\s\s\s\s}\n\s\s[CreateCaselessRegExp\s"Test\s#9"]\s{\n\s\s\s\s}\n\s\sdefault\s{\n\s\s\s\s}\n\s\s}}\n\nAs\syou\scan\ssee,\sit\scould\sbe\smade\sa\slittle\ssmarter\sbecause\sall\s\nnon-alphabet\scharacters\send\sup\sdoubled.\s\sA\stest\scould\sbe\sput\s\nin\sto\snot\screate\sa\s"one\sof\slist"\sselections\sfor\sthings\swhich\sare\s\nnot\salphabet,\sbut\sI\sfigured\sit\swas\sfine\sfor\sa\sfirst\scut....\s\sI\salso\s\nliked\sthe\sfact\sthat\sI\swas\sable\sto\sget\sthe\scase\sinsensitivity\swith\s\nvery\slittle\sextra\seffort....\n<Karl\sC.\sHansen>\n\n
J login kchansen
J mimetype text/plain
J username kchansen
K 1152746fffffffffffffffffffffffffffffffff
U kchansen
Z 75ce94664f8f07559d9aa494e6851a71