Skip to main content

Module sentinel

Module sentinel 

Source
Expand description

Shared sentinel-block primitives used by shells::profile and sys::profile to find, extract, remove, and insert the # >>> ... >>> / # <<< ... <<< blocks shine writes into user-owned shell profile files.

Two removal styles are kept deliberately separate (remove_block_bytewise vs remove_block_linewise): they differ in preceding-blank-line handling and CRLF behavior (see each function’s docs), and canonicalizing them without golden-output proof that neither caller depends on the difference would risk a silent formatting regression in a file shine does not own. Do not merge them without characterization tests confirming both callers’ current byte-for-byte output is preserved.

Structs§

Sentinel
A sentinel marker pair, e.g. ("# >>> shine >>>", "# <<< shine <<<").

Enums§

InsertAt
Where to insert a block relative to existing content, for insert_block.

Functions§

extract_block_with_newline
Like find_block, but also includes one trailing '\n' immediately after the end marker if present. The end marker is searched for only after the start marker, so an end marker that appears before the start marker is not matched.
find_block
Returns the substring from the start marker through the end marker (inclusive), or None if either marker is missing. Does not include any trailing newline after the end marker.
insert_block
Inserts block into content, separated from any existing content by exactly one blank line (regardless of whether block or content already end/start with a newline). When content is empty, no leading/trailing blank line is added — the result is just block.
remove_block_bytewise
Byte-offset block removal (shells::profile’s semantics).
remove_block_linewise
Line-based block removal (sys::profile’s semantics).
trim_outer_blank_lines
Trims all leading and trailing '\n' characters (not just one).