mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 18:30:06 +00:00
json.marshal
This commit is contained in:
@@ -117,7 +117,7 @@ write_encoded_rune :: proc(b: ^Builder, r: rune, write_quote := true) {
|
||||
}
|
||||
|
||||
|
||||
write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte) {
|
||||
write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false) {
|
||||
is_printable :: proc(r: rune) -> bool {
|
||||
if r <= 0xff {
|
||||
switch r {
|
||||
@@ -132,6 +132,18 @@ write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if html_safe {
|
||||
switch r {
|
||||
case '<', '>', '&':
|
||||
write_byte(b, '\\');
|
||||
write_byte(b, 'u');
|
||||
for s := 12; s >= 0; s -= 4 {
|
||||
write_byte(b, DIGITS_LOWER[r>>uint(s) & 0xf]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if r == rune(quote) || r == '\\' {
|
||||
write_byte(b, '\\');
|
||||
write_byte(b, byte(r));
|
||||
|
||||
Reference in New Issue
Block a user