forked from AbleOS/ableos_userland
36 lines
921 B
Rust
36 lines
921 B
Rust
use alloc::vec::Vec;
|
|
|
|
pub enum DisplayError {
|
|
InvalidFormat,
|
|
InvalidWidth,
|
|
InvalidHeight,
|
|
InvalidBPP,
|
|
InvalidFPS,
|
|
}
|
|
|
|
pub fn parse_display_string(s: &str) -> Result<(u32, u32, u32, u32), DisplayError> {
|
|
let parts: Vec<&str> = s.split('x').collect();
|
|
if parts.len() != 3 {
|
|
return Err(DisplayError::InvalidFormat);
|
|
}
|
|
|
|
let width = parts[0]
|
|
.parse::<u32>()
|
|
.map_err(|_| DisplayError::InvalidWidth)?;
|
|
let height = parts[1]
|
|
.parse::<u32>()
|
|
.map_err(|_| DisplayError::InvalidHeight)?;
|
|
let bits: Vec<&str> = parts[2].split('@').collect();
|
|
if bits.len() != 2 {
|
|
return Err(DisplayError::InvalidFormat);
|
|
}
|
|
|
|
let bpp = bits[0]
|
|
.parse::<u32>()
|
|
.map_err(|_| DisplayError::InvalidBPP)?;
|
|
let fps = bits[1]
|
|
.parse::<u32>()
|
|
.map_err(|_| DisplayError::InvalidFPS)?;
|
|
Ok((width, height, bpp, fps))
|
|
}
|