pub fn unescape_quoted<I: AsRef<[u8]> + ?Sized>(input: &I) -> Unescape<'_> ⓘ
Expand description
Creates a streaming JSON string unescaper, trimming enclosing quotes.
This function acts as a convenience wrapper around unescape
. It first
inspects the input byte slice. If the slice begins and ends with a double-quote
character ("
), these quotes are trimmed before the inner content is passed to
the unescaper.
If the input is not enclosed in quotes, this function behaves exactly like
unescape
. This is useful for directly unescaping a complete JSON string
literal.
§Example
use json_escape::{unescape, unescape_quoted};
// 1. With quotes: The outer quotes are trimmed before unescaping.
let unescaper = unescape_quoted(r#""hello\nworld""#);
assert_eq!(unescaper, b"hello\nworld");
// 2. Without quotes: Behaves exactly like the standard `unescape`.
let unescaper_no_quotes = unescape_quoted(r#"raw string"#);
assert_eq!(unescaper_no_quotes, b"raw string");
// 3. Mismatched quotes: The input is passed through as-is, quotes are not trimmed.
let mismatched_quotes = unescape_quoted(r#"hello""#);
assert_eq!(mismatched_quotes, b"hello\"");
// 4. Empty quoted string: Correctly results in an empty output.
let empty_quoted = unescape_quoted(r#""""#);
assert_eq!(empty_quoted, b"");