escape8259

Crates.ioescape8259
lib.rsescape8259
version0.5.3
sourcesrc
created_at2020-04-17 20:21:16.522941
updated_at2024-06-08 17:48:33.244198
descriptionRFC8259-compliant string escaping and un-escaping
homepage
repositoryhttps://github.com/ericseppanen/escape8259
max_upload_size
id231308
size13,677
Eric Seppanen (ericseppanen)

documentation

README

escape8259 performs RFC8259-compliant string escaping and un-escaping.

RFC8259 is a JSON encoding standard. Many JSON encoders exist, but other RFCs use the same string escaping mechanism, so it's useful to be able to access the string escaping functions by themselves.

Examples

use escape8259::{escape, unescape};

let s = "A null (\0) and a double-quote (\")";
assert_eq!(escape(s), r#"A null (\u0000) and a double-quote (\")"#);

let crab = r#"This is a crab: \ud83e\udd80"#;
assert_eq!(unescape(crab).unwrap(), "This is a crab: 🦀");

// We accept encodings that weren't really necessary.
assert_eq!(unescape(r#"\u0041\n"#).unwrap(), "A\n");

let multiline = r#"hello
 world"#;
assert_eq!(escape(multiline), r#"hello\n world"#);
Commit count: 22

cargo fmt