[−][src]Crate mangling
This module provides for converting arbitrary byte streams into valid C-language identifiers and back again.
The resulting symbol begins with an underscore character _, and is
followed by zero or more groups of two types: printables and non-printables.
The content of the input byte stream determines which type of group comes
first, after which the two types alternate strictly.
- A printable group corresponds to the longest substring of the input that
can be consumed while matching the (case-insensitive) regular expression
[a-z][a-z0-9_]*. The mangled form isNaaawhereNis the unbounded decimal length of the substring in the original input, andaaais the literal substring. - A non-printable group represents the shortest substring in the input that
can be consumed before a printable substring begins to match. The mangled
form is
0N_xxxxxxwhere0and_are literal,Nis the unbounded decimal length of the substring in the original input, andxxxxxxis the lowercase hexadecimal expansion of the original bytes (two hexadecimal digits per input byte, most significant nybble first).
Note that despite the description above, the current implementation does not actually use regular expressions for matching.
For example:
let input = "abc/123x".as_bytes(); let expect = "_3abc04_2f3132331x"; let output = mangling::mangle(input.to_vec()); assert_eq!(output, expect); let reverse = mangling::demangle(expect).unwrap(); assert_eq!(reverse, input);
Functions
| demangle | Takes a string slice corresponding to a symbol as converted by the |
| mangle | Takes an |
Type Definitions
| ManglingResult | A generic Result type for functions in this module |