diff --git a/uefi/src/data_types/chars.rs b/uefi/src/data_types/chars.rs index a92c57067..ab270a82f 100644 --- a/uefi/src/data_types/chars.rs +++ b/uefi/src/data_types/chars.rs @@ -83,6 +83,12 @@ impl Char16 { pub const unsafe fn from_u16_unchecked(val: u16) -> Self { Self(val) } + + /// Checks if the value is within the ASCII range. + #[must_use] + pub const fn is_ascii(&self) -> bool { + self.0 <= 127 + } } impl TryFrom for Char16 { diff --git a/uefi/src/data_types/strs.rs b/uefi/src/data_types/strs.rs index 4cfd2f7c4..9e22be51a 100644 --- a/uefi/src/data_types/strs.rs +++ b/uefi/src/data_types/strs.rs @@ -415,6 +415,12 @@ impl CStr16 { self.0.len() * 2 } + /// Checks if all characters in this string are within the ASCII range. + #[must_use] + pub fn is_ascii(&self) -> bool { + self.0.iter().all(|c| c.is_ascii()) + } + /// Writes each [`Char16`] as a [`char`] (4 bytes long in Rust language) into the buffer. /// It is up to the implementer of [`core::fmt::Write`] to convert the char to a string /// with proper encoding/charset. For example, in the case of [`alloc::string::String`]