MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / replace_string_in_file

Function replace_string_in_file

src/program/transform.rs:1526–1531  ·  view source on GitHub ↗

replace a pattern to a str in a file.

(file: &Path, pat: &str, to: &str)

Source from the content-addressed store, hash-verified

1524
1525 /// replace a pattern to a str in a file.
1526 pub fn replace_string_in_file(file: &Path, pat: &str, to: &str) -> eyre::Result<()> {
1527 let content = std::fs::read_to_string(file)?;
1528 let content = content.replace(pat, to);
1529 std::fs::write(file, content)?;
1530 Ok(())
1531 }
1532
1533 pub fn relace_pattern_in_content(content: &str, pat: &str, to: &str) -> eyre::Result<String> {
1534 let pattern = format!(r"\b{pat}\b");

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected