pub struct Quoted<'a> { /* private fields */ }Expand description
A wrapper around string types for displaying with quoting and escaping applied.
Implementations§
Source§impl<'a> Quoted<'a>
impl<'a> Quoted<'a>
Sourcepub fn native(text: &'a str) -> Self
pub fn native(text: &'a str) -> Self
Quote a string with the default style for the platform.
On Windows this is PowerShell syntax, on all other platforms this is bash/ksh syntax.
Sourcepub fn native_raw(text: &'a OsStr) -> Self
pub fn native_raw(text: &'a OsStr) -> Self
Quote an OsStr with the default style for the platform.
On platforms other than Windows and Unix, if the encoding is
invalid, the Debug representation will be used.
Sourcepub fn unix_raw(bytes: &'a [u8]) -> Self
pub fn unix_raw(bytes: &'a [u8]) -> Self
Quote possibly invalid UTF-8 using bash/ksh syntax.
§Optional
This requires the optional unix feature.
Sourcepub fn windows(text: &'a str) -> Self
pub fn windows(text: &'a str) -> Self
Examples found in repository?
3fn main() {
4 for arg in std::env::args_os().skip(1) {
5 println!("Native: {}", arg.maybe_quote());
6 #[cfg(all(windows, feature = "unix"))]
7 {
8 if let Some(arg) = arg.to_str() {
9 println!("Unix: {}", os_display::Quoted::unix(arg).force(false));
10 }
11 }
12 #[cfg(all(not(windows), feature = "windows"))]
13 {
14 if let Some(arg) = arg.to_str() {
15 println!("Windows: {}", os_display::Quoted::windows(arg).force(false));
16 }
17 }
18 }
19}Sourcepub fn windows_raw(units: &'a [u16]) -> Self
pub fn windows_raw(units: &'a [u16]) -> Self
Quote possibly invalid UTF-16 using PowerShell syntax.
§Optional
This requires the optional windows feature and the (default) alloc feature.
Sourcepub fn force(self, force: bool) -> Self
pub fn force(self, force: bool) -> Self
Toggle forced quoting. If true, quotes are added even if no special
characters are present.
Defaults to true.
Examples found in repository?
3fn main() {
4 for arg in std::env::args_os().skip(1) {
5 println!("Native: {}", arg.maybe_quote());
6 #[cfg(all(windows, feature = "unix"))]
7 {
8 if let Some(arg) = arg.to_str() {
9 println!("Unix: {}", os_display::Quoted::unix(arg).force(false));
10 }
11 }
12 #[cfg(all(not(windows), feature = "windows"))]
13 {
14 if let Some(arg) = arg.to_str() {
15 println!("Windows: {}", os_display::Quoted::windows(arg).force(false));
16 }
17 }
18 }
19}Sourcepub fn external(self, external: bool) -> Self
pub fn external(self, external: bool) -> Self
When quoting for PowerShell, toggle whether to use legacy quoting for external programs.
If enabled, double quotes (and sometimes backslashes) will be escaped so
that they can be passed to external programs in PowerShell versions before
7.3, or with $PSNativeCommandArgumentPassing set to 'Legacy'.
If disabled, quoting will suit modern argument passing (always used for internal commandlets and .NET functions). Strings that look like options or numbers will be quoted.
It is sadly impossible to quote a string such that it’s suitable for both modern and legacy argument passing.
Defaults to false.
§Optional
This requires either the windows or the native feature. It has no effect
on Unix-style quoting.