Skip to content

Commit

Permalink
Merge pull request rust-osdev#1008 from RaitoBezarius/is-ascii
Browse files Browse the repository at this point in the history
uefi(data-types): allow `is_ascii` function on `Char16` and `CStr16`
  • Loading branch information
phip1611 authored Nov 15, 2023
2 parents 06c300e + 712629b commit e85cb82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions uefi/src/data_types/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> for Char16 {
Expand Down
6 changes: 6 additions & 0 deletions uefi/src/data_types/strs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down

0 comments on commit e85cb82

Please sign in to comment.