unescape_quoted

Function unescape_quoted 

Source
pub fn unescape_quoted(bytes: &[u8]) -> Unescape<'_> 
Expand description

Creates a streaming JSON string unescaper that handles enclosing quotes.

This function is a convenience wrapper around unescape. If the input byte slice starts and ends with a double-quote ("), the quotes are trimmed before the content is unescaped.

If the input is not enclosed in quotes, this function behaves identically to unescape.

§Examples

use json_escape::explicit::unescape_quoted;

// An input string with quotes and an escaped tab.
let bytes = br#""\tline""#;
let mut unescaper = unescape_quoted(bytes);

// The first chunk is the unescaped tab character.
let chunk1 = unescaper.next().unwrap().unwrap();
assert_eq!(b"", chunk1.literal());
assert_eq!(Some('\t'), chunk1.unescaped());

// The second chunk is the literal "line".
let chunk2 = unescaper.next().unwrap().unwrap();
assert_eq!(b"line", chunk2.literal());
assert_eq!(None, chunk2.unescaped());

// The iterator is now exhausted.
assert!(unescaper.next().is_none());