pub struct Quoter { /* private fields */ }
Expand description
A more configurable interface to quote strings. If you only want the default settings you can
use the convenience functions try_quote
and try_join
.
The string equivalent is shlex::Quoter
.
Implementations§
Source§impl Quoter
impl Quoter
Sourcepub fn allow_nul(self, allow: bool) -> Self
pub fn allow_nul(self, allow: bool) -> Self
Set whether to allow nul bytes. By default they are not
allowed and will result in an error of QuoteError::Nul
.
Sourcepub fn join<'a, I: IntoIterator<Item = &'a [u8]>>(
&self,
words: I,
) -> Result<Vec<u8>, QuoteError>
pub fn join<'a, I: IntoIterator<Item = &'a [u8]>>( &self, words: I, ) -> Result<Vec<u8>, QuoteError>
Convenience function that consumes an iterable of words and turns it into a single byte string, quoting words when necessary. Consecutive words will be separated by a single space.
Sourcepub fn quote<'a>(&self, in_bytes: &'a [u8]) -> Result<Cow<'a, [u8]>, QuoteError>
pub fn quote<'a>(&self, in_bytes: &'a [u8]) -> Result<Cow<'a, [u8]>, QuoteError>
Given a single word, return a byte string suitable to encode it as a shell argument.
If given valid UTF-8, this will never produce invalid UTF-8. This is because it only ever inserts valid ASCII characters before or after existing ASCII characters (or returns two single quotes if the input was an empty string). It will never modify a multibyte UTF-8 character.