Posted to tcl by aspect at Sat Apr 26 09:12:37 GMT 2014view raw

  1. proc unicode {s} {
  2. join [lmap c [split $s ""] {
  3. scan $c %c x
  4. if {$x < 1<<16} {
  5. format \\u%04x $x
  6. } else {
  7. format \\U%08x $x
  8. }
  9. }] ""
  10. }