Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/uu/dir/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ffi::OsString;
use std::path::Path;
use uu_ls::{Config, Format, options};
use uucore::error::UResult;
use uucore::quoting_style::{Quotes, QuotingStyle};
use uucore::quoting_style::QuotingStyle;

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Expand Down Expand Up @@ -45,9 +45,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut config = Config::from(&matches)?;

if default_quoting_style {
config.quoting_style = QuotingStyle::C {
quotes: Quotes::None,
};
config.quoting_style = QuotingStyle::C_NO_QUOTES;
}
if default_format_style {
config.format = Format::Columns;
Expand Down
61 changes: 16 additions & 45 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR};
use uucore::libc::{dev_t, major, minor};
use uucore::line_ending::LineEnding;
use uucore::locale::{get_message, get_message_with_args};
use uucore::quoting_style::{
self, QuotingStyle, locale_aware_escape_dir_name, locale_aware_escape_name,
};
use uucore::quoting_style::{QuotingStyle, locale_aware_escape_dir_name, locale_aware_escape_name};
use uucore::{
display::Quotable,
error::{UError, UResult, set_exit_code},
Expand Down Expand Up @@ -598,34 +596,15 @@ fn extract_hyperlink(options: &clap::ArgMatches) -> bool {
fn match_quoting_style_name(style: &str, show_control: bool) -> Option<QuotingStyle> {
match style {
"literal" => Some(QuotingStyle::Literal { show_control }),
"shell" => Some(QuotingStyle::Shell {
escape: false,
always_quote: false,
show_control,
}),
"shell-always" => Some(QuotingStyle::Shell {
escape: false,
always_quote: true,
show_control,
}),
"shell-escape" => Some(QuotingStyle::Shell {
escape: true,
always_quote: false,
show_control,
}),
"shell-escape-always" => Some(QuotingStyle::Shell {
escape: true,
always_quote: true,
show_control,
}),
"c" => Some(QuotingStyle::C {
quotes: quoting_style::Quotes::Double,
}),
"escape" => Some(QuotingStyle::C {
quotes: quoting_style::Quotes::None,
}),
"shell" => Some(QuotingStyle::SHELL),
"shell-always" => Some(QuotingStyle::SHELL_QUOTE),
"shell-escape" => Some(QuotingStyle::SHELL_ESCAPE),
"shell-escape-always" => Some(QuotingStyle::SHELL_ESCAPE_QUOTE),
"c" => Some(QuotingStyle::C_DOUBLE),
"escape" => Some(QuotingStyle::C_NO_QUOTES),
_ => None,
}
.map(|qs| qs.show_control(show_control))
}

/// Extracts the quoting style to use based on the options provided.
Expand All @@ -651,13 +630,9 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot
} else if options.get_flag(options::quoting::LITERAL) {
QuotingStyle::Literal { show_control }
} else if options.get_flag(options::quoting::ESCAPE) {
QuotingStyle::C {
quotes: quoting_style::Quotes::None,
}
QuotingStyle::C_NO_QUOTES
} else if options.get_flag(options::quoting::C) {
QuotingStyle::C {
quotes: quoting_style::Quotes::Double,
}
QuotingStyle::C_DOUBLE
} else if options.get_flag(options::DIRED) {
QuotingStyle::Literal { show_control }
} else {
Expand All @@ -684,11 +659,7 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot
// By default, `ls` uses Shell escape quoting style when writing to a terminal file
// descriptor and Literal otherwise.
if stdout().is_terminal() {
QuotingStyle::Shell {
escape: true,
always_quote: false,
show_control,
}
QuotingStyle::SHELL_ESCAPE.show_control(show_control)
} else {
QuotingStyle::Literal { show_control }
}
Expand Down Expand Up @@ -2010,7 +1981,7 @@ fn show_dir_name(
config: &Config,
) -> std::io::Result<()> {
let escaped_name =
locale_aware_escape_dir_name(path_data.p_buf.as_os_str(), &config.quoting_style);
locale_aware_escape_dir_name(path_data.p_buf.as_os_str(), config.quoting_style);

let name = if config.hyperlink && !config.dired {
create_hyperlink(&escaped_name, path_data)
Expand Down Expand Up @@ -2511,7 +2482,7 @@ fn display_items(
// option, print the security context to the left of the size column.

let quoted = items.iter().any(|item| {
let name = locale_aware_escape_name(&item.display_name, &config.quoting_style);
let name = locale_aware_escape_name(&item.display_name, config.quoting_style);
os_str_starts_with(&name, b"'")
});

Expand Down Expand Up @@ -3175,7 +3146,7 @@ fn display_item_name(
current_column: LazyCell<usize, Box<dyn FnOnce() -> usize + '_>>,
) -> OsString {
// This is our return value. We start by `&path.display_name` and modify it along the way.
let mut name = locale_aware_escape_name(&path.display_name, &config.quoting_style);
let mut name = locale_aware_escape_name(&path.display_name, config.quoting_style);

let is_wrap =
|namelen: usize| config.width != 0 && *current_column + namelen > config.width.into();
Expand Down Expand Up @@ -3267,7 +3238,7 @@ fn display_item_name(
name.push(path.p_buf.read_link().unwrap());
} else {
name.push(color_name(
locale_aware_escape_name(target.as_os_str(), &config.quoting_style),
locale_aware_escape_name(target.as_os_str(), config.quoting_style),
path,
style_manager,
&mut state.out,
Expand All @@ -3280,7 +3251,7 @@ fn display_item_name(
// Apply the right quoting
name.push(locale_aware_escape_name(
target.as_os_str(),
&config.quoting_style,
config.quoting_style,
));
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/uu/vdir/src/vdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ffi::OsString;
use std::path::Path;
use uu_ls::{Config, Format, options};
use uucore::error::UResult;
use uucore::quoting_style::{Quotes, QuotingStyle};
use uucore::quoting_style::QuotingStyle;

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Expand Down Expand Up @@ -44,9 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut config = Config::from(&matches)?;

if default_quoting_style {
config.quoting_style = QuotingStyle::C {
quotes: Quotes::None,
};
config.quoting_style = QuotingStyle::C_NO_QUOTES;
}
if default_format_style {
config.format = Format::Long;
Expand Down
25 changes: 9 additions & 16 deletions src/uu/wc/src/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@
static ARG_FILES: &str = "files";
static STDIN_REPR: &str = "-";

static QS_ESCAPE: &QuotingStyle = &QuotingStyle::Shell {
escape: true,
always_quote: false,
show_control: false,
};
static QS_QUOTE_ESCAPE: &QuotingStyle = &QuotingStyle::Shell {
escape: true,
always_quote: true,
show_control: false,
};

/// Supported inputs.
#[derive(Debug)]
enum Inputs<'a> {
Expand Down Expand Up @@ -260,7 +249,8 @@
let path = path.as_os_str();
if path.to_string_lossy().contains('\n') {
Some(Cow::Owned(quoting_style::locale_aware_escape_name(
path, QS_ESCAPE,
path,
QuotingStyle::SHELL_ESCAPE,
)))
} else {
Some(Cow::Borrowed(path))
Expand Down Expand Up @@ -761,9 +751,12 @@
"wc-error-cannot-open-for-reading",
HashMap::from([(
"path".to_string(),
quoting_style::locale_aware_escape_name(path.as_os_str(), QS_QUOTE_ESCAPE)
.into_string()
.expect("All escaped names with the escaping option return valid strings."),
quoting_style::locale_aware_escape_name(
path.as_os_str(),
QuotingStyle::SHELL_ESCAPE_QUOTE,
)
.into_string()
.expect("All escaped names with the escaping option return valid strings."),

Check warning on line 759 in src/uu/wc/src/wc.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/wc/src/wc.rs#L754-L759

Added lines #L754 - L759 were not covered by tests
)]),
)
})),
Expand Down Expand Up @@ -814,7 +807,7 @@
}

fn escape_name_wrapper(name: &OsStr) -> String {
quoting_style::locale_aware_escape_name(name, QS_ESCAPE)
quoting_style::locale_aware_escape_name(name, QuotingStyle::SHELL_ESCAPE)
.into_string()
.expect("All escaped names with the escaping option return valid strings.")
}
Expand Down
9 changes: 2 additions & 7 deletions src/uucore/src/lib/features/format/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::format::spec::ArgumentLocation;
use crate::{
error::set_exit_code,
parser::num_parser::{ExtendedParser, ExtendedParserError},
quoting_style::{Quotes, QuotingStyle, locale_aware_escape_name},
quoting_style::{QuotingStyle, locale_aware_escape_name},
show_error, show_warning,
};
use os_display::Quotable;
Expand Down Expand Up @@ -153,12 +153,7 @@ fn extract_value<T: Default>(p: Result<T, ExtendedParserError<'_, T>>, input: &s
Ok(v) => v,
Err(e) => {
set_exit_code(1);
let input = locale_aware_escape_name(
OsStr::new(input),
&QuotingStyle::C {
quotes: Quotes::None,
},
);
let input = locale_aware_escape_name(OsStr::new(input), QuotingStyle::C_NO_QUOTES);
match e {
ExtendedParserError::Overflow(v) => {
show_error!("{}: Numerical result out of range", input.quote());
Expand Down
6 changes: 1 addition & 5 deletions src/uucore/src/lib/features/format/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,7 @@ impl Spec {
Self::QuotedString { position } => {
let s = locale_aware_escape_name(
args.next_string(position).as_ref(),
&QuotingStyle::Shell {
escape: true,
always_quote: false,
show_control: false,
},
QuotingStyle::SHELL_ESCAPE,
);
#[cfg(unix)]
let bytes = std::os::unix::ffi::OsStringExt::into_vec(s);
Expand Down
Loading
Loading