wstr: add `WStr::make_ascii_lowercase`

This commit is contained in:
Moulins 2023-04-05 21:37:22 +02:00 committed by Nathan Adams
parent 83f7bfc0c2
commit 604a15f957
2 changed files with 19 additions and 0 deletions

View File

@ -329,6 +329,12 @@ impl WStr {
super::ops::str_to_ascii_lowercase(self) super::ops::str_to_ascii_lowercase(self)
} }
/// Converts this string to its ASCII lower case equivalent in-place.
#[inline]
pub fn make_ascii_lowercase(&mut self) {
super::ops::str_make_ascii_lowercase(self)
}
/// Analogue of [`str::replace`]. /// Analogue of [`str::replace`].
#[inline] #[inline]
pub fn replace<'a, P: Pattern<'a>>(&'a self, pattern: P, with: &WStr) -> WString { pub fn replace<'a, P: Pattern<'a>>(&'a self, pattern: P, with: &WStr) -> WString {

View File

@ -202,6 +202,19 @@ pub fn str_to_ascii_lowercase(s: &WStr) -> WString {
map_latin1_chars(s, |c| c.to_ascii_lowercase()) map_latin1_chars(s, |c| c.to_ascii_lowercase())
} }
pub fn str_make_ascii_lowercase(s: &mut WStr) {
match s.units_mut() {
Units::Bytes(us) => us.make_ascii_lowercase(),
Units::Wide(us) => {
for c in us {
if let Ok(b) = u8::try_from(*c) {
*c = b.to_ascii_lowercase().into();
}
}
}
}
}
pub fn str_is_latin1(s: &WStr) -> bool { pub fn str_is_latin1(s: &WStr) -> bool {
match s.units() { match s.units() {
Units::Bytes(_) => true, Units::Bytes(_) => true,