Skip to content

Commit

Permalink
Don't rely on std to_{upper,lower}case because they use the system al…
Browse files Browse the repository at this point in the history
…locator
  • Loading branch information
dstoza committed Feb 28, 2024
1 parent d43a426 commit 5f170ff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/rune/src/modules/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,9 @@ fn parse_char(s: &str) -> Result<char, char::ParseCharError> {
/// ```
#[rune::function(instance)]
fn to_lowercase(s: &str) -> VmResult<String> {
VmResult::Ok(vm_try!(String::try_from(s.to_lowercase())))
let mut lowercase = vm_try!(String::try_with_capacity(s.len()));
vm_try!(lowercase.try_extend(s.chars().flat_map(|c| c.to_lowercase())));
VmResult::Ok(lowercase)
}

/// Returns the uppercase equivalent of this string slice, as a new [`String`].
Expand Down Expand Up @@ -1184,7 +1186,9 @@ fn to_lowercase(s: &str) -> VmResult<String> {
/// ```
#[rune::function(instance)]
fn to_uppercase(s: &str) -> VmResult<String> {
VmResult::Ok(vm_try!(String::try_from(s.to_uppercase())))
let mut uppercase = vm_try!(String::try_with_capacity(s.len()));
vm_try!(uppercase.try_extend(s.chars().flat_map(|c| c.to_uppercase())));
VmResult::Ok(uppercase)
}

crate::__internal_impl_any!(::std::string, FromUtf8Error);
Expand Down

0 comments on commit 5f170ff

Please sign in to comment.