use std::sync::LazyLock;
use regex::Regex;
static WORD_CHAR: LazyLock<Regex> = LazyLock::new(|| {
#[allow(clippy::unwrap_used)]
Regex::new(r"^\w$").unwrap()
});
pub(crate) fn is_word_char(c: char) -> bool {
let mut buf = [0u8; 4];
WORD_CHAR.is_match(c.encode_utf8(&mut buf))
}
#[cfg(test)]
mod tests {
use super::is_word_char;
#[test]
fn ascii_word_chars() {
assert!(is_word_char('a'));
assert!(is_word_char('Z'));
assert!(is_word_char('0'));
assert!(is_word_char('_'));
}
#[test]
fn unicode_letters_and_digits() {
assert!(is_word_char('é'));
assert!(is_word_char('س'));
assert!(is_word_char('中'));
assert!(is_word_char('٣')); }
#[test]
fn marks_and_join_controls() {
assert!(is_word_char('\u{0301}')); assert!(is_word_char('\u{200c}')); assert!(is_word_char('\u{200d}')); }
#[test]
fn non_word_chars() {
assert!(!is_word_char(' '));
assert!(!is_word_char('-'));
assert!(!is_word_char('#'));
assert!(!is_word_char(':'));
assert!(!is_word_char('^'));
}
}