Skip to content

uefi(data-types): allow is_ascii function on Char16 and CStr16 #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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