Commit 14d8a91f authored by Jett's avatar Jett

Replace sprintf with hex function, this fixes #149

parent c0132232
...@@ -4677,11 +4677,19 @@ class basic_json ...@@ -4677,11 +4677,19 @@ class basic_json
{ {
if (c >= 0x00 and c <= 0x1f) if (c >= 0x00 and c <= 0x1f)
{ {
// convert a number 0..15 to its hex representation (0..f)
auto hexify = [](const char v) -> char
{
return (v < 10) ? ('0' + v) : ('a' + v - 10);
};
// print character c as \uxxxx // print character c as \uxxxx
sprintf(&result[pos + 1], "u%04x", int(c)); for(const char m : { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f) })
pos += 6; {
// overwrite trailing null character result[++pos] = m;
result[pos] = '\\'; }
++pos;
} }
else else
{ {
......
...@@ -4677,11 +4677,19 @@ class basic_json ...@@ -4677,11 +4677,19 @@ class basic_json
{ {
if (c >= 0x00 and c <= 0x1f) if (c >= 0x00 and c <= 0x1f)
{ {
// convert a number 0..15 to its hex representation (0..f)
auto hexify = [](const char v) -> char
{
return (v < 10) ? ('0' + v) : ('a' + v - 10);
};
// print character c as \uxxxx // print character c as \uxxxx
sprintf(&result[pos + 1], "u%04x", int(c)); for(const char m : { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f) })
pos += 6; {
// overwrite trailing null character result[++pos] = m;
result[pos] = '\\'; }
++pos;
} }
else else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment