Merge pull request #404 from Arcterus/wc-fix

Fix wc (for bytes) and test (for testing purposes)
This commit is contained in:
Heather 2014-09-28 09:30:47 +04:00
commit 6bcc7e3be3
2 changed files with 13 additions and 5 deletions

View file

@ -16,13 +16,21 @@ use std::os::{args_as_bytes};
use std::str::{from_utf8}; use std::str::{from_utf8};
use num::bigint::{BigInt}; use num::bigint::{BigInt};
static NAME: &'static str = "test";
// TODO: decide how to handle non-UTF8 input for all the utils
pub fn uumain(_: Vec<String>) -> int { pub fn uumain(_: Vec<String>) -> int {
let args = args_as_bytes(); let args = args_as_bytes();
let args: Vec<&[u8]> = args.iter().map(|a| a.as_slice()).collect(); let args: Vec<&[u8]> = args.iter().map(|a| a.as_slice()).collect();
let args = args.as_slice();
if args.len() == 0 { if args.len() == 0 {
return 2; return 2;
} }
let args =
if !args[0].ends_with(NAME.as_bytes()) {
args.slice_from(1)
} else {
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.slice(1, args.len() - 1),

View file

@ -203,7 +203,7 @@ fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: u
print!("{:1$}", word_count, max_str_len); print!("{:1$}", word_count, max_str_len);
} }
if matches.opt_present("bytes") { if matches.opt_present("bytes") {
print!("{:1$}", byte_count, max_str_len + 1); print!("{:1$}", byte_count, max_str_len);
} }
if matches.opt_present("chars") { if matches.opt_present("chars") {
print!("{:1$}", char_count, max_str_len); print!("{:1$}", char_count, max_str_len);