MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / try_replace_all_byteset

Function try_replace_all_byteset

rust/stringzilla.rs:1688–1712  ·  view source on GitHub ↗

Tries to replace all non-overlapping bytes in `buffer` that belong to `byteset` with `replacement`. Uses the same three-way strategy as [`try_replace_all`]. If the byteset is empty, the buffer is left untouched. Returns the number of replacements performed.

(buffer: &mut Vec<u8>, byteset: Byteset, replacement: &[u8])

Source from the content-addressed store, hash-verified

1686/// Uses the same three-way strategy as [`try_replace_all`]. If the byteset is empty, the buffer is
1687/// left untouched. Returns the number of replacements performed.
1688pub fn try_replace_all_byteset(buffer: &mut Vec<u8>, byteset: Byteset, replacement: &[u8]) -> Result<usize, Status> {
1689 if byteset.bits.iter().all(|&b| b == 0) {
1690 return Ok(0);
1691 }
1692
1693 replace_all_with_finder(
1694 buffer,
1695 1,
1696 replacement,
1697 |haystack, start| {
1698 if start >= haystack.len() {
1699 None
1700 } else {
1701 find_byteset(&haystack[start..], byteset).map(|offset| start + offset)
1702 }
1703 },
1704 |haystack, end| {
1705 if end == 0 {
1706 None
1707 } else {
1708 rfind_byteset(&haystack[..end], byteset)
1709 }
1710 },
1711 )
1712}
1713
1714/// Finds the first newline character in UTF-8 encoded text.
1715///

Callers 2

Calls 5

replace_all_with_finderFunction · 0.85
find_bytesetFunction · 0.85
rfind_bytesetFunction · 0.85
iterMethod · 0.80
lenMethod · 0.80

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…