MCPcopy Create free account
hub / github.com/apache/datafusion / replace_all

Function replace_all

benchmarks/src/sql_benchmark.rs:1319–1339  ·  view source on GitHub ↗
(
    re: &Regex,
    haystack: &str,
    replacement: impl Fn(&regex::Captures) -> Result<String, E>,
)

Source from the content-addressed store, hash-verified

1317}
1318
1319fn replace_all<E>(
1320 re: &Regex,
1321 haystack: &str,
1322 replacement: impl Fn(&regex::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
1341static TRUE_FALSE_REPLACEMENT_RE: LazyLock<Regex> = LazyLock::new(|| {
1342 Regex::new(r"\$\{(\w+)(?::-([^|}]+))?\|([^|]+)\|([^}]+)}")

Callers 1

Calls 4

lenMethod · 0.45
getMethod · 0.45
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…