forked from hummypkg/webif
d0cb142952
git-svn-id: file:///root/webif/svn/pkg/webif/trunk@3442 2a923420-c742-0410-a762-8d5b09965624
29 lines
855 B
Plaintext
29 lines
855 B
Plaintext
|
|
if {![exists -proc ::json::escape]} {
|
|
|
|
# Initialise a map from control characters to JSON escaped characters.
|
|
# Initially all non-null control characters to \u00xx sequences.
|
|
for {set i 1} {$i < 32} {incr i} {
|
|
set ::json::escape_map([format %c $i]) \\u[format %04x $i]
|
|
}
|
|
|
|
# Then overwrite certain well known control characters with shorter
|
|
# versions.
|
|
set ::json::escape_map([format %c 8]) \\b; # backspace
|
|
set ::json::escape_map([format %c 9]) \\t; # tab
|
|
set ::json::escape_map([format %c 10]) \\n; # lf
|
|
set ::json::escape_map([format %c 12]) \\f; # ff
|
|
set ::json::escape_map([format %c 13]) \\r; # cr
|
|
# Other special sequences
|
|
set ::json::escape_map(\") {\"}
|
|
set ::json::escape_map(\\) {\\}
|
|
set ::json::escape_map(/) {\/}
|
|
|
|
proc ::json::escape {in} {
|
|
return [string map $::json::escape_map $in]
|
|
}
|
|
|
|
alias jescape ::json::escape
|
|
}
|
|
|