pub fn is_xdigit(ch: char) -> bool {
ch.is_ascii_hexdigit()
}
pub fn is_space(ch: char) -> bool {
ch.is_ascii_whitespace()
}
pub fn is_digit(ch: char) -> bool {
ch.is_ascii_digit()
}
pub fn is_csymf(ch: char) -> bool {
ch.is_ascii_alphabetic() || ch == '_' || (ch as u8) >= 128
}
pub fn is_csym(ch: char) -> bool {
ch.is_ascii_alphanumeric() || ch == '_'
}
pub fn hex_digit_to_val(ch: char) -> u8 {
match ch {
'0'..='9' => (ch as u8) - b'0',
'A'..='F' => (ch as u8) - b'A' + 10,
'a'..='f' => (ch as u8) - b'a' + 10,
_ => 0,
}
}
pub fn stricmp(s1: &str, s2: &str) -> i32 {
match s1.to_uppercase().cmp(&s2.to_uppercase()) {
std::cmp::Ordering::Less => -1,
std::cmp::Ordering::Equal => 0,
std::cmp::Ordering::Greater => 1,
}
}
pub fn is_empty(s: &str) -> bool {
s.trim().is_empty()
}
pub fn expand_tabs(line: &str, tab_size: usize) -> String {
let mut result = String::new();
let mut col = 0;
for ch in line.chars() {
if ch == '\t' {
let spaces_to_add = tab_size - (col % tab_size);
result.push_str(&" ".repeat(spaces_to_add));
col += spaces_to_add;
} else {
result.push(ch);
col += 1;
}
}
result
}