0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd::json: Conditions for which string grammar to invoke.

This commit is contained in:
Jason Volk 2018-09-05 23:10:51 -07:00
parent 8593d09c80
commit 5ac5a26f83

View file

@ -212,12 +212,6 @@ struct ircd::json::output
,"number"
};
rule<string_view> chars
{
*(char_)
,"characters"
};
rule<string_view> quoted
{
char_('"') << *char_ << char_('"')
@ -1983,11 +1977,28 @@ ircd::json::stringify(mutable_buffer &buf,
{
case STRING:
{
const string_view sv{v};
printer(buf, printer.string, sv);
//TODO: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
const string_view ret{start, begin(buf)};
if(endswith(ret, "\\\"")) printer(buf, printer.quote);
if(!v.string)
{
consume(buf, copy(buf, empty_string));
break;
}
const string_view sv
{
v.string, v.len
};
if(v.serial)
{
consume(buf, copy(buf, sv));
break;
}
if(surrounds(sv, '"'))
printer(buf, printer.quoted, sv);
else
printer(buf, printer.unquoted, sv);
break;
}
@ -2124,6 +2135,9 @@ ircd::json::serialized(const value &v)
if(!v.string)
return size(empty_string);
if(v.serial)
return v.len;
size_t ret(v.len);
const string_view sv{v.string, v.len};
ret += !startswith(sv, '"');