Crate r_shquote

source ·
Expand description

POSIX Shell Compatible Argument Parser

This crate implements POSIX Shell compatible quote and unquote operations. These allow to quote arbitrary strings so they are not interpreted by a shell if taken as input. In the same way it allows unquoting these strings to get back the original input.

The way this quoting works is mostly standardized by POSIX. However, many existing implementations support additional features. These are explicitly not supported by this crate, and it is not the intention of this crate to support these quirks and peculiarities.

The basic operations provided are quote() and unquote(), which both take a UTF-8 string as input, and produce the respective output string.

Examples

let str = "Hello World!";

println!("Quoted input: {}", r_shquote::quote(str));

Unquote operations can fail when the input is not well defined. The returned error contains diagnostics to identify where exactly the parser failed:

let quote = "'foobar";
let res = r_shquote::unquote(quote).unwrap_err();

println!("Unquote operation failed: {}", res);

Combining the quote and unquote operation always produces the original input:

let str = "foo bar";

assert_eq!(str, r_shquote::unquote(&r_shquote::quote(str)).unwrap());

Enums

Error information for unquote operations

Functions

Quote string
Unquote String