#json #rfc8259 #cddl

escape8259

RFC8259-compliant string escaping and un-escaping

4 releases

0.5.3 Jun 8, 2024
0.5.2 Aug 24, 2022
0.5.1 Aug 16, 2021
0.5.0 Apr 17, 2020

#249 in Encoding

Download history 46053/week @ 2024-06-26 41387/week @ 2024-07-03 42843/week @ 2024-07-10 47482/week @ 2024-07-17 49047/week @ 2024-07-24 49669/week @ 2024-07-31 53470/week @ 2024-08-07 51621/week @ 2024-08-14 52838/week @ 2024-08-21 50369/week @ 2024-08-28 50801/week @ 2024-09-04 49408/week @ 2024-09-11 47213/week @ 2024-09-18 45386/week @ 2024-09-25 50792/week @ 2024-10-02 44862/week @ 2024-10-09

197,050 downloads per month
Used in 92 crates (10 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"#);

No runtime deps