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

proc unicode {s} {
    join [lmap c [split $s ""] {
        scan $c %c x
        if {$x < 1<<16} {
            format \\u%04x $x
        } else {
            format \\U%08x $x
        }
    }] ""      
}