1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Fixed line count

This commit is contained in:
Boden Garman 2013-11-30 12:13:39 +11:00
parent 8f49e2afa2
commit 5000ad7f39

View file

@ -60,12 +60,10 @@ fn main() {
} }
if (matches.opt_present("version")) { if (matches.opt_present("version")) {
println("cat 1.0.0"); println("wc 1.0.0");
return; return;
} }
let mut files = matches.free.clone(); let mut files = matches.free.clone();
if files.is_empty() { if files.is_empty() {
files = ~[~"-"]; files = ~[~"-"];
@ -113,7 +111,11 @@ pub fn wc(files: ~[~str], matches: &Matches) {
// hence the option wrapped in a result here // hence the option wrapped in a result here
match result(| | reader.read_until(LF)) { match result(| | reader.read_until(LF)) {
Ok(Some(raw_line)) => { Ok(Some(raw_line)) => {
line_count += 1; // GNU 'wc' only counts lines that end in LF as lines
if (raw_line.iter().last().unwrap() == &LF) {
line_count += 1;
}
byte_count += raw_line.iter().len(); byte_count += raw_line.iter().len();
// try and convert the bytes to UTF-8 first // try and convert the bytes to UTF-8 first