mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
Merge pull request #894 from kwantam/master
fix fmt's behavior for blank prefixed lines
This commit is contained in:
commit
73fdc4824f
2 changed files with 8 additions and 7 deletions
|
@ -206,7 +206,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let p_stream = ParagraphStream::new(&fmt_opts, &mut fp);
|
let p_stream = ParagraphStream::new(&fmt_opts, &mut fp);
|
||||||
for para_result in p_stream {
|
for para_result in p_stream {
|
||||||
match para_result {
|
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(¶, &fmt_opts, &mut ostream)
|
Ok(para) => break_lines(¶, &fmt_opts, &mut ostream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,11 +100,9 @@ impl<'a> FileLines<'a> {
|
||||||
if !exact {
|
if !exact {
|
||||||
// we do it this way rather than byte indexing to support unicode whitespace chars
|
// we do it this way rather than byte indexing to support unicode whitespace chars
|
||||||
for (i, char) in line.char_indices() {
|
for (i, char) in line.char_indices() {
|
||||||
if char.is_whitespace() {
|
if line[i..].starts_with(pfx) {
|
||||||
if line[i..].starts_with(pfx) {
|
return (true, i);
|
||||||
return (true, i);
|
} else if !char.is_whitespace() {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +155,7 @@ impl<'a> Iterator for FileLines<'a> {
|
||||||
// Err(true) indicates that this was a linebreak,
|
// Err(true) indicates that this was a linebreak,
|
||||||
// which is important to know when detecting mail headers
|
// which is important to know when detecting mail headers
|
||||||
if n.chars().all(|c| c.is_whitespace()) {
|
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,
|
// if this line does not match the prefix,
|
||||||
|
|
Loading…
Reference in a new issue