Function roe::make_ascii_titlecase

source ·
pub fn make_ascii_titlecase<T: AsMut<[u8]>>(slice: &mut T)
Expand description

Converts the given slice to its ASCII title case equivalent in-place.

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’ in the first byte; subsequent bytes with ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’; non-ASCII letters are unchanged.

This function can be used to implement String#capitalize! for ASCII strings in Ruby.

To return a new titlecased value without modifying the existing one, use to_ascii_titlecase.

§Examples

let mut buf = *b"ABCxyz";
make_ascii_titlecase(&mut buf);
assert_eq!(buf, *b"Abcxyz");

let mut buf = *b"1234%&*";
make_ascii_titlecase(&mut buf);
assert_eq!(buf, *b"1234%&*");

let mut buf = *b"ABC1234%&*";
make_ascii_titlecase(&mut buf);
assert_eq!(buf, *b"Abc1234%&*");

let mut buf = *b"1234%&*abcXYZ";
make_ascii_titlecase(&mut buf);
assert_eq!(buf, *b"1234%&*abcxyz");

let mut buf = *b"ABC, XYZ";
make_ascii_titlecase(&mut buf);
assert_eq!(buf, *b"Abc, xyz");