Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/sed/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ pub struct ProcessingContext {
pub append_elements: Vec<AppendElement>,
}

impl ProcessingContext {
/// Return the byte that separates lines: \0 with -z, otherwise \n.
pub fn line_separator(&self) -> u8 {
if self.null_data { b'\0' } else { b'\n' }
}
}

#[derive(Clone, Debug)]
/// Elements that shall be appended at the end of each command processing cycle
pub enum AppendElement {
Expand Down Expand Up @@ -394,6 +401,8 @@ pub struct InputAction {
pub next_command: Option<Rc<RefCell<Command>>>,
/// Data to prepend to the read contents
pub prepend: Vec<u8>,
/// True if the prepended line ended with a line separator
pub prepend_terminated: bool,
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion src/sed/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,11 @@ fn compile_read_line_command(
let path = read_file_path(lines, line)?;
// Reuse a reader keyed by path so all `R` commands on the same file share
// one cursor (see `ProcessingContext::named_readers`).
let separator = context.line_separator();
let reader = context
.named_readers
.entry(path.clone())
.or_insert_with(|| NamedReader::new(path))
.or_insert_with(|| NamedReader::new(path, separator))
.clone();
cmd.data = CommandData::NamedReader(reader);
Ok(CommandHandling::Continue)
Expand Down
Loading
Loading