Crate descape

Source
Expand description

§descape

Provides utilities for easily parsing escape sequences in a string via UnescapeExt, using alloc::borrow::Cow to only borrow when needed.

This library supports many escape sequences:

  • \\a -> \x07
  • \\b -> \x08
  • \\t -> \x09
  • \\n -> \x0A
  • \\v -> \x0B
  • \\f -> \x0C
  • \\r -> \x0D
  • \\e -> \x1B
  • \\' -> '
  • \\" -> "
  • \\` -> `
  • \\\\ -> \\
  • \\xNN -> \xNN
  • \\o -> \o, for all octal digits o
  • \\oo -> \oo, for all octal digits o
  • \\ooo -> \ooo, for all octal digits o
  • \\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.

Optionally, this crate has the std and core_error features, to allow the error type of an invalid escape to implement the Error trait.

std uses std::error::Error, and core_error depends on core::error::Error, which is stable on Rust 1.82.0 or greater.

Structs§

DefaultHandler
The default escape sequence handler.
InvalidEscape
An error representing an invalid escape sequence in a string.

Traits§

EscapeHandler
A trait distinguishing an object as a handler for custom escape sequences.
UnescapeExt
An extension trait for &str to allow parsing escape sequences in strings, only copying when needed.