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§
- Nearest
Miss - The best partial alignment of a block that did not match.
Functions§
- edit_
blocks - Replace every non-overlapping occurrence of
blockincontentwithreplacementlines, preserving every untouched byte (including a missing final newline). An emptyreplacementdeletes the matched lines entirely. Returns the new content, the occurrence count, and the changed sites (lineis the block’s 1-based start;before/afterare newline-joined). - edit_
blocks_ with edit_blocks, with optional blank-runsqueezeing of the match (seefind_spans_squeezed). Under squeeze the replaced source span can be longer than the block, so eachSite::beforecarries the actual matched source lines (identical to the block in the exact path).- find_
spans_ squeezed - Find every non-overlapping squeezed match of
blockinlines, scanning forward (see [align_squeezed]). Returns each match’s(0-based start, source-line count)span — the span can be longer than the block when the source has wider blank runs than the anchor. - find_
starts - Find every non-overlapping occurrence of
blockinlines, scanning forward. Returns the 0-based start indices. - nearest_
miss - Report the best partial alignment of an unmatched
blockagainstlines: 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. - nearest_
miss_ with nearest_miss, selecting the exact or blank-run-squeezing matcher bysqueeze. Used so the diagnostic agrees with how the edit actually matched.