Merge pull request #894 from kwantam/master

fix fmt's behavior for blank prefixed lines
This commit is contained in:
Heather 2016-06-02 08:28:52 +04:00
commit 73fdc4824f
2 changed files with 8 additions and 7 deletions

View file

@ -206,7 +206,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
let p_stream = ParagraphStream::new(&fmt_opts, &mut fp);
for para_result in p_stream {
match para_result {
Err(s) => silent_unwrap!(ostream.write_all(s.as_bytes())),
Err(s) => {
silent_unwrap!(ostream.write_all(s.as_bytes()));
silent_unwrap!(ostream.write_all("\n".as_bytes()));
},
Ok(para) => break_lines(&para, &fmt_opts, &mut ostream)
}
}

View file

@ -100,11 +100,9 @@ impl<'a> FileLines<'a> {
if !exact {
// we do it this way rather than byte indexing to support unicode whitespace chars
for (i, char) in line.char_indices() {
if char.is_whitespace() {
if line[i..].starts_with(pfx) {
return (true, i);
}
} else {
if line[i..].starts_with(pfx) {
return (true, i);
} else if !char.is_whitespace() {
break;
}
}
@ -157,7 +155,7 @@ impl<'a> Iterator for FileLines<'a> {
// Err(true) indicates that this was a linebreak,
// which is important to know when detecting mail headers
if n.chars().all(|c| c.is_whitespace()) {
return Some(Line::NoFormatLine("\n".to_owned(), true));
return Some(Line::NoFormatLine("".to_owned(), true));
}
// if this line does not match the prefix,