<i>Tcl [string match] and [glob] are exponential complexity for bad patterns, could be linear</i> status still Open with 3 other changes
by
.
D 2017-05-02T11:12:40.223
J icomment Trying\sto\ssimplify\sTcl_StringCaseMatch\sso\sI\scan\sattack\sthis,\sa\sbunch\sof\sstrange\sedge\scases\scome\sup:\r\n\r\n%\sstring\smatch\s{[a}\sa\r\n1\r\n%\sstring\smatch\s{[a-}\sa\r\n0\r\n%\sstring\smatch\s{[a-z}\sa\r\n1\r\n%\sstring\smatch\s{[a-z}\sb\r\n1\r\n%\sstring\smatch\s{[a-]}\sa\r\n1\r\n%\sstring\smatch\s{[a-]}\sb\r\n0\r\n%\sstring\smatch\s{[a-]}\s-\r\n0\r\n%\sstring\smatch\s{[-a]}\sa\r\n1\r\n%\sstring\smatch\s{[-a]}\sb\r\n0\r\n%\sstring\smatch\s{[-a]}\s-\r\n1\r\n\r\nFurther,\sany\spattern\sending\swith\san\sodd\snumber\sof\sbackslashes\swill\snever\smatch.\r\n\r\nThere\sare\sthree\sspecial\scases\sto\sconsider:\r\n\r\n#1\s-\smalformed\spattern:\sends\swith\ssingle\s\\\r\n#2\s-\smalformed\spattern:\sunclosed\s[\ssequence\r\n#3\s-\s[a-]\s(and\s[-a])\r\n\r\nI\sthink\s#3\sshould\smatch\sexactly\s"a"\sand\s"-",\sas\s[-a]\sdoes\spresently.\s\sglob(3)\sagrees.\s\sThe\swording\sof\sstring(n)\simplies\sthis\sis\swhat\swill\shappen.\r\n\r\nfor\s#1,\s#2\sthere\sare\sthree\sarguments:\r\n\r\n\sa:\smalformed\spatterns\sshould\sbe\san\serror.\r\n\r\n\sb:\sagree\swith\sglob(3)\sand\streat\sthem\sas\sliterals.\r\n\r\n\sc:\smalformed\spatterns\smatch\snothing.\r\n\r\nSince\sTcl_StringMatch\shas\sno\sway\sto\sreport\serrors,\s(a)\sis\soff\sthe\stable.\s\sI\slean\sslightly\sto\soption\s(c)\sbecause\sit\skeeps\sthe\scode\ssimpler,\sand\sis\sclosest\sto\swhat\sTcl_StringMatch\sseems\sto\swant\sto\sdo.
J login aspect
J mimetype text/plain
K a4a7f2abd376b2806073d2865f07b7d910b04574
U aspect
Z 8a2c96e5e8f00af82eb9de0b842e6b0c