mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Avoid unsafe code in to_ascii_[lower/upper]case()
This commit is contained in:
parent
9e75dddf60
commit
8dbc878a35
@ -559,10 +559,9 @@ impl str {
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[inline]
|
||||
pub fn to_ascii_uppercase(&self) -> String {
|
||||
let mut bytes = self.as_bytes().to_vec();
|
||||
bytes.make_ascii_uppercase();
|
||||
// make_ascii_uppercase() preserves the UTF-8 invariant.
|
||||
unsafe { String::from_utf8_unchecked(bytes) }
|
||||
let mut s = self.to_owned();
|
||||
s.make_ascii_uppercase();
|
||||
s
|
||||
}
|
||||
|
||||
/// Returns a copy of this string where each character is mapped to its
|
||||
@ -592,10 +591,9 @@ impl str {
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[inline]
|
||||
pub fn to_ascii_lowercase(&self) -> String {
|
||||
let mut bytes = self.as_bytes().to_vec();
|
||||
bytes.make_ascii_lowercase();
|
||||
// make_ascii_lowercase() preserves the UTF-8 invariant.
|
||||
unsafe { String::from_utf8_unchecked(bytes) }
|
||||
let mut s = self.to_owned();
|
||||
s.make_ascii_lowercase();
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user