You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm particularly interested in titlecase support since it is not provided by the std.
For the capitalize cases, I believe they could be implemented like:
traitByteSlice{fnmake_ascii_capitalized(&mutself){ifletSome((head, tail)) = self.as_bytes().split_first_mut(){
head.make_ascii_uppercase();
tail.make_ascii_lowercase();}}fnto_capitalized_into(&self,buf:&mutVec<u8>){// This allocation assumes that in the common case, capitalizing// and lowercasing `char`s do not change the length of the// `Vec`.
buf.reserve(bytes.len());letmut bytes = self.as_bytes();match bstr::decode_utf8(bytes){(Some(ch), size) => {// Converting a UTF-8 character to uppercase may yield// multiple codepoints.for ch in ch.to_uppercase(){
buf.push_char(ch)}
bytes = &bytes[size..];}(None, size)if size == 0 => return,(None, size) => {let(substring, remainder) = bytes.split_at(size);
buf.extend_from_slice(substring);
bytes = remainder;}}while !bytes.is_empty(){let(ch, size) = bstr::decode_utf8(bytes);ifletSome(ch) = ch {// Converting a UTF-8 character to lowercase may yield// multiple codepoints.for ch in ch.to_lowercase(){
buf.push_char(ch);}
bytes = &bytes[size..];}else{let(substring, remainder) = bytes.split_at(size);
buf.extend_from_slice(substring);
bytes = remainder;}}self = replacement;}}
The text was updated successfully, but these errors were encountered:
lopopolo
changed the title
feat: make_{capitalized,lowercase,uppercase,titlecase}, make_ascii_{capitalized,lowercase,uppercase,titlecase}
feat: make_{capitalized,lowercase,uppercase,titlecase}, make_ascii_{capitalized,titlecase}
Jan 14, 2021
lopopolo
changed the title
feat: make_{capitalized,lowercase,uppercase,titlecase}, make_ascii_{capitalized,titlecase}
feat: make_{capitalized,titlecase}, make_ascii_{capitalized,titlecase}
Jan 14, 2021
lopopolo
changed the title
feat: make_{capitalized,titlecase}, make_ascii_{capitalized,titlecase}
feat: to_{capitalized,titlecase}, to_{capitalized,titlecase}_into, make_ascii_{capitalized,titlecase}
Jan 14, 2021
I'm particularly interested in titlecase support since it is not provided by the
std
.For the
capitalize
cases, I believe they could be implemented like:The above code is MIT licensed and comes from https://github.com/artichoke/artichoke/blob/fc87277afda4ac3db59ea9c080bbb5f5170b6d10/spinoso-string/src/lib.rs#L1305-L1353.
The text was updated successfully, but these errors were encountered: