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])
| 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. |
| 1688 | pub 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 | /// |
searching dependent graphs…