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

Function apply_replace

datafusion/functions/src/string/replace.rs:247–283  ·  view source on GitHub ↗
(
    builder: &mut B,
    string: &str,
    from: &str,
    to: &str,
)

Source from the content-addressed store, hash-verified

245
246#[inline]
247fn apply_replace<B: BulkNullStringArrayBuilder>(
248 builder: &mut B,
249 string: &str,
250 from: &str,
251 to: &str,
252) {
253 // Hot path: single ASCII byte → single ASCII byte. An ASCII byte (< 0x80)
254 // cannot appear inside a multi-byte UTF-8 sequence, so any multi-byte
255 // sequences in `string` pass through unchanged and output stays valid
256 // UTF-8.
257 if let (&[from_byte], &[to_byte]) = (from.as_bytes(), to.as_bytes())
258 && from_byte.is_ascii()
259 && to_byte.is_ascii()
260 {
261 // SAFETY: see the contract above.
262 unsafe {
263 builder.append_byte_map(string.as_bytes(), |b| {
264 if b == from_byte { to_byte } else { b }
265 });
266 }
267 return;
268 }
269
270 if from.is_empty() {
271 // Empty `from`: insert `to` before each character and at both ends.
272 builder.append_with(|w| {
273 w.write_str(to);
274 for ch in string.chars() {
275 w.write_char(ch);
276 w.write_str(to);
277 }
278 });
279 return;
280 }
281
282 builder.append_with(|w| replace_into_writer(w, string, from, to));
283}
284
285#[inline]
286fn replace_into_writer<W: StringWriter>(w: &mut W, string: &str, from: &str, to: &str) {

Callers 2

replace_viewFunction · 0.85
replaceFunction · 0.85

Calls 6

replace_into_writerFunction · 0.85
append_byte_mapMethod · 0.80
append_withMethod · 0.80
write_strMethod · 0.80
write_charMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…