(input: &str, container: &mut String)
| 273 | } |
| 274 | |
| 275 | fn 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)] |
| 304 | mod tests { |
no test coverage detected
searching dependent graphs…