0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::json: Safer unquote for json::string constructions; specify constructions.

This commit is contained in:
Jason Volk 2019-02-20 11:21:25 -08:00
parent 2b2725f7c1
commit a441c77b6b

View file

@ -50,11 +50,27 @@ namespace ircd::json
struct ircd::json::string
:string_view
{
string(const string_view &s)
:string_view{unquote(s)}
{}
string() = default;
string(json::string &&) = default;
string(const json::string &) = default;
string(const string_view &s)
:string_view
{
surrounds(s, '"')?
unquote(s):
s
}{}
string &operator=(json::string &&) = default;
string &operator=(const json::string &) = default;
string &operator=(const string_view &s)
{
*static_cast<string_view *>(this) = surrounds(s, '"')?
unquote(s):
s;
return *this;
}
};
/// Alternative to `json::strung` which uses a fixed array rather than an