-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#![deny(rust_2018_idioms)] | ||
//! Provides functions to quote and possibly unquote strings with different quoting styles. | ||
#![deny(rust_2018_idioms, missing_docs)] | ||
#![forbid(unsafe_code)] | ||
|
||
/// | ||
pub mod ansi_c; | ||
|
||
mod single; | ||
pub use single::single; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use bstr::{BStr, BString, ByteSlice}; | ||
|
||
/// Transforms the given `value` to be suitable for use as an argument for Bourne shells by wrapping it into single quotes. | ||
/// | ||
/// Every single-quote `'` is escaped with `\'`, every exclamation mark `!` is escaped with `\!`, and the entire string is enclosed | ||
/// in single quotes. | ||
pub fn single(mut value: &BStr) -> BString { | ||
let mut quoted = BString::new(b"'".to_vec()); | ||
|
||
while let Some(pos) = value.find_byteset(b"!'") { | ||
quoted.extend_from_slice(&value[..pos]); | ||
quoted.push(b'\\'); | ||
quoted.push(value[pos]); | ||
|
||
value = &value[pos + 1..]; | ||
} | ||
|
||
quoted.extend_from_slice(value); | ||
quoted.push(b'\''); | ||
quoted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters