unescaper

Unescape Rust strings whose escape sequences are written out as literal characters

Library
Cargo
v0.2.0
31stars
MIT OR GPL-3.0-only

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
58/100Fair
Development Activity84
Maintenance64
Community16
Maturity56
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture76
Code Quality80
Innovation68
Learning Curve85

unescaper is a small Rust crate that turns strings containing literal escape sequences back into their real characters. When text arrives with backslash escapes written out verbatim, such as a two-character sequence backslash-n instead of an actual newline, unescaper decodes them into the characters they represent.

It handles ASCII control escapes, quotes and slashes, Unicode scalar values in both fixed and braced forms, hex byte escapes, and octal bytes. A strict unescape returns an error on malformed input, while a lossy variant decodes what it can and preserves malformed escapes as written.

What You Get

  • An unescape function that decodes escape sequences and returns a Result, erroring on malformed input
  • An unescape_lossy function that decodes valid escapes and preserves malformed ones as written
  • Support for ASCII control escapes, quotes, slashes, Unicode (\u000a and \u{a}), hex (\x0a), and octal bytes
  • A typed error via thiserror describing exactly what went wrong in a malformed sequence

Common Use Cases

  • Decoding string literals read from config files, logs, or serialized data
  • Building interpreters or parsers that need to resolve source-level escape sequences
  • Normalizing user or machine input where escapes were stored as literal text

Under The Hood

Architecture - The crate is a single-purpose module in src/lib.rs (~370 lines) exposing two entry points, unescape and unescape_lossy. Both walk the input character by character; on encountering a backslash they dispatch on the following character to parse control escapes, quote/slash literals, or numeric forms (Unicode \u, braced \u{...}, hex \x, and octal), accumulating decoded characters into the output string. The lossy variant re-emits any malformed sequence unchanged instead of returning an error.

Tech Stack - Pure Rust on edition 2024. The only runtime dependency is thiserror for the error type; proptest is used as a dev-dependency for property-based testing. No unsafe or platform-specific code.

Code Quality - A compact implementation paired with a dedicated src/test.rs (~177 lines) plus property tests via proptest, giving strong coverage of edge cases across escape forms. Errors are modeled explicitly rather than panicking.

API Design - The public surface is two free functions with obvious names and signatures returning either a Result<String> or a plain String. There is essentially no setup or configuration, making it trivial to adopt and giving it a very gentle learning curve.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search