www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12897] New: std.json.toJSON doesn't translate unicode

https://issues.dlang.org/show_bug.cgi?id=12897

          Issue ID: 12897
           Summary: std.json.toJSON doesn't translate unicode
                    chars(>=0x80) to "\uXXXX"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: egustc gmail.com

Created attachment 1362
  --> https://issues.dlang.org/attachment.cgi?id=1362&action=edit
json bug

As the attachment showed, uUnicode chars GE than 0x80 (for exp.: Chinese,
Japanese ) should be converted to "\uXXXX" in JSON. But Phobos doesn't. It
causes problems while transmitting JSON from D to other languages.

A std.json.appendJSONChar implement can fix this bug:
private void appendJSONChar(Appender!string* dst, wchar c)
{
    if(isControl(c) || c>=0x80)
        dst.put("\\u%04x".format(c));
    else
        dst.put(c);
}

--
Jun 12 2014