I\'m writing a utility (which happens to be in python) which is generating output in the form of a TCL script. Given some arbitrary string variable (not unicode) in the python,
You really only need 2 rules,
You don't need to worry about newlines, non printable characters etc. They are valid in a literal string, and TCL has excellent Unicode support.
set s {
this is
a
long
string. I have $10 [10,000 cents] only curly braces \{ need \} to be escaped.
\t is not a real tab, but ' ' is. "quoting somthing" :
{matchin` curly braces are okay, list = string in tcl}
}
Edit In light of your comment, you can do the following:
[]
{}
and $
set s [subst { $output } ]
The beauty of Tcl is it a has a very simple grammar. There are no other characters besides the 3 above needed to be escaped.
Edit 2 One last try.
If you pass subst
some options, you will only need to escape \
and {}
set s [subst -nocommands -novariables { $output } ]
You would need to come up with a regex to convert non printable characters to their escaped codes however.
Good luck!