Skip to content

Commit e85cb82

Browse files
authored
Merge pull request #1008 from RaitoBezarius/is-ascii
uefi(data-types): allow `is_ascii` function on `Char16` and `CStr16`
2 parents 06c300e + 712629b commit e85cb82

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: uefi/src/data_types/chars.rs

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ impl Char16 {
8383
pub const unsafe fn from_u16_unchecked(val: u16) -> Self {
8484
Self(val)
8585
}
86+
87+
/// Checks if the value is within the ASCII range.
88+
#[must_use]
89+
pub const fn is_ascii(&self) -> bool {
90+
self.0 <= 127
91+
}
8692
}
8793

8894
impl TryFrom<char> for Char16 {

Diff for: uefi/src/data_types/strs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ impl CStr16 {
415415
self.0.len() * 2
416416
}
417417

418+
/// Checks if all characters in this string are within the ASCII range.
419+
#[must_use]
420+
pub fn is_ascii(&self) -> bool {
421+
self.0.iter().all(|c| c.is_ascii())
422+
}
423+
418424
/// Writes each [`Char16`] as a [`char`] (4 bytes long in Rust language) into the buffer.
419425
/// It is up to the implementer of [`core::fmt::Write`] to convert the char to a string
420426
/// with proper encoding/charset. For example, in the case of [`alloc::string::String`]

0 commit comments

Comments
 (0)