Skip to main content

Module block

Module block 

Source
Expand description

Line-anchored literal block matching, shared by ct-search, ct-view, and ct-edit.

A multi-line pattern matches as a block: a find block of K lines matches K consecutive source lines exactly, byte-for-byte, leading and trailing whitespace significant. When a block fails to match, nearest_miss reports the best partial alignment — the candidate with the longest matching prefix and the first diverging line — so the author sees why the anchor missed (whitespace drift, a comment edit, an already-applied change) without bisecting by hand.

Structs§

NearestMiss
The best partial alignment of a block that did not match.

Functions§

edit_blocks
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).
find_starts
Find every non-overlapping occurrence of block in lines, scanning forward. Returns the 0-based start indices.
nearest_miss
Report the best partial alignment of an unmatched block against lines: the start with the longest run of matching leading block lines (ties go to the earliest). When no line equals the block’s first line at all, falls back to a whitespace-insensitive scan of that first line, so indentation drift — the most common anchor failure — is still diagnosed.