1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Merge pull request #504 from ebfe/slice

Replace deprecated slice_{to,from} with slicing syntax
This commit is contained in:
Heather 2015-01-24 18:47:46 +03:00
commit 6c897dc76c
27 changed files with 84 additions and 87 deletions

View file

@ -15,7 +15,7 @@ fn main() {
let mut crates = String::new(); let mut crates = String::new();
let mut util_map = String::new(); let mut util_map = String::new();
let mut hashsum = false; let mut hashsum = false;
for prog in args.slice_from(2).iter() { for prog in args[2..].iter() {
match prog.as_slice() { match prog.as_slice() {
"hashsum" | "md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => { "hashsum" | "md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => {
if !hashsum { if !hashsum {

View file

@ -105,7 +105,7 @@ fn strip_suffix(name: &str, suffix: &str) -> String {
} }
if name.ends_with(suffix) { if name.ends_with(suffix) {
return name.slice_to(name.len() - suffix.len()).to_owned(); return name[..name.len() - suffix.len()].to_owned();
} }
name.to_owned() name.to_owned()

View file

@ -110,7 +110,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
Ok(n) if n != 0 => n, Ok(n) if n != 0 => n,
_ => break, _ => break,
}; };
let in_buf = in_buf.slice_to(n); let in_buf = &in_buf[..n];
let mut buf_pos = range(0, n); let mut buf_pos = range(0, n);
loop { loop {
writer.possibly_flush(); writer.possibly_flush();
@ -139,9 +139,9 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
(write!(&mut writer, "{0:6}\t", line_counter)).unwrap(); (write!(&mut writer, "{0:6}\t", line_counter)).unwrap();
line_counter += 1; line_counter += 1;
} }
match in_buf.slice_from(pos).iter().position(|c| *c == '\n' as u8) { match in_buf[pos..].iter().position(|c| *c == '\n' as u8) {
Some(p) => { Some(p) => {
writer.write(in_buf.slice(pos, pos + p)).unwrap(); writer.write(&in_buf[pos..pos + p]).unwrap();
if show_ends { if show_ends {
writer.write_u8('$' as u8).unwrap(); writer.write_u8('$' as u8).unwrap();
} }
@ -153,7 +153,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
at_line_start = true; at_line_start = true;
}, },
None => { None => {
writer.write(in_buf.slice_from(pos)).unwrap(); writer.write(&in_buf[pos..]).unwrap();
at_line_start = false; at_line_start = false;
break; break;
} }
@ -186,7 +186,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
Ok(n) if n != 0 => n, Ok(n) if n != 0 => n,
_ => break, _ => break,
}; };
for &byte in in_buf.slice_to(n).iter() { for &byte in in_buf[..n].iter() {
if flush_counter.next().is_none() { if flush_counter.next().is_none() {
writer.possibly_flush(); writer.possibly_flush();
flush_counter = range(0us, 1024); flush_counter = range(0us, 1024);
@ -256,7 +256,7 @@ fn write_fast(files: Vec<String>) {
match reader.read(&mut in_buf) { match reader.read(&mut in_buf) {
Ok(n) if n != 0 => { Ok(n) if n != 0 => {
// This interface is completely broken. // This interface is completely broken.
writer.write(in_buf.slice_to(n)).unwrap(); writer.write(&in_buf[..n]).unwrap();
}, },
_ => break _ => break
} }
@ -312,7 +312,7 @@ impl<'a, W: Writer> UnsafeWriter<'a, W> {
fn flush_buf(&mut self) -> IoResult<()> { fn flush_buf(&mut self) -> IoResult<()> {
if self.pos != 0 { if self.pos != 0 {
let ret = self.inner.write(self.buf.slice_to(self.pos)); let ret = self.inner.write(&self.buf[..self.pos]);
self.pos = 0; self.pos = 0;
ret ret
} else { } else {
@ -322,7 +322,7 @@ impl<'a, W: Writer> UnsafeWriter<'a, W> {
fn possibly_flush(&mut self) { fn possibly_flush(&mut self) {
if self.pos > self.threshold { if self.pos > self.threshold {
self.inner.write(self.buf.slice_to(self.pos)).unwrap(); self.inner.write(&self.buf[..self.pos]).unwrap();
self.pos = 0; self.pos = 0;
} }
} }
@ -335,7 +335,7 @@ fn fail() -> ! {
impl<'a, W: Writer> Writer for UnsafeWriter<'a, W> { impl<'a, W: Writer> Writer for UnsafeWriter<'a, W> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write(&mut self, buf: &[u8]) -> IoResult<()> {
let dst = self.buf.slice_from_mut(self.pos); let dst = &mut self.buf[self.pos..];
if buf.len() > dst.len() { if buf.len() > dst.len() {
fail(); fail();
} }

View file

@ -219,7 +219,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
let mut rwx = 0; let mut rwx = 0;
let mut special = 0; let mut special = 0;
let mut special_changed = false; let mut special_changed = false;
for ch in change.slice_from(1).chars() { for ch in change[1..].chars() {
match ch { match ch {
'+' | '-' | '=' => { '+' | '-' | '=' => {
for level in levels.chars() { for level in levels.chars() {
@ -277,7 +277,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
let change = cap.at(4).unwrap(); let change = cap.at(4).unwrap();
let ch = change.char_at(0); let ch = change.char_at(0);
let (action, slice) = match ch { let (action, slice) = match ch {
'+' | '-' | '=' => (ch, change.slice_from(1)), '+' | '-' | '=' => (ch, &change[1..]),
_ => ('=', change) _ => ('=', change)
}; };
let mode = from_str_radix::<u32>(slice, 8).unwrap() as libc::mode_t; // already verified let mode = from_str_radix::<u32>(slice, 8).unwrap() as libc::mode_t; // already verified

View file

@ -89,7 +89,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}; };
vec!(shell, default_option) vec!(shell, default_option)
} }
_ => opts.free.slice(1, opts.free.len()).iter().map(|x| x.as_slice()).collect() _ => opts.free[1..opts.free.len()].iter().map(|x| x.as_slice()).collect()
}; };
set_context(&newroot, &opts); set_context(&newroot, &opts);

View file

@ -64,7 +64,7 @@ fn cksum(fname: &str) -> IoResult<(u32, usize)> {
loop { loop {
match rd.read(&mut bytes) { match rd.read(&mut bytes) {
Ok(num_bytes) => { Ok(num_bytes) => {
for &b in bytes.slice_to(num_bytes).iter() { for &b in bytes[..num_bytes].iter() {
crc = crc_update(crc, b); crc = crc_update(crc, b);
} }
size += num_bytes; size += num_bytes;

View file

@ -12,7 +12,7 @@ pub fn from_str(string: &str) -> Result<f64, String> {
if len == 0 { if len == 0 {
return Err("empty string".to_string()) return Err("empty string".to_string())
} }
let slice = string.slice_to(len - 1); let slice = &string[..len - 1];
let (numstr, times) = match string.char_at(len - 1) { let (numstr, times) = match string.char_at(len - 1) {
's' | 'S' => (slice, 1us), 's' | 'S' => (slice, 1us),
'm' | 'M' => (slice, 60us), 'm' | 'M' => (slice, 60us),

View file

@ -83,7 +83,7 @@ fn copy(matches: getopts::Matches) {
panic!() panic!()
} else { } else {
// All but the last argument: // All but the last argument:
matches.free.slice(0, matches.free.len() - 1).iter() matches.free[..matches.free.len() - 1].iter()
.map(|arg| Path::new(arg.clone())).collect() .map(|arg| Path::new(arg.clone())).collect()
}; };
let dest = if matches.free.len() < 2 { let dest = if matches.free.len() < 2 {

View file

@ -38,7 +38,7 @@ impl<R: Reader> BufReader<R> {
#[inline] #[inline]
fn read(&mut self) -> IoResult<usize> { fn read(&mut self) -> IoResult<usize> {
let buffer_fill = self.buffer.slice_from_mut(self.end); let buffer_fill = &mut self.buffer[self.end..];
match self.reader.read(buffer_fill) { match self.reader.read(buffer_fill) {
Ok(nread) => { Ok(nread) => {
@ -72,7 +72,7 @@ impl<R: Reader> BufReader<R> {
_ => () _ => ()
} }
let filled_buf = self.buffer.slice(self.start, self.end); let filled_buf = &self.buffer[self.start..self.end];
match filled_buf.position_elem(&b'\n') { match filled_buf.position_elem(&b'\n') {
Some(idx) => { Some(idx) => {
@ -103,14 +103,12 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
buf_used if bytes < buf_used => { buf_used if bytes < buf_used => {
// because the output delimiter should only be placed between // because the output delimiter should only be placed between
// segments check if the byte after bytes is a newline // segments check if the byte after bytes is a newline
let buf_slice = self.buffer.slice(self.start, let buf_slice = &self.buffer[self.start..self.start + bytes + 1];
self.start + bytes + 1);
match buf_slice.position_elem(&b'\n') { match buf_slice.position_elem(&b'\n') {
Some(idx) => idx, Some(idx) => idx,
None => { None => {
let segment = self.buffer.slice(self.start, let segment = &self.buffer[self.start..self.start + bytes];
self.start + bytes);
self.start += bytes; self.start += bytes;
@ -119,12 +117,12 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
} }
} }
_ => { _ => {
let buf_filled = self.buffer.slice(self.start, self.end); let buf_filled = &self.buffer[self.start..self.end];
match buf_filled.position_elem(&b'\n') { match buf_filled.position_elem(&b'\n') {
Some(idx) => idx, Some(idx) => idx,
None => { None => {
let segment = self.buffer.slice(self.start, self.end); let segment = &self.buffer[self.start..self.end];
self.start = 0; self.start = 0;
self.end = 0; self.end = 0;
@ -136,7 +134,7 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
}; };
let new_start = self.start + newline_idx + 1; let new_start = self.start + newline_idx + 1;
let segment = self.buffer.slice(self.start, new_start); let segment = &self.buffer[self.start..new_start];
self.start = new_start; self.start = new_start;
Bytes::Selected::NewlineFound(segment) Bytes::Selected::NewlineFound(segment)

View file

@ -168,13 +168,13 @@ fn cut_characters<R: Reader>(reader: R,
match char_indices.nth(high - low) { match char_indices.nth(high - low) {
Some((high_idx, _)) => { Some((high_idx, _)) => {
let segment = line.as_bytes().slice(low_idx, high_idx); let segment = &line.as_bytes()[low_idx..high_idx];
out.write(segment).unwrap(); out.write(segment).unwrap();
} }
None => { None => {
let bytes = line.as_bytes(); let bytes = line.as_bytes();
let segment = bytes.slice(low_idx, bytes.len()); let segment = &bytes[low_idx..];
out.write(segment).unwrap(); out.write(segment).unwrap();
@ -226,8 +226,7 @@ impl<'a> Iterator for Searcher<'a> {
} }
while self.position + self.needle.len() <= self.haystack.len() { while self.position + self.needle.len() <= self.haystack.len() {
if self.haystack.slice(self.position, if &self.haystack[self.position..self.position + self.needle.len()] == self.needle {
self.position + self.needle.len()) == self.needle {
let match_pos = self.position; let match_pos = self.position;
self.position += self.needle.len(); self.position += self.needle.len();
return Some((match_pos, match_pos + self.needle.len())); return Some((match_pos, match_pos + self.needle.len()));
@ -286,7 +285,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
match delim_search.next() { match delim_search.next() {
Some((high_idx, next_low_idx)) => { Some((high_idx, next_low_idx)) => {
let segment = line.slice(low_idx, high_idx); let segment = &line[low_idx..high_idx];
out.write(segment).unwrap(); out.write(segment).unwrap();
@ -296,7 +295,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
fields_pos = high + 1; fields_pos = high + 1;
} }
None => { None => {
let segment = line.slice(low_idx, line.len()); let segment = &line[low_idx..];
out.write(segment).unwrap(); out.write(segment).unwrap();
@ -369,7 +368,7 @@ fn cut_fields<R: Reader>(reader: R,
match delim_search.nth(high - low) { match delim_search.nth(high - low) {
Some((high_idx, next_low_idx)) => { Some((high_idx, next_low_idx)) => {
let segment = line.slice(low_idx, high_idx); let segment = &line[low_idx..high_idx];
out.write(segment).unwrap(); out.write(segment).unwrap();
@ -378,7 +377,7 @@ fn cut_fields<R: Reader>(reader: R,
fields_pos = high + 1; fields_pos = high + 1;
} }
None => { None => {
let segment = line.slice(low_idx, line.len()); let segment = &line[low_idx..line.len()];
out.write(segment).unwrap(); out.write(segment).unwrap();

2
src/env/env.rs vendored
View file

@ -194,7 +194,7 @@ pub fn uumain(args: Vec<String>) -> isize {
if opts.program.len() >= 1 { if opts.program.len() >= 1 {
use std::io::process::{Command, InheritFd}; use std::io::process::{Command, InheritFd};
let prog = opts.program[0].clone(); let prog = opts.program[0].clone();
let args = opts.program.slice_from(1); let args = &opts.program[1..];
match Command::new(prog).args(args).stdin(InheritFd(0)).stdout(InheritFd(1)).stderr(InheritFd(2)).status() { match Command::new(prog).args(args).stdin(InheritFd(0)).stdout(InheritFd(1)).stderr(InheritFd(2)).status() {
Ok(exit) => Ok(exit) =>
return match exit { return match exit {

View file

@ -108,7 +108,7 @@ fn accum_words_simple<'a>(args: &mut BreakArgs<'a>, (l, prev_punct): (usize, boo
if l + wlen + slen > args.opts.width { if l + wlen + slen > args.opts.width {
write_newline(args.indent_str, args.ostream); write_newline(args.indent_str, args.ostream);
write_with_spaces(winfo.word.slice_from(winfo.word_start), 0, args.ostream); write_with_spaces(&winfo.word[winfo.word_start..], 0, args.ostream);
(args.indent_len + winfo.word_nchars, winfo.ends_punct) (args.indent_len + winfo.word_nchars, winfo.ends_punct)
} else { } else {
write_with_spaces(winfo.word, slen, args.ostream); write_with_spaces(winfo.word, slen, args.ostream);
@ -145,7 +145,7 @@ fn break_knuth_plass<'a, T: Clone + Iterator<Item=&'a WordInfo<'a>>>(mut iter: T
// OK, we found the matching word // OK, we found the matching word
if break_before { if break_before {
write_newline(args.indent_str, args.ostream); write_newline(args.indent_str, args.ostream);
write_with_spaces(winfo.word.slice_from(winfo.word_start), 0, args.ostream); write_with_spaces(&winfo.word[winfo.word_start..], 0, args.ostream);
} else { } else {
// breaking after this word, so that means "fresh" is true for the next iteration // breaking after this word, so that means "fresh" is true for the next iteration
write_with_spaces(word, slen, args.ostream); write_with_spaces(word, slen, args.ostream);
@ -427,7 +427,7 @@ fn compute_slen(uniform: bool, newline: bool, start: bool, punct: bool) -> usize
#[inline(always)] #[inline(always)]
fn slice_if_fresh<'a>(fresh: bool, word: &'a str, start: usize, uniform: bool, newline: bool, sstart: bool, punct: bool) -> (usize, &'a str) { fn slice_if_fresh<'a>(fresh: bool, word: &'a str, start: usize, uniform: bool, newline: bool, sstart: bool, punct: bool) -> (usize, &'a str) {
if fresh { if fresh {
(0, word.slice_from(start)) (0, &word[start..])
} else { } else {
(compute_slen(uniform, newline, sstart, punct), word) (compute_slen(uniform, newline, sstart, punct), word)
} }

View file

@ -104,7 +104,7 @@ impl<'a> FileLines<'a> {
let mut i = 0; let mut i = 0;
while (i < line.len()) && line.char_at(i).is_whitespace() { while (i < line.len()) && line.char_at(i).is_whitespace() {
i = match line.char_range_at(i) { CharRange { ch: _ , next: nxi } => nxi }; i = match line.char_range_at(i) { CharRange { ch: _ , next: nxi } => nxi };
if line.slice_from(i).starts_with(pfx) { if line[i..].starts_with(pfx) {
return (true, i); return (true, i);
} }
} }
@ -165,7 +165,7 @@ impl<'a> Iterator for FileLines<'a> {
let (pmatch, poffset) = self.match_prefix(n.as_slice()); let (pmatch, poffset) = self.match_prefix(n.as_slice());
if !pmatch { if !pmatch {
return Some(Line::NoFormatLine(n, false)); return Some(Line::NoFormatLine(n, false));
} else if n.as_slice().slice_from(poffset + self.opts.prefix.len()).is_whitespace() { } else if n.as_slice()[poffset + self.opts.prefix.len()..].is_whitespace() {
// if the line matches the prefix, but is blank after, // if the line matches the prefix, but is blank after,
// don't allow lines to be combined through it (that is, // don't allow lines to be combined through it (that is,
// treat it like a blank line, except that since it's // treat it like a blank line, except that since it's
@ -246,7 +246,7 @@ impl<'a> ParagraphStream<'a> {
// header field must be nonzero length // header field must be nonzero length
if colon_posn == 0 { return false; } if colon_posn == 0 { return false; }
return l_slice.slice_to(colon_posn).chars().all(|x| match x as usize { return l_slice[..colon_posn].chars().all(|x| match x as usize {
y if y < 33 || y > 126 => false, y if y < 33 || y > 126 => false,
_ => true _ => true
}); });
@ -314,7 +314,7 @@ impl<'a> Iterator for ParagraphStream<'a> {
indent_len = 2; indent_len = 2;
} else { } else {
if self.opts.crown || self.opts.tagged { if self.opts.crown || self.opts.tagged {
init_str.push_str(fl.line.as_slice().slice_to(fl.indent_end)); init_str.push_str(&fl.line.as_slice()[..fl.indent_end]);
init_len = fl.indent_len; init_len = fl.indent_len;
init_end = fl.indent_end; init_end = fl.indent_end;
} else { } else {
@ -324,7 +324,7 @@ impl<'a> Iterator for ParagraphStream<'a> {
// these will be overwritten in the 2nd line of crown or tagged mode, but // these will be overwritten in the 2nd line of crown or tagged mode, but
// we are not guaranteed to get to the 2nd line, e.g., if the next line // we are not guaranteed to get to the 2nd line, e.g., if the next line
// is a NoFormatLine or None. Thus, we set sane defaults the 1st time around // is a NoFormatLine or None. Thus, we set sane defaults the 1st time around
indent_str.push_str(fl.line.as_slice().slice_to(fl.indent_end)); indent_str.push_str(&fl.line.as_slice()[..fl.indent_end]);
indent_len = fl.indent_len; indent_len = fl.indent_len;
indent_end = fl.indent_end; indent_end = fl.indent_end;
@ -358,7 +358,7 @@ impl<'a> Iterator for ParagraphStream<'a> {
} else { } else {
// this is part of the same paragraph, get the indent info from this line // this is part of the same paragraph, get the indent info from this line
indent_str.clear(); indent_str.clear();
indent_str.push_str(fl.line.as_slice().slice_to(fl.indent_end)); indent_str.push_str(&fl.line.as_slice()[..fl.indent_end]);
indent_len = fl.indent_len; indent_len = fl.indent_len;
indent_end = fl.indent_end; indent_end = fl.indent_end;
} }
@ -430,17 +430,17 @@ impl<'a> ParaWords<'a> {
self.words.extend( self.words.extend(
if self.opts.crown || self.opts.tagged { if self.opts.crown || self.opts.tagged {
// crown and tagged mode has the "init" in the first line, so slice from there // crown and tagged mode has the "init" in the first line, so slice from there
WordSplit::new(self.opts, self.para.lines[0].as_slice().slice_from(self.para.init_end)) WordSplit::new(self.opts, &self.para.lines[0].as_slice()[self.para.init_end..])
} else { } else {
// otherwise we slice from the indent // otherwise we slice from the indent
WordSplit::new(self.opts, self.para.lines[0].as_slice().slice_from(self.para.indent_end)) WordSplit::new(self.opts, &self.para.lines[0].as_slice()[self.para.indent_end..])
}); });
if self.para.lines.len() > 1 { if self.para.lines.len() > 1 {
let indent_end = self.para.indent_end; let indent_end = self.para.indent_end;
let opts = self.opts; let opts = self.opts;
self.words.extend( self.words.extend(
self.para.lines.iter().skip(1).flat_map(|x| WordSplit::new(opts, x.as_slice().slice_from(indent_end)))); self.para.lines.iter().skip(1).flat_map(|x| WordSplit::new(opts, &x.as_slice()[indent_end..])));
} }
} }
} }
@ -521,7 +521,7 @@ impl<'a> Iterator for WordSplit<'a> {
let new_line = old_position == 0; let new_line = old_position == 0;
// find the start of the next word, and record if we find a tab character // find the start of the next word, and record if we find a tab character
let (before_tab, after_tab, word_start) = match self.analyze_tabs(self.string.slice_from(old_position)) { let (before_tab, after_tab, word_start) = match self.analyze_tabs(&self.string[old_position..]) {
(b, a, Some(s)) => (b, a, s + old_position), (b, a, Some(s)) => (b, a, s + old_position),
(_, _, None) => { (_, _, None) => {
self.position = self.length; self.position = self.length;
@ -534,7 +534,7 @@ impl<'a> Iterator for WordSplit<'a> {
// points to whitespace character OR end of string // points to whitespace character OR end of string
let mut word_nchars = 0; let mut word_nchars = 0;
self.position = self.position =
match self.string.slice_from(word_start) match self.string[word_start..]
.find(|&mut: x: char| if !x.is_whitespace() { word_nchars += char_width(x); false } else { true }) { .find(|&mut: x: char| if !x.is_whitespace() { word_nchars += char_width(x); false } else { true }) {
None => self.length, None => self.length,
Some(s) => s + word_start Some(s) => s + word_start
@ -551,9 +551,9 @@ impl<'a> Iterator for WordSplit<'a> {
let (word, word_start_relative, before_tab, after_tab) = let (word, word_start_relative, before_tab, after_tab) =
if self.opts.uniform { if self.opts.uniform {
(self.string.slice(word_start, self.position), 0, None, 0) (&self.string[word_start..self.position], 0, None, 0)
} else { } else {
(self.string.slice(old_position, self.position), word_start_relative, before_tab, after_tab) (&self.string[old_position..self.position], word_start_relative, before_tab, after_tab)
}; };
Some(WordInfo { Some(WordInfo {

View file

@ -84,8 +84,8 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
for (i, arg) in args.iter().enumerate() { for (i, arg) in args.iter().enumerate() {
let slice = arg.as_slice(); let slice = arg.as_slice();
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) { if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) {
return (args.slice_to(i).to_vec() + args.slice_from(i + 1), return (args[..i].to_vec() + &args[i + 1..],
Some(slice.slice_from(1).to_string())); Some(slice[1..].to_string()));
} }
} }
(args.to_vec(), None) (args.to_vec(), None)
@ -122,10 +122,10 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
while i < len { while i < len {
let width = if len - i >= width { width } else { len - i }; let width = if len - i >= width { width } else { len - i };
let slice = { let slice = {
let slice = line.slice(i, i + width); let slice = &line[i..i + width];
if spaces && i + width < len { if spaces && i + width < len {
match slice.rfind(|&: ch: char| ch.is_whitespace()) { match slice.rfind(|&: ch: char| ch.is_whitespace()) {
Some(m) => slice.slice_to(m + 1), Some(m) => &slice[..m + 1],
None => slice None => slice
} }
} else { } else {
@ -143,7 +143,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
println!(""); println!("");
continue; continue;
} }
line = line.slice_to(line.len() - 1); line = &line[..line.len() - 1];
len -= 1; len -= 1;
} }
let mut output = String::new(); let mut output = String::new();

View file

@ -302,7 +302,7 @@ fn digest_reader(digest: &mut Box<Digest>, reader: &mut Reader, binary: bool) ->
digest.input(vec.as_slice()); digest.input(vec.as_slice());
vec.clear(); vec.clear();
} else { } else {
digest.input(buffer.slice(0, nread)); digest.input(&buffer[..nread]);
} }
}, },
Err(e) => match e.kind { Err(e) => match e.kind {

View file

@ -151,7 +151,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
// If this is the last number // If this is the last number
if pos == len - 1 { if pos == len - 1 {
options.remove(a); options.remove(a);
let number: Option<usize> = from_utf8(current.slice(1,len)).unwrap().parse::<usize>(); let number: Option<usize> = from_utf8(&current[1..len]).unwrap().parse::<usize>();
return (options, Some(number.unwrap())); return (options, Some(number.unwrap()));
} }
} }

View file

@ -145,7 +145,7 @@ fn xgethostname() -> String {
let last_char = name.iter().position(|byte| *byte == 0).unwrap_or(namelen); let last_char = name.iter().position(|byte| *byte == 0).unwrap_or(namelen);
str::from_utf8(name.slice_to(last_char)).unwrap().to_string() str::from_utf8(&name[..last_char]).unwrap().to_string()
} }
#[cfg(any(target_os = "macos", target_os = "freebsd"))] #[cfg(any(target_os = "macos", target_os = "freebsd"))]

View file

@ -107,7 +107,7 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
// this is safe because slice is valid when it is referenced // this is safe because slice is valid when it is referenced
let slice: &str = unsafe { std::mem::transmute(args[i].as_slice()) }; let slice: &str = unsafe { std::mem::transmute(args[i].as_slice()) };
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) { if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) {
let val = slice.slice_from(1); let val = &slice[1..];
match val.parse() { match val.parse() {
Some(num) => { Some(num) => {
if signals::is_signal(num) { if signals::is_signal(num) {

View file

@ -99,7 +99,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
eof_count += 1; eof_count += 1;
} else { } else {
match file.read_line() { match file.read_line() {
Ok(line) => output.push_str(line.as_slice().slice_to(line.len() - 1)), Ok(line) => output.push_str(&line.as_slice()[..line.len() - 1]),
Err(f) => if f.kind == io::EndOfFile { Err(f) => if f.kind == io::EndOfFile {
eof[i] = true; eof[i] = true;
eof_count += 1; eof_count += 1;

View file

@ -24,7 +24,7 @@ struct SeqOptions {
fn parse_float(mut s: &str) -> Result<f64, String> { fn parse_float(mut s: &str) -> Result<f64, String> {
if s.starts_with("+") { if s.starts_with("+") {
s = s.slice_from(1); s = &s[1..];
} }
match s.parse() { match s.parse() {
Some(n) => Ok(n), Some(n) => Ok(n),

View file

@ -204,7 +204,7 @@ impl Splitter for ByteSplitter {
self.bytes_to_write = self.saved_bytes_to_write; self.bytes_to_write = self.saved_bytes_to_write;
control.request_new_file = true; control.request_new_file = true;
self.require_whole_line = false; self.require_whole_line = false;
return line.as_slice().slice(0, 0).to_string(); return line.as_slice()[0..0].to_string();
} }
self.bytes_to_write -= n; self.bytes_to_write -= n;
if n == 0 { if n == 0 {
@ -214,7 +214,7 @@ impl Splitter for ByteSplitter {
if self.break_on_line_end && n == line.as_slice().chars().count() { if self.break_on_line_end && n == line.as_slice().chars().count() {
self.require_whole_line = self.break_on_line_end; self.require_whole_line = self.break_on_line_end;
} }
line.as_slice().slice(0, n).to_string() line.as_slice()[..n].to_string()
} }
} }
@ -308,7 +308,7 @@ fn split(settings: &Settings) -> isize {
let advance = consumed.as_slice().chars().count(); let advance = consumed.as_slice().chars().count();
let clone = control.current_line.clone(); let clone = control.current_line.clone();
let sl = clone.as_slice(); let sl = clone.as_slice();
control.current_line = sl.slice(advance, sl.chars().count()).to_string(); control.current_line = sl[advance..sl.chars().count()].to_string();
} }
0 0
} }

View file

@ -31,7 +31,7 @@ fn bsd_sum(mut reader: Box<Reader>) -> (usize, u16) {
match reader.read(&mut buf) { match reader.read(&mut buf) {
Ok(n) if n != 0 => { Ok(n) if n != 0 => {
blocks_read += 1; blocks_read += 1;
for &byte in buf.slice_to(n).iter() { for &byte in buf[..n].iter() {
checksum = (checksum >> 1) + ((checksum & 1) << 15); checksum = (checksum >> 1) + ((checksum & 1) << 15);
checksum += byte as u16; checksum += byte as u16;
} }
@ -52,7 +52,7 @@ fn sysv_sum(mut reader: Box<Reader>) -> (usize, u16) {
match reader.read(&mut buf) { match reader.read(&mut buf) {
Ok(n) if n != 0 => { Ok(n) if n != 0 => {
blocks_read += 1; blocks_read += 1;
for &byte in buf.slice_to(n).iter() { for &byte in buf[..n].iter() {
ret += byte as u32; ret += byte as u32;
} }
}, },

View file

@ -88,7 +88,7 @@ pub fn uumain(args: Vec<String>) -> isize {
let mut slice = n.as_slice(); let mut slice = n.as_slice();
if slice.len() > 0 && slice.char_at(0) == '+' { if slice.len() > 0 && slice.char_at(0) == '+' {
beginning = true; beginning = true;
slice = slice.slice_from(1); slice = &slice[1..];
} }
line_count = match parse_size(slice) { line_count = match parse_size(slice) {
Some(m) => m, Some(m) => m,
@ -103,7 +103,7 @@ pub fn uumain(args: Vec<String>) -> isize {
let mut slice = n.as_slice(); let mut slice = n.as_slice();
if slice.len() > 0 && slice.char_at(0) == '+' { if slice.len() > 0 && slice.char_at(0) == '+' {
beginning = true; beginning = true;
slice = slice.slice_from(1); slice = &slice[1..];
} }
byte_count = match parse_size(slice) { byte_count = match parse_size(slice) {
Some(m) => m, Some(m) => m,
@ -152,7 +152,7 @@ pub fn uumain(args: Vec<String>) -> isize {
fn parse_size(mut size_slice: &str) -> Option<usize> { fn parse_size(mut size_slice: &str) -> Option<usize> {
let mut base = let mut base =
if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' { if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' {
size_slice = size_slice.slice_to(size_slice.len() - 1); size_slice = &size_slice[..size_slice.len() - 1];
1000us 1000us
} else { } else {
1024us 1024us
@ -179,7 +179,7 @@ fn parse_size(mut size_slice: &str) -> Option<usize> {
} }
}; };
if has_suffix { if has_suffix {
size_slice = size_slice.slice_to(size_slice.len() - 1); size_slice = &size_slice[..size_slice.len() - 1];
} }
exp exp
} else { } else {
@ -224,7 +224,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
// If this is the last number // If this is the last number
if pos == len - 1 { if pos == len - 1 {
options.remove(a); options.remove(a);
let number: Option<usize> = from_utf8(current.slice(1,len)).unwrap().parse(); let number: Option<usize> = from_utf8(&current[1..len]).unwrap().parse();
return (options, Some(number.unwrap())); return (options, Some(number.unwrap()));
} }
} }

View file

@ -28,16 +28,16 @@ pub fn uumain(_: Vec<String>) -> isize {
} }
let args = let args =
if !args[0].ends_with(NAME.as_bytes()) { if !args[0].ends_with(NAME.as_bytes()) {
args.slice_from(1) &args[1..]
} else { } else {
args.as_slice() args.as_slice()
}; };
let args = match args[0] { let args = match args[0] {
b"[" => match args[args.len() - 1] { b"[" => match args[args.len() - 1] {
b"]" => args.slice(1, args.len() - 1), b"]" => &args[1..args.len() - 1],
_ => return 2, _ => return 2,
}, },
_ => args.slice(1, args.len()), _ => &args[1..args.len()],
}; };
let mut error = false; let mut error = false;
let retval = 1 - parse_expr(args, &mut error) as isize; let retval = 1 - parse_expr(args, &mut error) as isize;
@ -54,7 +54,7 @@ fn one(args: &[&[u8]]) -> bool {
fn two(args: &[&[u8]], error: &mut bool) -> bool { fn two(args: &[&[u8]], error: &mut bool) -> bool {
match args[0] { match args[0] {
b"!" => !one(args.slice_from(1)), b"!" => !one(&args[1..]),
b"-b" => path(args[1], PathCondition::BlockSpecial), b"-b" => path(args[1], PathCondition::BlockSpecial),
b"-c" => path(args[1], PathCondition::CharacterSpecial), b"-c" => path(args[1], PathCondition::CharacterSpecial),
b"-d" => path(args[1], PathCondition::Directory), b"-d" => path(args[1], PathCondition::Directory),
@ -63,7 +63,7 @@ fn two(args: &[&[u8]], error: &mut bool) -> bool {
b"-g" => path(args[1], PathCondition::GroupIDFlag), b"-g" => path(args[1], PathCondition::GroupIDFlag),
b"-h" => path(args[1], PathCondition::SymLink), b"-h" => path(args[1], PathCondition::SymLink),
b"-L" => path(args[1], PathCondition::SymLink), b"-L" => path(args[1], PathCondition::SymLink),
b"-n" => one(args.slice_from(1)), b"-n" => one(&args[1..]),
b"-p" => path(args[1], PathCondition::FIFO), b"-p" => path(args[1], PathCondition::FIFO),
b"-r" => path(args[1], PathCondition::Readable), b"-r" => path(args[1], PathCondition::Readable),
b"-S" => path(args[1], PathCondition::Socket), b"-S" => path(args[1], PathCondition::Socket),
@ -72,7 +72,7 @@ fn two(args: &[&[u8]], error: &mut bool) -> bool {
b"-u" => path(args[1], PathCondition::UserIDFlag), b"-u" => path(args[1], PathCondition::UserIDFlag),
b"-w" => path(args[1], PathCondition::Writable), b"-w" => path(args[1], PathCondition::Writable),
b"-x" => path(args[1], PathCondition::Executable), b"-x" => path(args[1], PathCondition::Executable),
b"-z" => !one(args.slice_from(1)), b"-z" => !one(&args[1..]),
_ => { _ => {
*error = true; *error = true;
false false
@ -91,7 +91,7 @@ fn three(args: &[&[u8]], error: &mut bool) -> bool {
b"-lt" => integers(args[0], args[2], IntegerCondition::Less), b"-lt" => integers(args[0], args[2], IntegerCondition::Less),
b"-le" => integers(args[0], args[2], IntegerCondition::LessEqual), b"-le" => integers(args[0], args[2], IntegerCondition::LessEqual),
_ => match args[0] { _ => match args[0] {
b"!" => !two(args.slice_from(1), error), b"!" => !two(&args[1..], error),
_ => { _ => {
*error = true; *error = true;
false false
@ -103,7 +103,7 @@ fn three(args: &[&[u8]], error: &mut bool) -> bool {
fn four(args: &[&[u8]], error: &mut bool) -> bool { fn four(args: &[&[u8]], error: &mut bool) -> bool {
match args[0] { match args[0] {
b"!" => { b"!" => {
!three(args.slice_from(1), error) !three(&args[1..], error)
} }
_ => { _ => {
*error = true; *error = true;
@ -157,7 +157,7 @@ fn dispatch(args: &mut &[&[u8]], error: &mut bool) -> bool {
3 => dispatch_three(args, error), 3 => dispatch_three(args, error),
_ => dispatch_four(args, error) _ => dispatch_four(args, error)
}; };
*args = (*args).slice_from(idx); *args = &(*args)[idx..];
val val
} }
@ -229,7 +229,7 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
}); });
while !*error && args.len() > 0 && prec as usize >= min_prec as usize { while !*error && args.len() > 0 && prec as usize >= min_prec as usize {
let op = args[0]; let op = args[0];
*args = (*args).slice_from(1); *args = &(*args)[1..];
let mut rhs = dispatch(args, error); let mut rhs = dispatch(args, error);
while args.len() > 0 { while args.len() > 0 {
let subprec = *hashmap.get(&args[0]).unwrap_or_else(|| { let subprec = *hashmap.get(&args[0]).unwrap_or_else(|| {

View file

@ -95,7 +95,7 @@ Usage:
return ERR_EXIT_STATUS; return ERR_EXIT_STATUS;
} }
}; };
return timeout(matches.free[1].as_slice(), matches.free.slice_from(2), duration, signal, kill_after, foreground, status); return timeout(matches.free[1].as_slice(), &matches.free[2..], duration, signal, kill_after, foreground, status);
} }
0 0

View file

@ -175,12 +175,12 @@ fn parse_size(size: &str) -> (u64, TruncateMode) {
let size: &str = size; let size: &str = size;
size size
} else { } else {
size.slice_from(1) &size[1..]
}; };
if slice.char_at(slice.len() - 1).is_alphabetic() { if slice.char_at(slice.len() - 1).is_alphabetic() {
slice = slice.slice_to(slice.len() - 1); slice = &slice[..slice.len() - 1];
if slice.len() > 0 && slice.char_at(slice.len() - 1).is_alphabetic() { if slice.len() > 0 && slice.char_at(slice.len() - 1).is_alphabetic() {
slice = slice.slice_to(slice.len() - 1); slice = &slice[..slice.len() - 1];
} }
} }
slice slice

View file

@ -68,7 +68,7 @@ impl Uniq {
Some(i) => min(slice_start + i, len), Some(i) => min(slice_start + i, len),
None => len None => len
}; };
let sliced = line.as_slice().slice(slice_start, slice_stop).to_string(); let sliced = line.as_slice()[slice_start..slice_stop].to_string();
if self.ignore_case { if self.ignore_case {
sliced.into_ascii_uppercase() sliced.into_ascii_uppercase()
} else { } else {