Skip to content
Tcl Source Code Artifact [9b78079142]
Login

Artifact [9b78079142]

Artifact 9b78079142651f8b5ed85f05e43a50fb8d100507:

Ticket change [9b78079142] - Ticket [ded7528bffe8bdf4|ded7528bff] <i>subst/regsub/format/scan gets confused by braces</i> status still Open with 3 other changes by dgp on 2014-02-16 03:55:36.
D 2014-02-16T03:55:36.473
J icomment There's\sno\sbug\sin\sTcl\sdemonstrated\shere.\r\n\r\nIt's\squite\slikely\syou\sare\sdemonstrating\sbuggy\sattempts\r\nto\saccomplish\swhatever\sit\sis\syou\sare\strying\sto\sdo.\r\n\r\nIt\shelps\snot\sto\sobscure\sthe\sintermediate\sresults,\sor\sto\r\ninclude\spointless\spreliminaries.\s\sExamine\sthis:\r\n\r\n%\sset\sa\s{w1\son\sthe\s<blah\sabc\s{}\sdef\s>\sform}\r\nw1\son\sthe\s<blah\sabc\s{}\sdef\s>\sform\r\n\r\n%\sset\sb\s[regsub\s-all\s{[\\[\\]\\\\\\{\\\\\\}\\$\\u0000-\\u001f\\u0080-\\uffff]}\s$a\s{[format\s"\\\\\\\\u%04x"\s[scan\s{&}\s%c]]}]\r\nw1\son\sthe\s<blah\sabc\s[format\s"\\\\u%04x"\s[scan\s{{}\s%c]][format\s"\\\\u%04x"\s[scan\s{}}\s%c]]\sdef\s>\sform\r\n\r\n\r\n%\sset\sc\s[subst\s$b]\r\nw1\son\sthe\s<blah\sabc\s\\u007b\sdef\s>\sform\r\n\r\n\r\nTake\sa\sgood\slook\sat\sthe\svalue\sof\s$b\sand\sthink\sthrough\s\r\nhow\s[subst]\sis\sgoing\sto\sparse\sthe\sbrace\squoted\swords\sin\r\nthe\scommand\ssubstitutions\sfound\swithin\sit.\s\sYou\slikely\r\nwere\snot\sexpecting\sthe\scommand\r\n\r\nscan\s{{}\s%c]][format\s"\\\\u%04x"\s[scan\s{}}\s%c\r\n\r\nto\sbe\spart\sof\sit,\sbut\sthat's\swhat\shappened.\s\s(That's\r\nthe\s[scan]\scommand\swith\sonly\s2\sarguments)\r\n\r\nJust\sas\sa\saside,\swhenever\syou\ssee\sa\sTcl\sprogrammer\strying\r\nto\sperfect\sstring\smanipulation\stechniques\sto\somit\sor\sdisguise\r\nbraces,\sit's\sa\svery\sgood\sbet\sthey\sare\smis-using\slists\ssomewhere.\r\nFrequently\sit\sinvolves\smistaking\sthe\sappearance\sof\sthe\slist\s\r\nitself\swith\sthe\sappearance\sof\sthe\selements\sit\scomprises.\r\nWhat\sis\sthe\sreal\sproblem\sto\sbe\ssolved\swhen\syou\sget\sinto\strouble?
J login dgp
J mimetype text/plain
K ded7528bffe8bdf4cf5ab9f327b50b207777378e
U dgp
Z 2dacdcd24f356d8d9ce071e7ee6d32e0