mirror of
https://github.com/matrix-construct/construct
synced 2024-10-03 06:08:52 +02:00
ircd::json: Add a specific escape transform utility to interface.
This commit is contained in:
parent
c0d575a4ee
commit
67d57ed2b6
2 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
17
ircd/json.cc
17
ircd/json.cc
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue