From 43d3834880b3ed01a3361ff2895e5bdaf12b78d1 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 8 Aug 2015 03:53:21 -0400 Subject: [PATCH] Backport and/or replace unstable features. I removed the unstable slice_patterns and str_char features. I also used the deprecated connect() method, instead of join(). --- src/echo/echo.rs | 2 +- src/ln/ln.rs | 21 ++++++++++----------- src/mv/mv.rs | 21 +++++++++++---------- src/nl/helper.rs | 26 +++++++++++++------------- src/nl/nl.rs | 1 - src/users/users.rs | 2 +- src/yes/yes.rs | 2 +- 7 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/echo/echo.rs b/src/echo/echo.rs index 5e3e3f56a..11ba354ef 100644 --- a/src/echo/echo.rs +++ b/src/echo/echo.rs @@ -174,7 +174,7 @@ pub fn uumain(args: Vec) -> i32 { }; if !free.is_empty() { - let string = free.join(" "); + let string = free.connect(" "); if options.escape { let mut prev_was_slash = false; let mut iter = string.chars().enumerate(); diff --git a/src/ln/ln.rs b/src/ln/ln.rs index ac9698def..6a7646e93 100644 --- a/src/ln/ln.rs +++ b/src/ln/ln.rs @@ -1,5 +1,4 @@ #![crate_name = "ln"] -#![feature(slice_patterns, str_char)] /* * This file is part of the uutils coreutils package. @@ -172,33 +171,33 @@ fn exec(files: &[PathBuf], settings: &Settings) -> i32 { Some(ref name) => return link_files_in_dir(files, &PathBuf::from(name), &settings), None => {} } - match files { - [] => { + match files.len() { + 0 => { show_error!("missing file operand\nTry '{} --help' for more information.", NAME); 1 }, - [ref target] => match link(target, target, settings) { + 1 => match link(&files[0], &files[0], settings) { Ok(_) => 0, Err(e) => { show_error!("{}", e); 1 } }, - [ref target, ref linkname] => match link(target, linkname, settings) { + 2 => match link(&files[0], &files[1], settings) { Ok(_) => 0, Err(e) => { show_error!("{}", e); 1 } }, - fs => { + _ => { if settings.no_target_dir { - show_error!("extra operand '{}'\nTry '{} --help' for more information.", fs[2].display(), NAME); + show_error!("extra operand '{}'\nTry '{} --help' for more information.", files[2].display(), NAME); return 1; } let (targets, dir) = match settings.target_dir { - Some(ref dir) => (fs, PathBuf::from(dir.clone())), - None => (&fs[0..fs.len()-1], fs[fs.len()-1].clone()) + Some(ref dir) => (files, PathBuf::from(dir.clone())), + None => (&files[0..files.len()-1], files[files.len()-1].clone()) }; link_files_in_dir(targets, &dir, settings) } @@ -289,8 +288,8 @@ fn link(src: &PathBuf, dst: &PathBuf, settings: &Settings) -> Result<()> { fn read_yes() -> bool { let mut s = String::new(); match BufReader::new(stdin()).read_line(&mut s) { - Ok(_) => match s.slice_shift_char() { - Some((x, _)) => x == 'y' || x == 'Y', + Ok(_) => match s.char_indices().nth(0) { + Some((_, x)) => x == 'y' || x == 'Y', _ => false }, _ => false diff --git a/src/mv/mv.rs b/src/mv/mv.rs index fb7453839..f8317ccd9 100644 --- a/src/mv/mv.rs +++ b/src/mv/mv.rs @@ -1,5 +1,4 @@ #![crate_name = "mv"] -#![feature(slice_patterns, str_char)] /* * This file is part of the uutils coreutils package. @@ -192,13 +191,15 @@ fn exec(files: &[PathBuf], b: Behaviour) -> i32 { Some(ref name) => return move_files_into_dir(files, &PathBuf::from(name), &b), None => {} } - match files { - [] | [_] => { + match files.len() { + 0 | 1 => { show_error!("missing file operand\n\ Try '{} --help' for more information.", NAME); return 1; }, - [ref source, ref target] => { + 2 => { + let ref source = files[0]; + let ref target = files[1]; if !source.uu_exists() { show_error!("cannot stat ‘{}’: No such file or directory", source.display()); return 1; @@ -232,14 +233,14 @@ fn exec(files: &[PathBuf], b: Behaviour) -> i32 { _ => {} } } - fs => { + _ => { if b.no_target_dir { show_error!("mv: extra operand ‘{}’\n\ - Try '{} --help' for more information.", fs[2].display(), NAME); + Try '{} --help' for more information.", files[2].display(), NAME); return 1; } - let target_dir = fs.last().unwrap(); - move_files_into_dir(&fs[0..fs.len()-1], target_dir, &b); + let target_dir = files.last().unwrap(); + move_files_into_dir(&files[0..files.len()-1], target_dir, &b); } } 0 @@ -323,8 +324,8 @@ fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> { fn read_yes() -> bool { let mut s = String::new(); match BufReader::new(stdin()).read_line(&mut s) { - Ok(_) => match s.slice_shift_char() { - Some((x, _)) => x == 'y' || x == 'Y', + Ok(_) => match s.char_indices().nth(0) { + Some((_, x)) => x == 'y' || x == 'Y', _ => false }, _ => false diff --git a/src/nl/helper.rs b/src/nl/helper.rs index acec13470..2cdd5d9f5 100644 --- a/src/nl/helper.rs +++ b/src/nl/helper.rs @@ -3,20 +3,20 @@ extern crate regex; // parse_style parses a style string into a NumberingStyle. fn parse_style(chars: &[char]) -> Result<::NumberingStyle, String> { - match chars { - ['a'] => { Ok(::NumberingStyle::NumberForAll) }, - ['t'] => { Ok(::NumberingStyle::NumberForNonEmpty) }, - ['n'] => { Ok(::NumberingStyle::NumberForNone) }, - ['p', rest..] => { - let s: String = rest.iter().map(|c| *c).collect(); - match regex::Regex::new(&s) { - Ok(re) => Ok(::NumberingStyle::NumberForRegularExpression(re)), - Err(_) => Err(String::from("Illegal regular expression")), - } + if chars.len() == 1 && chars[0] == 'a' { + Ok(::NumberingStyle::NumberForAll) + } else if chars.len() == 1 && chars[0] == 't' { + Ok(::NumberingStyle::NumberForNonEmpty) + } else if chars.len() == 1 && chars[0] == 'n' { + Ok(::NumberingStyle::NumberForNone) + } else if chars.len() > 1 && chars[0] == 'p' { + let s: String = chars[1..].iter().map(|c| *c).collect(); + match regex::Regex::new(&s) { + Ok(re) => Ok(::NumberingStyle::NumberForRegularExpression(re)), + Err(_) => Err(String::from("Illegal regular expression")), } - _ => { - Err(String::from("Illegal style encountered")) - }, + } else { + Err(String::from("Illegal style encountered")) } } diff --git a/src/nl/nl.rs b/src/nl/nl.rs index f1f2fa6b6..5a1eba46c 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -1,5 +1,4 @@ #![crate_name = "nl"] -#![feature(slice_patterns)] /* * This file is part of the uutils coreutils package. diff --git a/src/users/users.rs b/src/users/users.rs index d46092f8b..17aafcf67 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -117,6 +117,6 @@ fn exec(filename: &str) { if users.len() > 0 { users.sort(); - println!("{}", users.join(" ")); + println!("{}", users.connect(" ")); } } diff --git a/src/yes/yes.rs b/src/yes/yes.rs index 52af0f53a..870d61128 100644 --- a/src/yes/yes.rs +++ b/src/yes/yes.rs @@ -50,7 +50,7 @@ pub fn uumain(args: Vec) -> i32 { let string = if matches.free.is_empty() { "y".to_string() } else { - matches.free.join(" ") + matches.free.connect(" ") }; exec(&string[..]);