mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
std.json: Inline appendJSONChar
Since the previous commit, it was only called from one place.
This commit is contained in:
parent
55aa34e440
commit
e44666fc51
1 changed files with 19 additions and 22 deletions
41
std/json.d
41
std/json.d
|
@ -1117,7 +1117,25 @@ string toJSON(const ref JSONValue root, in bool pretty = false, in JSONOptions o
|
||||||
case '\r': json.put("\\r"); break;
|
case '\r': json.put("\\r"); break;
|
||||||
case '\t': json.put("\\t"); break;
|
case '\t': json.put("\\t"); break;
|
||||||
default:
|
default:
|
||||||
appendJSONChar(json, c, options);
|
{
|
||||||
|
import std.uni : isControl;
|
||||||
|
|
||||||
|
with (JSONOptions) if (isControl(c) ||
|
||||||
|
((options & escapeNonAsciiChars) >= escapeNonAsciiChars && c >= 0x80))
|
||||||
|
{
|
||||||
|
json.put("\\u");
|
||||||
|
foreach_reverse (i; 0 .. 4)
|
||||||
|
{
|
||||||
|
char ch = (c >>> (4 * i)) & 0x0f;
|
||||||
|
ch += ch < 10 ? '0' : 'A' - 10;
|
||||||
|
json.put(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json.put(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1284,27 +1302,6 @@ string toJSON(const ref JSONValue root, in bool pretty = false, in JSONOptions o
|
||||||
return json.data;
|
return json.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendJSONChar(ref Appender!string dst, dchar c, JSONOptions opts) @safe
|
|
||||||
{
|
|
||||||
import std.uni : isControl;
|
|
||||||
|
|
||||||
with (JSONOptions) if (isControl(c) ||
|
|
||||||
((opts & escapeNonAsciiChars) >= escapeNonAsciiChars && c >= 0x80))
|
|
||||||
{
|
|
||||||
dst.put("\\u");
|
|
||||||
foreach_reverse (i; 0 .. 4)
|
|
||||||
{
|
|
||||||
char ch = (c >>> (4 * i)) & 0x0f;
|
|
||||||
ch += ch < 10 ? '0' : 'A' - 10;
|
|
||||||
dst.put(ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dst.put(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@safe unittest // bugzilla 12897
|
@safe unittest // bugzilla 12897
|
||||||
{
|
{
|
||||||
JSONValue jv0 = JSONValue("test测试");
|
JSONValue jv0 = JSONValue("test测试");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue