From a544332c1ba2b3ec7f40058e2c524df623927838 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Wed, 2 Jul 2014 18:25:29 +0200 Subject: [PATCH] &str is no longer indexable --- echo/echo.rs | 8 ++++---- head/head.rs | 7 ++++--- tail/tail.rs | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/echo/echo.rs b/echo/echo.rs index ea7239b8d..2f8c76a13 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -51,7 +51,7 @@ fn isodigit(c: u8) -> bool { } } -fn convert_str(string: &str, index: uint, base: uint) -> (char, uint) { +fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) { let (max_digits, is_legal_digit) = match base { 8u => (3, isodigit), 16u => (2, isxdigit), @@ -201,7 +201,7 @@ pub fn uumain(args: Vec) -> int { 't' => print!("\t"), 'v' => print!("\x0B"), 'x' => { - let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 16u); + let (c, num_char_used) = convert_str(string.as_bytes(), index + 1, 16u); if num_char_used == 0 { print!("\\x"); } else { @@ -212,7 +212,7 @@ pub fn uumain(args: Vec) -> int { } }, '0' => { - let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 8u); + let (c, num_char_used) = convert_str(string.as_bytes(), index + 1, 8u); if num_char_used == 0 { print!("\0"); } else { @@ -223,7 +223,7 @@ pub fn uumain(args: Vec) -> int { } } _ => { - let (esc_c, num_char_used) = convert_str(string.as_slice(), index, 8u); + let (esc_c, num_char_used) = convert_str(string.as_bytes(), index, 8u); if num_char_used == 0 { print!("\\{}", c); } else { diff --git a/head/head.rs b/head/head.rs index a1c492283..4e90cfaa5 100644 --- a/head/head.rs +++ b/head/head.rs @@ -17,6 +17,7 @@ use std::io::{stdin}; use std::io::BufferedReader; use std::io::fs::File; use std::path::Path; +use std::str::from_utf8; use getopts::{optopt, optflag, getopts, usage}; static PROGRAM: &'static str = "head"; @@ -104,18 +105,18 @@ fn obsolete (options: &[String]) -> (Vec, Option) { while a < b { let current = options.get(a).clone(); - let current = current.as_slice(); + let current = current.as_bytes(); if current.len() > 1 && current[0] == '-' as u8 { let len = current.len(); for pos in range(1, len) { // Ensure that the argument is only made out of digits - if !char::is_digit(current.char_at(pos)) { break; } + if !char::is_digit(current[pos] as char) { break; } // If this is the last number if pos == len - 1 { options.remove(a); - let number : Option = from_str(current.slice(1,len)); + let number : Option = from_str(from_utf8(current.slice(1,len)).unwrap()); return (options, Some(number.unwrap())); } } diff --git a/tail/tail.rs b/tail/tail.rs index b939a5092..1d9f6873d 100644 --- a/tail/tail.rs +++ b/tail/tail.rs @@ -16,6 +16,7 @@ use std::io::{stdin}; use std::io::BufferedReader; use std::io::fs::File; use std::path::Path; +use std::str::from_utf8; use getopts::{optopt, optflag, getopts, usage}; use std::collections::Deque; use std::collections::ringbuf::RingBuf; @@ -123,18 +124,18 @@ fn obsolete (options: &[String]) -> (Vec, Option) { while a < b { let current = options.get(a).clone(); - let current = current.as_slice(); + let current = current.as_bytes(); if current.len() > 1 && current[0] == '-' as u8 { let len = current.len(); for pos in range(1, len) { // Ensure that the argument is only made out of digits - if !char::is_digit(current.char_at(pos)) { break; } + if !char::is_digit(current[pos] as char) { break; } // If this is the last number if pos == len - 1 { options.remove(a); - let number : Option = from_str(current.slice(1,len)); + let number : Option = from_str(from_utf8(current.slice(1,len)).unwrap()); return (options, Some(number.unwrap())); } }