descape-1.2.0 has been yanked.
descape
Provides utilities for easily parsing escape sequences in a string, using alloc::borrow::Cow to only borrow when needed.
This library supports many escape sequences:
- All escapes mentioned in the documentation of
core::ascii::Char \\'->'\\"->"- \\` -> `
\\\\->\\\\xNN->\xNN\\o->\o, for all octal digitso\\oo->\oo, for all octal digitso\\ooo->\ooo, for all octal digitso\\uXXXX->\u{XXXX}\\u{HEX}->\u{HEX}
Along with this, you can define your own custom escape handlers! See UnescapeExt::to_unescaped_with for more information on that.
This crate supports no-std.
Examples
Parsing an escaped string
let escaped = "Hello,\\nworld!".to_unescaped;
assert_eq!;
Not allocating for a string without escapes
let no_escapes = "No escapes here!".to_unescaped;
assert_eq!;
Erroring for invalid escapes
let invalid_escape = r"Uh oh! \xJJ".to_unescaped;
assert_eq!;
Custom escape handlers
let escaped = r"\H\e\l\l\o \n \W\o\r\l\d";
let unescaped = escaped.to_unescaped_with.expect;
assert_eq!;