Skip to content

Commit 640e548

Browse files
committed
Add required comments
1 parent 03958ae commit 640e548

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/uu/sed/src/script_line_provider.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Provide the script contents line by line
1+
//! Provide the script contents line by line
22
//
33
// SPDX-License-Identifier: MIT
44
// Copyright (c) 2025 Diomidis Spinellis
@@ -12,44 +12,51 @@ use crate::command::ScriptValue;
1212
use std::fs::File;
1313
use std::io::{self, BufRead, BufReader};
1414

15+
/// The provider of script lines across all specified scripts
16+
/// Scripts can be specified to sed as files or as strings.
1517
pub struct ScriptLineProvider {
1618
sources: Vec<ScriptValue>,
1719
state: State,
1820
}
1921

22+
// Encapsulation of the script line provider's state
2023
enum State {
21-
NotStarted,
24+
NotStarted, // Processing has not yet started
2225
Active {
2326
index: usize,
24-
reader: Box<dyn BufRead>,
25-
input_name: String,
26-
line_number: usize,
27+
reader: Box<dyn BufRead>, // Object on which read_line is called
28+
input_name: String, // Input description (path or script string)
29+
line_number: usize, // Current line number
2730
},
28-
Done,
31+
Done, // All scripts have been processed
2932
}
3033

3134
impl ScriptLineProvider {
35+
/// Construct the script provider from the specified script sources
3236
pub fn new(sources: Vec<ScriptValue>) -> Self {
3337
Self {
3438
sources,
3539
state: State::NotStarted,
3640
}
3741
}
3842

43+
/// Return the currently processed script line number.
3944
pub fn get_line_number(&self) -> usize {
4045
match &self.state {
4146
State::Active { line_number, .. } => *line_number,
4247
_ => 0,
4348
}
4449
}
4550

51+
/// Return the currently processed script descriptive name.
4652
pub fn get_input_name(&self) -> &str {
4753
match &self.state {
4854
State::Active { input_name, .. } => input_name.as_str(),
4955
_ => "",
5056
}
5157
}
5258

59+
/// Return the next script line to process across all scripts.
5360
pub fn next_line(&mut self) -> io::Result<Option<String>> {
5461
let mut line = String::new();
5562

@@ -82,6 +89,7 @@ impl ScriptLineProvider {
8289
}
8390
}
8491

92+
// Move to the next available script source.
8593
fn advance_source(&mut self, next_index: usize) -> io::Result<()> {
8694
if next_index >= self.sources.len() {
8795
self.state = State::Done;
@@ -130,6 +138,7 @@ impl ScriptLineProvider {
130138
Ok(())
131139
}
132140
}
141+
133142
#[cfg(test)]
134143
mod tests {
135144
use super::*;

0 commit comments

Comments
 (0)