Module shlex::bytes

source ·
Expand description

Shlex and friends for byte strings.

This is used internally by the outer module, and may be more convenient if you are working with byte slices ([u8]) or types that are wrappers around bytes, such as OsStr:

#[cfg(unix)] {
    use shlex::bytes::quote;
    use std::ffi::OsStr;
    use std::os::unix::ffi::OsStrExt;

    // `\x80` is invalid in UTF-8.
    let os_str = OsStr::from_bytes(b"a\x80b c");
    assert_eq!(quote(os_str.as_bytes()), &b"'a\x80b c'"[..]);
}

(On Windows, OsStr uses 16 bit wide characters so this will not work.)

Structs§

  • 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.
  • An iterator that takes an input byte string and splits it into the words using the same syntax as the POSIX shell.

Functions§

  • joinDeprecated
    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.
  • quoteDeprecated
    Given a single word, return a string suitable to encode it as a shell argument.
  • Convenience function that consumes the whole byte string at once. Returns None if the input was erroneous.
  • 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.
  • Given a single word, return a string suitable to encode it as a shell argument.