(
re: &Regex,
haystack: &str,
replacement: impl Fn(®ex::Captures) -> Result<String, E>,
)
| 1317 | } |
| 1318 | |
| 1319 | fn replace_all<E>( |
| 1320 | re: &Regex, |
| 1321 | haystack: &str, |
| 1322 | replacement: impl Fn(®ex::Captures) -> Result<String, E>, |
| 1323 | ) -> Result<String, E> { |
| 1324 | let mut new = String::with_capacity(haystack.len()); |
| 1325 | let mut last_match = 0; |
| 1326 | |
| 1327 | for caps in re.captures_iter(haystack) { |
| 1328 | let m = caps.get(0).unwrap(); |
| 1329 | |
| 1330 | new.push_str(&haystack[last_match..m.start()]); |
| 1331 | new.push_str(&replacement(&caps)?); |
| 1332 | |
| 1333 | last_match = m.end(); |
| 1334 | } |
| 1335 | |
| 1336 | new.push_str(&haystack[last_match..]); |
| 1337 | |
| 1338 | Ok(new) |
| 1339 | } |
| 1340 | |
| 1341 | static TRUE_FALSE_REPLACEMENT_RE: LazyLock<Regex> = LazyLock::new(|| { |
| 1342 | Regex::new(r"\$\{(\w+)(?::-([^|}]+))?\|([^|]+)\|([^}]+)}") |
no test coverage detected
searching dependent graphs…