Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/uu/fmt/src/parasplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// spell-checker:ignore (ToDO) INFTY MULT PSKIP accum aftertab beforetab breakwords fmt's formatline linebreak linebreaking linebreaks linelen maxlength minlength nchars noformat noformatline ostream overlen parasplit plass pmatch poffset posn powf prefixindent punct signum slen sstart tabwidth tlen underlen winfo wlen wordlen wordsplits xanti xprefix

use std::io::{BufRead, Lines};
use std::io::{BufRead, Split};
use std::iter::Peekable;
use std::slice::Iter;
use unicode_width::UnicodeWidthChar;
Expand Down Expand Up @@ -78,11 +78,11 @@ pub struct FileLine {
/// Iterator that produces a stream of Lines from a file
pub struct FileLines<'a> {
opts: &'a FmtOptions,
lines: Lines<&'a mut FileOrStdReader>,
lines: Split<&'a mut FileOrStdReader>,
}

impl FileLines<'_> {
fn new<'b>(opts: &'b FmtOptions, lines: Lines<&'b mut FileOrStdReader>) -> FileLines<'b> {
fn new<'b>(opts: &'b FmtOptions, lines: Split<&'b mut FileOrStdReader>) -> FileLines<'b> {
FileLines { opts, lines }
}

Expand Down Expand Up @@ -156,7 +156,8 @@ impl Iterator for FileLines<'_> {
type Item = Line;

fn next(&mut self) -> Option<Line> {
let n = self.lines.next()?.ok()?;
let bytes = self.lines.next()?.ok()?;
let n = String::from_utf8_lossy(&bytes).into_owned();

// if this line is entirely whitespace,
// emit a blank line
Expand Down Expand Up @@ -242,7 +243,7 @@ pub struct ParagraphStream<'a> {

impl ParagraphStream<'_> {
pub fn new<'b>(opts: &'b FmtOptions, reader: &'b mut FileOrStdReader) -> ParagraphStream<'b> {
let lines = FileLines::new(opts, reader.lines()).peekable();
let lines = FileLines::new(opts, reader.split(b'\n')).peekable();
// at the beginning of the file, we might find mail headers
ParagraphStream {
lines,
Expand Down
Loading