ctb_formats_eite/util/
pred.rs1#[allow(
23 unused_imports,
24 clippy::wildcard_imports,
25 reason = "Standard workspace module prelude"
26)]
27use crate::utilities::*;
28
29use crate::{
30 encoding::ascii::byte_from_stagel_char, util::math::int_is_between_i32,
31};
32
33pub fn is_byte(v: i32) -> bool {
34 int_is_between_i32(v, 0, 255)
35}
36pub fn is_int_bit(v: i32) -> bool {
37 v == 0 || v == 1
38}
39pub fn is_char_byte(v: i32) -> bool {
40 int_is_between_i32(v, 32, 126)
41}
42
43pub fn is_char_str(s: &str) -> bool {
44 if s.chars().count() != 1 {
45 return false;
46 }
47 let Ok(b) = byte_from_stagel_char(s) else {
48 return false;
49 };
50 is_char_byte(i32::from(b))
51}
52
53pub fn is_valid_ident(s: &str) -> bool {
58 let mut chars = s.chars();
59 let Some(first) = chars.next() else {
60 return false;
61 };
62 if !first.is_ascii_lowercase() {
63 return false;
64 }
65 chars.all(|c| c.is_ascii_alphanumeric())
66}
67
68#[cfg(test)]
69#[allow(
70 clippy::panic,
71 clippy::expect_used,
72 clippy::unwrap_used,
73 clippy::unwrap_in_result,
74 clippy::panic_in_result_fn,
75 clippy::indexing_slicing,
76 clippy::arithmetic_side_effects,
77 reason = "Standard repository test boilerplate"
78)]
79mod tests {
80 use super::*;
81
82 #[crate::ctb_test]
83 fn test_ident_validation() {
84 assert!(is_valid_ident("abc1"));
85 assert!(!is_valid_ident("Abc"));
86 assert!(!is_valid_ident("a-b"));
87 }
88}