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).
edit_blocks_with
edit_blocks, with optional blank-run squeezeing of the match (see find_spans_squeezed). Under squeeze the replaced source span can be longer than the block, so each Site::before carries the actual matched source lines (identical to the block in the exact path).
find_spans_squeezed
Find every non-overlapping squeezed match of block in lines, 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 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.
nearest_miss_with
nearest_miss, selecting the exact or blank-run-squeezing matcher by squeeze. Used so the diagnostic agrees with how the edit actually matched.