0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-03 17:28:18 +02:00

ircd::json: Add a specific escape transform utility to interface.

This commit is contained in:
Jason Volk 2019-02-05 15:42:39 -08:00
parent c0d575a4ee
commit 67d57ed2b6
2 changed files with 20 additions and 0 deletions

View file

@ -40,6 +40,9 @@ namespace ircd::json
// (Internal) validates output
void valid_output(const string_view &, const size_t &expected);
// Transforms input into escaped output only
string_view escape(const mutable_buffer &out, const string_view &in);
}
/// Strong type representing quoted strings in JSON (which may be unquoted

View file

@ -3396,6 +3396,23 @@ static_assert
ircd::json::undefined_number != 0
);
ircd::string_view
ircd::json::escape(const mutable_buffer &buf,
const string_view &in)
{
static const printer::rule<string_view> characters
{
*(printer.character)
};
mutable_buffer out{buf};
printer(out, characters, in);
return string_view
{
data(buf), data(out)
};
}
std::string
ircd::json::why(const string_view &s)
try