pub fn edit_blocks(
path: &str,
content: &str,
block: &[String],
replacement: &[String],
) -> (String, usize, Vec<Site>)Expand description
Replace every non-overlapping occurrence of block in content with
replacement lines, preserving every untouched byte (including a missing
final newline). An empty replacement deletes the matched lines entirely.
Returns the new content, the occurrence count, and the changed sites
(line is the block’s 1-based start; before/after are newline-joined).
§Examples
use coding_tools::block::edit_blocks;
let block = vec!["b".to_string(), "c".to_string()];
let repl = vec!["X".to_string()];
let (out, n, sites) = edit_blocks("f", "a\nb\nc\nd\n", &block, &repl);
assert_eq!(out, "a\nX\nd\n");
assert_eq!(n, 1);
assert_eq!(sites[0].line, 2);
// Empty replacement deletes the block's lines.
let (out, _, _) = edit_blocks("f", "a\nb\nc\nd\n", &block, &[]);
assert_eq!(out, "a\nd\n");