Skip to main content

apply_diff_to_text

Function apply_diff_to_text 

Source
pub fn apply_diff_to_text(
    input: &str,
    diff: &str,
) -> Result<String, ApplyDiffError>
Expand description

Applies a complete update body to in-memory text.

A body can contain multiple @@ sections. Within each section, context lines begin with a space, removals with -, and insertions with +. Uniform CRLF input remains CRLF; LF and trailing-newline behavior are also preserved.

§Errors

Returns ApplyDiffError when an anchor or context cannot be found, a body line has an invalid prefix, or the sections are malformed.

§Example

use agents_tools::apply_diff_to_text;

let result = apply_diff_to_text(
    "alpha\nbeta\ngamma\n",
    "@@ alpha\n-beta\n+BETA\n gamma",
)?;
assert_eq!(result, "alpha\nBETA\ngamma\n");