Skip to main content

to_find_lines

Function to_find_lines 

Source
pub fn to_find_lines(payload: &str) -> Vec<String>
Expand description

Split a find/anchor payload into the lines a block match anchors on: to_lines, then drop any trailing empty lines.

Editors and file-writers terminate files with a newline and frequently leave a final blank line; without trimming, that becomes a phantom empty line at the tail of the anchor and a K-line block fails to match as a K+1-line one. Interior blank lines and whitespace-only lines are preserved (whitespace is significant in a block match); only exactly-empty ("") trailing lines are removed. An anchor that is entirely blank therefore reduces to zero lines.

ยงExamples

use coding_tools::payload::to_find_lines;

// A trailing blank line (e.g. a file ending in two newlines) is dropped.
assert_eq!(to_find_lines("a\nb\n\n"), vec!["a", "b"]);
// A single terminator already collapses, same as `to_lines`.
assert_eq!(to_find_lines("a\nb\n"), vec!["a", "b"]);
// An interior blank line is significant and kept.
assert_eq!(to_find_lines("a\n\nb\n"), vec!["a", "", "b"]);
// An all-blank anchor reduces to nothing.
assert!(to_find_lines("\n\n").is_empty());