mirror of
https://github.com/uutils/coreutils
synced 2024-12-15 07:42:48 +00:00
Merge pull request #404 from Arcterus/wc-fix
Fix wc (for bytes) and test (for testing purposes)
This commit is contained in:
commit
6bcc7e3be3
2 changed files with 13 additions and 5 deletions
|
@ -16,16 +16,24 @@ use std::os::{args_as_bytes};
|
|||
use std::str::{from_utf8};
|
||||
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 {
|
||||
let args = args_as_bytes();
|
||||
let args: Vec<&[u8]> = args.iter().map(|a| a.as_slice()).collect();
|
||||
let args = args.as_slice();
|
||||
if args.len() == 0 {
|
||||
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] {
|
||||
b"[" => match args[args.len()-1] {
|
||||
b"]" => args.slice(1, args.len()-1),
|
||||
b"[" => match args[args.len() - 1] {
|
||||
b"]" => args.slice(1, args.len() - 1),
|
||||
_ => return 2,
|
||||
},
|
||||
_ => args.slice(1, args.len()),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
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") {
|
||||
print!("{:1$}", char_count, max_str_len);
|
||||
|
|
Loading…
Reference in a new issue