mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
numfmt: allow ' ' as field separator
This commit is contained in:
parent
614c367e46
commit
2d4810b91b
3 changed files with 8 additions and 3 deletions
|
@ -160,7 +160,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
|
||||||
|
|
||||||
let fields = args.get_one::<String>(options::FIELD).unwrap().as_str();
|
let fields = args.get_one::<String>(options::FIELD).unwrap().as_str();
|
||||||
// a lone "-" means "all fields", even as part of a list of fields
|
// a lone "-" means "all fields", even as part of a list of fields
|
||||||
let fields = if fields.split(',').any(|x| x == "-") {
|
let fields = if fields.split(&[',', ' ']).any(|x| x == "-") {
|
||||||
vec![Range {
|
vec![Range {
|
||||||
low: 1,
|
low: 1,
|
||||||
high: std::usize::MAX,
|
high: std::usize::MAX,
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl Range {
|
||||||
pub fn from_list(list: &str) -> Result<Vec<Self>, String> {
|
pub fn from_list(list: &str) -> Result<Vec<Self>, String> {
|
||||||
let mut ranges = Vec::new();
|
let mut ranges = Vec::new();
|
||||||
|
|
||||||
for item in list.split(',') {
|
for item in list.split(&[',', ' ']) {
|
||||||
let range_item = FromStr::from_str(item)
|
let range_item = FromStr::from_str(item)
|
||||||
.map_err(|e| format!("range {} was invalid: {}", item.quote(), e))?;
|
.map_err(|e| format!("range {} was invalid: {}", item.quote(), e))?;
|
||||||
ranges.push(range_item);
|
ranges.push(range_item);
|
||||||
|
|
|
@ -373,6 +373,11 @@ fn test_format_selected_fields() {
|
||||||
.args(&["--from=auto", "--field", "1,4,3", "1K 2K 3K 4K 5K 6K"])
|
.args(&["--from=auto", "--field", "1,4,3", "1K 2K 3K 4K 5K 6K"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("1000 2K 3000 4000 5K 6K\n");
|
.stdout_only("1000 2K 3000 4000 5K 6K\n");
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["--from=auto", "--field", "1,4 3", "1K 2K 3K 4K 5K 6K"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("1000 2K 3000 4000 5K 6K\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -401,7 +406,7 @@ fn test_format_selected_field_range() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_format_all_fields() {
|
fn test_format_all_fields() {
|
||||||
let all_fields_patterns = vec!["-", "-,3", "3,-", "1,-,3"];
|
let all_fields_patterns = vec!["-", "-,3", "3,-", "1,-,3", "- 3"];
|
||||||
|
|
||||||
for pattern in all_fields_patterns {
|
for pattern in all_fields_patterns {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue