Function snailquote::unescape[][src]

pub fn unescape(s: &str) -> Result<String, UnescapeError>
Expand description

Parse the provided shell-like quoted string, such as one produced by escape.

Details

Unescape is able to handle single quotes (which cannot contain any additional escapes), double quotes (which may contain a set of escapes similar to ANSI-C, i.e. ‘\n’, ‘\r’, ‘'’, etc. Unescape will also parse unicode escapes of the form “\u{01ff}”. See char::escape_unicode in the Rust standard library for more information on these escapes.

Multiple different quoting styles may be used in one string, for example, the following string is valid: 'some spaces'_some_unquoted_"and a \t tab".

The full set of supported escapes between double quotes may be found below:

EscapeUnicodeDescription
\a\u{07}Bell
\b\u{08}Backspace
\v\u{0B}Vertical tab
\f\u{0C}Form feed
\n\u{0A}Newline
\r\u{0D}Carriage return
\t\u{09}Tab
\e\u{1B}Escape
\E\u{1B}Escape
\\u{5C}Backslash
'\u{27}Single quote
"\u{22}Double quote
$\u{24}Dollar sign (sh compatibility)
`\u{60}Backtick (sh compatibility)
\u{XX}\u{XX}Unicode character with hex code XX

Errors

The returned result can display a human readable error if the string cannot be parsed as a valid quoted string.

Examples

use snailquote::unescape;
println!("{}", unescape("foo").unwrap());
// foo
println!("{}", unescape("'String with spaces'").unwrap());
// String with spaces
println!("{}", unescape("\"new\\nline\"").unwrap());
// new
// line
println!("{}", unescape("'some spaces'_some_unquoted_\"and a \\t tab\"").unwrap());
// some spaces_some_unquoted_and a 	 tab