| Crates.io | yash-quote |
| lib.rs | yash-quote |
| version | 1.1.1 |
| created_at | 2021-12-11 11:35:04.794134+00 |
| updated_at | 2023-11-11 15:14:59.50796+00 |
| description | Utility for quoting strings used in POSIX shell scripts |
| homepage | |
| repository | https://github.com/magicant/yash-rs |
| max_upload_size | |
| id | 496181 |
| size | 23,822 |
yash-quote is a Rust library crate for quoting strings used in a POSIX shell script.
This crate provides just one function: quote. It returns a quoted version of the argument string.
Add yash-quote as a dependency in your Cargo.toml.
use std::borrow::Cow::{Borrowed, Owned};
use yash_quote::quote;
assert_eq!(quote("foo"), Borrowed("foo"));
assert_eq!(quote(""), Owned::<str>("''".to_owned()));
assert_eq!(quote("$foo"), Owned::<str>("'$foo'".to_owned()));
assert_eq!(quote("'$foo'"), Owned::<str>(r#""'\$foo'""#.to_owned()));
MIT or Apache 2.0, at your option
r-shquote provides a function that always quotes using single quotes.quote function of the shell_words crate is similar but tries to return the argument unchanged if possible. Unlike yash-quote, it only supports ASCII characters.snailquote is also similar but uses an original format that is not fully compatible with POSIX shells.shell_quote returns a string escaped using Bash's $'...' notation.For the reverse operation of quote, the yash-syntax crate provides the unquote function.