5 个版本 (稳定)
| 1.1.1 | 2023年11月11日 |
|---|---|
| 1.1.0 | 2023年5月1日 |
| 1.0.1 | 2023年1月5日 |
| 1.0.0 | 2022年2月2日 |
| 0.1.0 | 2021年12月11日 |
#229 in 命令行界面
每月 200 次下载
在 4 个crate(3个直接使用) 中使用
11KB
176 行代码(不包括注释)
Yash-quote
yash-quote 是一个用于在 POSIX shell 脚本中引号的 Rust 库 crate。此 crate 提供一个函数:quote。它返回一个引号版本的参数字符串。
用法
将 yash-quote 添加到您的 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 或 Apache 2.0,任选其一
类似 crate
r-shquote提供一个始终使用单引号引号的函数。shell_words的quote函数类似,但尽可能返回未更改的参数。与yash-quote不同,它仅支持 ASCII 字符。snailquote也类似,但使用一种与 POSIX shell 不完全兼容的原始格式。shell_quote返回一个使用 Bash 的$'...'符号进行转义的字符串。
对于 quote 的反向操作,yash-syntax crate 提供了 unquote 函数。