Skip to content

Commit

Permalink
sl-std: Add ascii::Str::make_lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed Jul 19, 2024
1 parent b888c05 commit 574d73c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/sl-std/src/ascii/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ impl Str {
String::from_chars(chars)
}

/// Converts this string to its lower case equivalent in-place.
///
/// Letters 'A' to 'Z' are mapped to 'a' to 'z',
/// but other characters are unchanged.
///
/// To return a new lowercased value without modifying the existing one, use
/// [`to_lowercase()`].
///
/// [`to_lowercase()`]: #method.to_lowercase
///
/// # Examples
///
/// ```
/// #![feature(ascii_char_variants, ascii_char)]
/// # use sl_std::ascii;
/// let mut s = ascii::String::try_from("Hello World!").unwrap();
///
/// s.make_lowercase();
///
/// assert_eq!("hello world!", s.as_str());
/// ```
#[inline]
pub fn make_lowercase(&mut self) {
// SAFETY: Making chars lowercase does not invalidate ascii
let me = unsafe { self.as_bytes_mut() };
me.make_ascii_lowercase();
}

/// Construct [Self] from a `&[u8]`
///
/// Returns `None` if the bytes are not a valid ascii-encoded
Expand Down

0 comments on commit 574d73c

Please sign in to comment.