1 /* MIT (BSD) license - see LICENSE file for details */
2 #ifndef CCAN_JSON_ESCAPE_H
3 #define CCAN_JSON_ESCAPE_H
5 #include <ccan/tal/tal.h>
7 /* Type differentiation for a correctly-escaped JSON string */
9 /* NUL terminated string. */
14 * json_escape - escape a valid UTF-8 string.
15 * @ctx: tal context to allocate from.
16 * @str: the string to escape.
18 * Allocates and returns a valid JSON string (without surrounding quotes).
20 struct json_escape *json_escape(const tal_t *ctx, const char *str TAKES);
22 /* Version with @len */
23 struct json_escape *json_escape_len(const tal_t *ctx,
24 const char *str TAKES, size_t len);
26 /* @str is a valid UTF-8 string which may already contain escapes. */
27 struct json_escape *json_partial_escape(const tal_t *ctx,
28 const char *str TAKES);
30 /* Extract a JSON-escaped string. */
32 /* Are two escape json strings identical? */
33 bool json_escape_eq(const struct json_escape *a,
34 const struct json_escape *b);
36 /* Internal routine for creating json_escape from bytes. */
37 struct json_escape *json_escape_string_(const tal_t *ctx,
38 const void *bytes, size_t len);
40 /* Be very careful here! Can fail! Doesn't handle \u: use UTF-8 please. */
41 const char *json_escape_unescape(const tal_t *ctx,
42 const struct json_escape *esc);
43 #endif /* CCAN_JSON_ESCAPE_H */