Update stuff

This commit is contained in:
2026-06-07 01:12:42 +02:00
parent 35e020c62e
commit e01ce0a570
5 changed files with 302 additions and 24 deletions
+44
View File
@@ -0,0 +1,44 @@
use core::f32;
use core::str::{self, FromStr};
pub struct Parser {
pub curr: u32,
pub buffer: [u8; 100],
}
impl Parser {
pub fn new() -> Self {
Self {
curr: 0,
buffer: [0_u8; 100],
}
}
pub fn input_byte(&mut self, b: u8) -> Option<u32> {
if b == b'\n' || b == b'\r' {
let mut split = self.buffer.split(|num| {
num == &(u8::try_from(',').unwrap())
|| num == &(u8::try_from(' ').unwrap())
|| num == &0
}); // TODO: the use \0 and ' ' as split is kinda hacky
let buf = split.next()?;
let ret = if buf.contains(&b'.') {
Some((4095f32 / 3.3 * f32::from_str(str::from_utf8(buf).ok()?).ok()?) as u32)
} else {
Some(u32::from_str(str::from_utf8(buf).ok()?).ok()?)
};
for i in 0..self.curr {
self.buffer[i as usize] = 0;
}
self.curr = 0;
ret
} else {
self.buffer[self.curr as usize] = b;
self.curr += 1;
None
}
}
}