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

Function initcap_string

datafusion/functions/src/unicode/initcap.rs:275–301  ·  view source on GitHub ↗
(input: &str, container: &mut String)

Source from the content-addressed store, hash-verified

273}
274
275fn initcap_string(input: &str, container: &mut String) {
276 container.clear();
277 let mut prev_is_alphanumeric = false;
278
279 if input.is_ascii() {
280 container.reserve(input.len());
281 // SAFETY: each byte is ASCII, so the result is valid UTF-8.
282 let out = unsafe { container.as_mut_vec() };
283 for &b in input.as_bytes() {
284 if prev_is_alphanumeric {
285 out.push(b.to_ascii_lowercase());
286 } else {
287 out.push(b.to_ascii_uppercase());
288 }
289 prev_is_alphanumeric = b.is_ascii_alphanumeric();
290 }
291 } else {
292 for c in input.chars() {
293 if prev_is_alphanumeric {
294 container.extend(c.to_lowercase());
295 } else {
296 container.extend(c.to_uppercase());
297 }
298 prev_is_alphanumeric = c.is_alphanumeric();
299 }
300 }
301}
302
303#[cfg(test)]
304mod tests {

Callers 3

invoke_with_argsMethod · 0.85
initcapFunction · 0.85
initcap_utf8viewFunction · 0.85

Calls 5

reserveMethod · 0.80
clearMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…