Skip to content

Commit

Permalink
Simplify line counting
Browse files Browse the repository at this point in the history
We don't need to (or rather need not to) handle trailing newline in any
special way - BufReader::read_line already takes care of it, reading
until \n, so in all sensible cases (trailing \n, trailing \r\n, no
trailing newline), no extra line would be counted.
  • Loading branch information
AMDmi3 committed Mar 15, 2024
1 parent 095f25e commit 9c0a965
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ fn apply_content_rules(
let mut matched_lines: Vec<Vec<u64>> = vec![Default::default(); global_rule_statuses.len()];

let mut line_number: u64 = 0;
let mut last_line_was_empty = false;
for line in reader.lines() {
let line = line?;

Expand Down Expand Up @@ -121,16 +120,9 @@ fn apply_content_rules(
}

line_number += 1;
last_line_was_empty = line.is_empty();
}

let lines_count = if last_line_was_empty {
line_number - 1
} else {
line_number
};

apply_file_line_conditions(lines_count, &mut rules_with_conditions);
apply_file_line_conditions(line_number, &mut rules_with_conditions);

rules_with_conditions.iter().for_each(|(rule, condition)| {
if !condition.are_all_positive_conditions_satisfied(&local_condition_statuses) {
Expand Down

0 comments on commit 9c0a965

Please sign in to comment.