From 0c117eb8a84be36bec02e5e6011d3d33f3569b82 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 27 Sep 2015 23:29:07 -0400 Subject: [PATCH] initial work --- src/expand/expand.rs | 6 +----- src/fmt/parasplit.rs | 5 ++--- src/stdbuf/stdbuf.rs | 4 ++-- src/tr/tr.rs | 1 - src/unexpand/unexpand.rs | 6 +----- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 09bf427b1..3098b87e1 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -1,6 +1,4 @@ #![crate_name = "expand"] -#![feature(unicode)] - /* * This file is part of the uutils coreutils package. * @@ -14,14 +12,12 @@ extern crate getopts; extern crate libc; -extern crate rustc_unicode; extern crate unicode_width; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::iter::repeat; use std::str::from_utf8; -use rustc_unicode::str::utf8_char_width; use unicode_width::UnicodeWidthChar; #[path = "../common/util.rs"] @@ -177,7 +173,7 @@ fn expand(options: Options) { while byte < buf.len() { let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = utf8_char_width(buf[byte]); + let nbytes = UnicodeWidthChar::width(buf[byte] as char).unwrap_or(0); if byte + nbytes > buf.len() { // don't overrun buffer because of invalid UTF-8 diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 155edf6c2..01627f24a 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -11,7 +11,6 @@ use std::iter::Peekable; use std::io::{BufRead, Lines}; use std::slice::Iter; use std::str::CharRange; -use rustc_unicode::str::UnicodeStr; use unicode_width::UnicodeWidthChar; use FileOrStdReader; use FmtOptions; @@ -157,7 +156,7 @@ impl<'a> Iterator for FileLines<'a> { // emit a blank line // Err(true) indicates that this was a linebreak, // which is important to know when detecting mail headers - if n.is_whitespace() { + if n.chars().all(|c| c.is_whitespace()) { return Some(Line::NoFormatLine("\n".to_string(), true)); } @@ -166,7 +165,7 @@ impl<'a> Iterator for FileLines<'a> { let (pmatch, poffset) = self.match_prefix(&n[..]); if !pmatch { return Some(Line::NoFormatLine(n, false)); - } else if n[poffset + self.opts.prefix.len()..].is_whitespace() { + } else if n[poffset + self.opts.prefix.len()..].chars().all(|c| c.is_whitespace()) { // if the line matches the prefix, but is blank after, // don't allow lines to be combined through it (that is, // treat it like a blank line, except that since it's diff --git a/src/stdbuf/stdbuf.rs b/src/stdbuf/stdbuf.rs index 0024ef72d..ecb30fa76 100644 --- a/src/stdbuf/stdbuf.rs +++ b/src/stdbuf/stdbuf.rs @@ -227,7 +227,7 @@ pub fn uumain(args: Vec) -> i32 { opts.optflag("", "version", "output version information and exit"); let mut options = ProgramOptions {stdin: BufferType::Default, stdout: BufferType::Default, stderr: BufferType::Default}; - let mut command_idx = -1; + let mut command_idx: i32 = -1; for i in 1 .. args.len()+1 { match parse_options(&args[1 .. i], &mut options, &opts) { Ok(OkMsg::Buffering) => { @@ -252,7 +252,7 @@ pub fn uumain(args: Vec) -> i32 { let ref command_name = args[command_idx as usize]; let mut command = Command::new(command_name); let (preload_env, libstdbuf) = get_preload_env(); - command.args(&args[(command_idx as usize)+ 1 ..]).env(preload_env, libstdbuf); + command.args(&args[(command_idx as usize) + 1 ..]).env(preload_env, libstdbuf); set_command_env(&mut command, "_STDBUF_I", options.stdin); set_command_env(&mut command, "_STDBUF_O", options.stdout); set_command_env(&mut command, "_STDBUF_E", options.stderr); diff --git a/src/tr/tr.rs b/src/tr/tr.rs index a95fc9460..7ec6627ff 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -1,6 +1,5 @@ #![crate_name = "tr"] #![feature(io)] - /* * This file is part of the uutils coreutils package. * diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index af138dcef..83bae7fc7 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -1,6 +1,4 @@ #![crate_name = "unexpand"] -#![feature(unicode)] - /* * This file is part of the uutils coreutils package. * @@ -14,13 +12,11 @@ extern crate getopts; extern crate libc; -extern crate rustc_unicode; extern crate unicode_width; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write}; use std::str::from_utf8; -use rustc_unicode::str::utf8_char_width; use unicode_width::UnicodeWidthChar; #[path = "../common/util.rs"] @@ -210,7 +206,7 @@ fn unexpand(options: Options) { } let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = utf8_char_width(buf[byte]); + let nbytes = UnicodeWidthChar::width(buf[byte] as char).unwrap_or(0); // figure out how big the next char is, if it's UTF-8 if byte + nbytes > buf.len() {