Posted to tcl by apn at Sun Apr 13 16:58:12 GMT 2014view raw

  1. # From tcllib -
  2. proc ::htmlparse::mapEscapes html {
  3. # Find HTML escape characters of the form &xxx(;|EOW)
  4.  
  5. # Quote special Tcl chars so they pass through [subst] unharmed.
  6. set new [string map [list \] \\\] \[ \\\[ \$ \\\$ \\ \\\\] $html]
  7. regsub -all -- {&([[:alnum:]]{2,7})(;|\M)} $new {[DoNamedMap \1 {\2}]} new
  8. regsub -all -- {&#([[:digit:]]{1,5})(;|\M)} $new {[DoDecMap \1 {\2}]} new
  9. regsub -all -- {&#x([[:xdigit:]]{1,4})(;|\M)} $new {[DoHexMap \1 {\2}]} new
  10. return [subst $new]
  11. }