initial work

This commit is contained in:
Steve Klabnik 2015-09-27 23:29:07 -04:00
parent ac7e289d29
commit 0c117eb8a8
5 changed files with 6 additions and 16 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

@ -227,7 +227,7 @@ 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) => {
@ -252,7 +252,7 @@ pub fn uumain(args: Vec<String>) -> 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);

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