Overview
| Artifact ID: | 9b78079142651f8b5ed85f05e43a50fb8d100507 |
|---|---|
| Ticket: | ded7528bffe8bdf4cf5ab9f327b50b207777378e
subst/regsub/format/scan gets confused by braces |
| User & Date: | dgp on 2014-02-16 03:55:36 |
Changes
- icomment:
There's no bug in Tcl demonstrated here. It's quite likely you are demonstrating buggy attempts to accomplish whatever it is you are trying to do. It helps not to obscure the intermediate results, or to include pointless preliminaries. Examine this: % set a {w1 on the <blah abc {} def > form} w1 on the <blah abc {} def > form % set b [regsub -all {[\[\]\\\{\\\}\$\u0000-\u001f\u0080-\uffff]} $a {[format "\\\\u%04x" [scan {&} %c]]}] w1 on the <blah abc [format "\\u%04x" [scan {{} %c]][format "\\u%04x" [scan {}} %c]] def > form % set c [subst $b] w1 on the <blah abc \u007b def > form Take a good look at the value of $b and think through how [subst] is going to parse the brace quoted words in the command substitutions found within it. You likely were not expecting the command scan {{} %c]][format "\\u%04x" [scan {}} %c to be part of it, but that's what happened. (That's the [scan] command with only 2 arguments) Just as a aside, whenever you see a Tcl programmer trying to perfect string manipulation techniques to omit or disguise braces, it's a very good bet they are mis-using lists somewhere. Frequently it involves mistaking the appearance of the list itself with the appearance of the elements it comprises. What is the real problem to be solved when you get into trouble? - login: "dgp"
- mimetype: "text/plain"