use alloc::string::String;
use alloc::vec::Vec;
pub fn path_check(path: &str, is_goal: &mut bool) -> usize {
for (i, c) in path.chars().enumerate() {
if i >= 255 {
break;
}
if c == '/' {
*is_goal = false;
return i;
}
if c == '\0' {
*is_goal = true;
return i;
}
}
*is_goal = true;
path.len()
}
#[cfg(test)]
mod path_tests {
use super::*;
#[test]
fn test_ext4_path_check() {
let mut is_goal = false;
assert_eq!(path_check("/", &mut is_goal), 0);
assert!(!is_goal, "Root path should not set is_goal to true");
assert_eq!(path_check("/home/user/file.txt", &mut is_goal), 0);
assert!(!is_goal, "Normal path should not set is_goal to true");
let path = "file.txt";
assert_eq!(path_check(path, &mut is_goal), path.len());
assert!(is_goal, "Path without slashes should set is_goal to true");
let path = "home\0";
assert_eq!(path_check(path, &mut is_goal), 4);
assert!(
is_goal,
"Path with null character should set is_goal to true"
);
}
}