Merge pull request #691 from steveklabnik/stable

Stable
This commit is contained in:
Heather 2015-09-28 08:23:04 +03:00
commit a5e6f8f485
6 changed files with 9 additions and 19 deletions

View file

@ -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

View file

@ -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

View file

@ -156,7 +156,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, bytes: bool, spaces: bool, width:
let ncount = routput.chars().fold(0, |out, ch: char| {
out + match ch {
'\t' => 8,
'\x08' => if out > 0 { -1 } else { 0 },
'\x08' => if out > 0 { !0 } else { 0 },
'\r' => return 0,
_ => 1
}

View file

@ -227,11 +227,11 @@ pub fn uumain(args: Vec<String>) -> 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) => {
command_idx = i - 1;
command_idx = (i as i32) - 1;
break;
},
Ok(OkMsg::Help) => {
@ -249,10 +249,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
if command_idx == -1 {
crash!(125, "Invalid options\nTry 'stdbuf --help' for more information.");
}
let ref command_name = args[command_idx];
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 + 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);

View file

@ -1,6 +1,5 @@
#![crate_name = "tr"]
#![feature(io)]
/*
* This file is part of the uutils coreutils package.
*

View file

@ -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() {