Skip to main content

Module splice

Module splice 

Source
Expand description

Byte-range splicer for the workload edit primitive.

Once super::locate tells us where to make a change, this module emits the new bytes that go in. Three operations:

  • replace_range — overwrite an existing value’s byte range (replace-style edits, e.g. --add --replace).
  • insert_at — insert new content at an offset (add-new-key edits, e.g. --add with a missing anchor).
  • indent_block — re-indent a multi-line block of text to a given column. Used to align emitted YAML to the locator-reported indent.

Each function returns the post-splice source string; it doesn’t write to disk. The transactional driver in super does the on-disk rename via super::backup::commit_temp.

Functions§

indent_block
Re-indent block to start every non-empty line at column column. Existing leading whitespace on each line is replaced by exactly column spaces.
insert_at
Insert new_content at offset. Equivalent to replace_range(original, offset..offset, new_content), expressed plainly because insertion is the common case for adding new keys.
replace_range
Replace original[range] with replacement. The ranges either side are preserved byte-for-byte.