ctoolbox/formats/eite/util/
pred.rs1use crate::formats::eite::{
4 encoding::ascii::byte_from_stagel_char, util::math::int_is_between_i32,
5};
6
7pub fn is_byte(v: i32) -> bool {
8 int_is_between_i32(v, 0, 255)
9}
10pub fn is_int_bit(v: i32) -> bool {
11 v == 0 || v == 1
12}
13pub fn is_char_byte(v: i32) -> bool {
14 int_is_between_i32(v, 32, 126)
15}
16
17pub fn is_char_str(s: &str) -> bool {
18 if s.chars().count() != 1 {
19 return false;
20 }
21 let b = byte_from_stagel_char(s);
22 if let Err(_) = b {
23 return false;
24 }
25 is_char_byte(i32::from(b.unwrap()))
26}
27
28pub fn is_valid_ident(s: &str) -> bool {
33 if s.is_empty() {
34 return false;
35 }
36 let mut chars = s.chars();
37 let first = chars.next().unwrap();
38 if !first.is_ascii_lowercase() {
39 return false;
40 }
41 chars.all(|c| c.is_ascii_alphanumeric())
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[crate::ctb_test]
49 fn test_ident_validation() {
50 assert!(is_valid_ident("abc1"));
51 assert!(!is_valid_ident("Abc"));
52 assert!(!is_valid_ident("a-b"));
53 }
54}