RosettaCodeData/Task/Strip-comments-from-a-string/Tcl/strip-comments-from-a-string-3.tcl
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

8 lines
464 B
Tcl

proc stripLineComments {inputString {commentChars ";#"}} {
# Convert the character set into a transformation
foreach c [split $commentChars ""] {lappend map $c "\uFFFF"}; # *very* rare character!
# Apply transformation and then use a simpler constant RE to strip
regsub -all -line {\uFFFF.*$} [string map $map $inputString] "" commentStripped
# Now strip the whitespace
regsub -all -line {^[ \t\r]*(.*\S)?[ \t\r]*$} $commentStripped {\1}
}