| Crates.io | escaping |
| lib.rs | escaping |
| version | 0.2.3 |
| created_at | 2025-08-13 20:23:38.319648+00 |
| updated_at | 2025-08-14 16:46:59.877037+00 |
| description | configurable string escaping and unescaping |
| homepage | |
| repository | https://github.com/estokes/escaping |
| max_upload_size | |
| id | 1794048 |
| size | 35,925 |
Escaping is a general purpose escaping library that is const compatible (for the configuration). You can configure an escape character, a set of characters you want to escape, and a set of translations you want to use for escaped characters (for example to handle non printable characters). It provides,
Say you are writing a compiler and you want to implement interpolation of expressions surrounded by [] in string literals, as well as C like escapes, and escaping of any remaining control characters to generic \u{HHHH} format.
use escaping::Escape;
fn use_generic_escape(c: char) -> bool {
c.is_control()
}
const ESC: Escape<8, 4> = Escape::const_new(
'\\',
['\\', '[', ']', '"', '\0', '\n', '\r', '\t'],
[('\n', "n"), ('\r', "r"), ('\0', "0"), ('\t', "t")],
Some(use_generic_escape),
);
fn main() {
assert_eq!(ESC.escape("foo [e] bar\n"), r#"foo \[e\] bar\n"#);
assert_eq!(ESC.unescape(r#"foo \[e\] bar\n"#), "foo [e] bar\n");
}