Refactor string per-replacement op into helper
Extract the replacement loop body into `_replace_once` to ease future
annotation tracking during string replacement operations. The new
function returns match information (pattern index, match range, bytes
written) that will be needed to properly adjust annotation positions
when replacements occur.