Use to do something similar to this back in
the past with the following code which might well be a little faster (certainly
was in the Tcl7.6 days it was being used in, but Tcl8.4 with its lovely TclObjs
and bytecompilation might have reduced the difference)
define 'BadChars' as you will.
# <comment> persistant cache of bad
chars so escape will not regenerate them each time it is
called</comment>
namespace eval ::chars {
set gBadChars "" for {set i 127} {$i < 256} {incr i} { append gBadChars [format %c $i] } } # <proc
name="escapeChars">
# <comment> # Escape the explicitly named chars into html escape sequences # - will not escape square brackets, always leaves them alone. # do not include them in gBadChars or else it will go wrong. # </comment> # </proc> proc escapeChars {pText} {
# Put a backslash in front of all square brackets and backslashes before continuing regsub -all -- {\]|\[|\\} $pText {\\&} pText regsub -all -- "[format %c 91]$::chars::gBadChars[format %c 93]" $pText {[scan {&} %c c;set c "\&#$c;"]} vString return [subst -novariables $vString] } Of course this won't translate silly MS
characters into anything more sensible, and still relies on the browser being
able to correctly display the output.
you might need to play witht the encoding
command to do that
e.g.
encoding convertto iso8859-1
$pText
or alteratively deal with each of them as a
special case
e.g.
proc remove_MS_cruft { string2clean }
{
regsub -all {\\u2019} $string2clean {'} newString regsub -all {\\u201c} $newString {"} newString regsub -all {\\u201d} $newString {"} newString regsub -all {\\u2013} $newString {-} newString regsub -all {\\u201e} $newString {"} newString regsub -all {\\u2018} $newString {'} newString regsub -all {Ó} $newString {-} newString return [escapeChars $newString] }
|
- [AOLSERVER] more on special characters: smart quotes Scott Laplante
- Re: [AOLSERVER] more on special characters: smart quo... Mark Page
- Re: [AOLSERVER] more on special characters: smart quo... Jamie Rasmussen
- Re: [AOLSERVER] more on special characters: smart quo... Carson Evans
- Re: [AOLSERVER] more on special characters: smart quo... Chris Goehring
- Re: [AOLSERVER] more on special characters: smart quo... Chris Goehring
- Re: [AOLSERVER] more on special characters: smart quo... Michael Richman
- Tim Moss