#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum LineClass {
Open,
Close,
Exclam,
Infix,
NonStarter,
Inseparable,
Hyphen,
Slash,
Prefix,
Postfix,
Numeric,
Alpha,
Space,
Other,
}
pub(crate) fn line_class(ch: char) -> LineClass {
use LineClass::*;
match ch {
'「' | '『' | '(' | '(' | '[' | '[' | '{' | '{' | '〈' | '《' | '【' | '〔' | '〘'
| '〖' | '“' | '‘' | '〝' | '«' | '‹' | '⦅' | '「' => Open,
'」' | '』' | ')' | ')' | ']' | ']' | '}' | '}' | '〉' | '》' | '】' | '〕' | '〙'
| '〗' | '”' | '’' | '〟' | '»' | '›' | '⦆' | '」' => Close,
'!' | '?' | '!' | '?' | '‼' | '⁇' | '⁈' | '⁉' => Exclam,
'、' | '。' | ',' | '.' | ',' | '.' | '・' | ':' | ';' | ':' | ';' | '、' | '。'
| '・' => Infix,
'ー' | '~' | '〜' | '゠' | '‐' | '–' | '゛' | '゜' | 'ゝ' | 'ゞ' | 'ヽ' | 'ヾ' | '々'
| '〻' | 'ぁ' | 'ぃ' | 'ぅ' | 'ぇ' | 'ぉ' | 'っ' | 'ゃ' | 'ゅ' | 'ょ' | 'ゎ' | 'ゕ'
| 'ゖ' | 'ァ' | 'ィ' | 'ゥ' | 'ェ' | 'ォ' | 'ッ' | 'ャ' | 'ュ' | 'ョ' | 'ヮ' | 'ヵ'
| 'ヶ' | '\u{31F0}'..='\u{31FF}' | '\u{FF67}'..='\u{FF70}' | '\u{FF9E}' | '\u{FF9F}' => NonStarter,
'…' | '‥' | '―' | '─' | '—' | '⋯' => Inseparable,
'-' => Hyphen,
'/' => Slash,
'$' | '¥' | '£' | '€' | '₩' | '₹' | '₽' | '₺' | '₴' | '₱' | '₫' | '₪' | '฿' | '$'
| '¥' | '£' | '₩' | '№' => Prefix,
'%' | '‰' | '‱' | '°' | '′' | '″' | '℃' | '℉' | '¢' | '%' | '¢' => Postfix,
'0'..='9' => Numeric,
' ' => Space,
c if c.is_ascii_alphabetic() || (matches!(c as u32, 0xC0..=0x24F) && c.is_alphabetic()) => {
Alpha
}
_ => Other,
}
}
#[cfg(test)]
mod tests {
use super::*;
use LineClass::*;
#[test]
fn 分類の表() {
for (c, k) in [
('「', Open),
('«', Open),
('」', Close),
('〟', Close),
('!', Exclam),
('、', Infix),
(':', Infix),
('っ', NonStarter),
('〜', NonStarter),
('ァ', NonStarter),
('…', Inseparable),
('—', Inseparable),
('-', Hyphen),
('/', Slash),
('$', Prefix),
('¥', Prefix),
('%', Postfix),
('℃', Postfix),
('7', Numeric),
('é', Alpha),
(' ', Space),
('あ', Other),
('漢', Other),
('×', Other),
] {
assert_eq!(line_class(c), k, "{c}");
}
}
}