]> git.ozlabs.org Git - ccan/commit
json_escape: add json_escape_unescape_len()
authorMatt Whitlock <ccan@mattwhitlock.name>
Mon, 14 Jul 2025 10:02:58 +0000 (06:02 -0400)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 15 Aug 2025 00:50:02 +0000 (10:20 +0930)
commite43c61c4c760aed7fd4ab6b716b019fc170f280d
tree7431ebc58669a0134b07ca24044bcf60d2cfb695
parent8f77bab685f87b29f933fd36076f3c0d4614dc85
json_escape: add json_escape_unescape_len()

Lacking a variant of json_escape_unescape() that takes a sized span,
the common case of unescaping a JSON string that is embedded inside a
larger buffer is forced to make a copy of the escaped string so as to
terminate it with a NUL character. This extra copy can be avoided if
we can pass an explicit length to the unescaping function.

Also, a drive-by fix: shrink the returned unescaped string to fit its
contents, which can save the caller a subsequent call to strlen().
ccan/json_escape/json_escape.c
ccan/json_escape/json_escape.h