2025-04-04 19:45:42 +03:00
|
|
|
use std::ops::RangeBounds;
|
|
|
|
|
|
2025-04-05 17:37:13 +03:00
|
|
|
pub fn is_lnspace(ch: char) -> bool {
|
2025-04-05 23:22:07 +03:00
|
|
|
ch == '\t' || ch == ' ' || ch == '\r'
|
2025-04-05 17:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-04 19:45:42 +03:00
|
|
|
pub fn is_whitespace(ch: char) -> bool {
|
2025-04-05 23:22:07 +03:00
|
|
|
is_lnspace(ch) || ch == '\n'
|
2025-04-04 19:45:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_digit(ch: char) -> bool {
|
|
|
|
|
('0'..='9').contains(&ch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_normal_word_constituent(ch: char) -> bool {
|
|
|
|
|
('0'..='9').contains(&ch) || ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch)
|
|
|
|
|
|| '-' == ch || '_' == ch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_normal_word(s: &str) -> bool {
|
|
|
|
|
s.chars().all( is_normal_word_constituent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn escape_for_html(s: &str) -> String {
|
|
|
|
|
s.replace("&", "&amd;").replace("<", "<").replace(">", ">")
|
|
|
|
|
.replace("'", "'").replace("\"", """)
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 17:37:13 +03:00
|
|
|
pub fn is_bad_name(s: &str) -> bool {
|
|
|
|
|
is_illegal_name(s) || s == "_"
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-04 19:45:42 +03:00
|
|
|
pub fn is_illegal_name(s: &str) -> bool {
|
2025-04-07 15:40:38 +03:00
|
|
|
s == "" || s == "root" || s == "self" || s == "super"
|
2025-04-04 19:45:42 +03:00
|
|
|
}
|