Function roe::to_ascii_titlecase [−][src]
pub fn to_ascii_titlecase<T: AsRef<[u8]>>(slice: T) -> Vec<u8>
This is supported on crate feature
alloc
only.Returns a vector containing a copy of the given slice where each byte is mapped to its ASCII title case equivalent.
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
and
Symbol#capitalize
for ASCII strings in Ruby.
To titlecase the value in-place, use make_ascii_titlecase
.
Examples
assert_eq!(to_ascii_titlecase("ABCxyz"), &b"Abcxyz"[..]); assert_eq!(to_ascii_titlecase("1234%&*"), &b"1234%&*"[..]); assert_eq!(to_ascii_titlecase("ABC1234%&*"), &b"Abc1234%&*"[..]); assert_eq!(to_ascii_titlecase("1234%&*abcXYZ"), &b"1234%&*abcxyz"[..]); assert_eq!(to_ascii_titlecase("ABC, XYZ"), &b"Abc, xyz"[..]);