aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbutl/json/serializer.cxx2
-rw-r--r--libbutl/json/serializer.hxx12
-rw-r--r--libbutl/json/serializer.ixx15
3 files changed, 29 insertions, 0 deletions
diff --git a/libbutl/json/serializer.cxx b/libbutl/json/serializer.cxx
index 84941ed..0e8b566 100644
--- a/libbutl/json/serializer.cxx
+++ b/libbutl/json/serializer.cxx
@@ -283,6 +283,8 @@ namespace butl
// Fall through.
case event::number:
{
+ // Note: this event is also used by value_json_text().
+
if (st != nullptr && name_expected (*st))
goto fail_unexpected_event;
diff --git a/libbutl/json/serializer.hxx b/libbutl/json/serializer.hxx
index fad91e2..b52bf65 100644
--- a/libbutl/json/serializer.hxx
+++ b/libbutl/json/serializer.hxx
@@ -235,6 +235,18 @@ namespace butl
void
value (std::nullptr_t);
+ // Serialize value as a pre-serialized JSON value.
+ //
+ // Note that the value is expected to be a valid (and suitable) UTF-8-
+ // encoded JSON text. Note also that if pretty-printing is enabled,
+ // the resulting output may not be correctly indented.
+ //
+ void
+ value_json_text (const char*);
+
+ void
+ value_json_text (const std::string&);
+
// Serialize next JSON event.
//
// If check is false, then don't check whether the value is valid UTF-8
diff --git a/libbutl/json/serializer.ixx b/libbutl/json/serializer.ixx
index 5b2c173..50fe397 100644
--- a/libbutl/json/serializer.ixx
+++ b/libbutl/json/serializer.ixx
@@ -151,6 +151,21 @@ namespace butl
next (event::null);
}
+ inline void buffer_serializer::
+ value_json_text (const char* v)
+ {
+ // Use event::number (which doesn't involve any quoting) with a disabled
+ // check.
+ //
+ next (event::number, {v, strlen (v)}, false /* check */);
+ }
+
+ inline void buffer_serializer::
+ value_json_text (const std::string& v)
+ {
+ next (event::number, {v.c_str (), v.size ()}, false /* check */);
+ }
+
inline size_t buffer_serializer::
to_chars (char* b, size_t s, int v)
{