haxe
haxe copied to clipboard
haxe.Json does not encode Unicode properly
Any string containing emoji for example is corrupted on CPP. Using this fixes it:
function quote(s:UnicodeString) {
addChar('"'.code);
for (c in s) {
switch (c) {
case '"'.code:
add('\\"');
case '\\'.code:
add('\\\\');
case '\n'.code:
add('\\n');
case '\r'.code:
add('\\r');
case '\t'.code:
add('\\t');
case 8:
add('\\b');
case 12:
add('\\f');
default:
addChar(c);
}
}
addChar('"'.code);
}