#json #rfc8259 #cddl

escape8259

RFC8259-compliant string escaping and un-escaping

3 releases

0.5.2 Aug 24, 2022
0.5.1 Aug 16, 2021
0.5.0 Apr 17, 2020

#762 in Encoding

Download history 7177/week @ 2023-11-24 7642/week @ 2023-12-01 7404/week @ 2023-12-08 7111/week @ 2023-12-15 5874/week @ 2023-12-22 6351/week @ 2023-12-29 7695/week @ 2024-01-05 14840/week @ 2024-01-12 27036/week @ 2024-01-19 23295/week @ 2024-01-26 21533/week @ 2024-02-02 13835/week @ 2024-02-09 16186/week @ 2024-02-16 19080/week @ 2024-02-23 19708/week @ 2024-03-01 9445/week @ 2024-03-08

66,393 downloads per month
Used in 37 crates (8 directly)

MIT license

13KB
216 lines

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"#);

lib.rs:

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"#);

Dependencies