#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum GeneralCategory {
UppercaseLetter = 0,
LowercaseLetter,
TitlecaseLetter,
ModifierLetter,
OtherLetter,
NonspacingMark,
SpacingMark,
EnclosingMark,
DecimalNumber,
LetterNumber,
OtherNumber,
ConnectorPunctuation,
DashPunctuation,
OpenPunctuation,
ClosePunctuation,
InitialPunctuation,
FinalPunctuation,
OtherPunctuation,
MathSymbol,
CurrencySymbol,
ModifierSymbol,
OtherSymbol,
SpaceSeparator,
LineSeparator,
ParagraphSeparator,
Control,
Format,
Surrogate,
PrivateUse,
Unassigned,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum Group {
Letter,
Mark,
Number,
Punctuation,
Symbol,
Separator,
Other,
}
impl GeneralCategory {
#[inline]
#[must_use]
pub const fn group(self) -> Group {
use GeneralCategory::*;
match self {
UppercaseLetter | LowercaseLetter | TitlecaseLetter | ModifierLetter | OtherLetter => {
Group::Letter
}
NonspacingMark | SpacingMark | EnclosingMark => Group::Mark,
DecimalNumber | LetterNumber | OtherNumber => Group::Number,
ConnectorPunctuation | DashPunctuation | OpenPunctuation | ClosePunctuation
| InitialPunctuation | FinalPunctuation | OtherPunctuation => Group::Punctuation,
MathSymbol | CurrencySymbol | ModifierSymbol | OtherSymbol => Group::Symbol,
SpaceSeparator | LineSeparator | ParagraphSeparator => Group::Separator,
Control | Format | Surrogate | PrivateUse | Unassigned => Group::Other,
}
}
#[inline]
#[must_use]
pub const fn abbr(self) -> &'static str {
use GeneralCategory::*;
match self {
UppercaseLetter => "Lu",
LowercaseLetter => "Ll",
TitlecaseLetter => "Lt",
ModifierLetter => "Lm",
OtherLetter => "Lo",
NonspacingMark => "Mn",
SpacingMark => "Mc",
EnclosingMark => "Me",
DecimalNumber => "Nd",
LetterNumber => "Nl",
OtherNumber => "No",
ConnectorPunctuation => "Pc",
DashPunctuation => "Pd",
OpenPunctuation => "Ps",
ClosePunctuation => "Pe",
InitialPunctuation => "Pi",
FinalPunctuation => "Pf",
OtherPunctuation => "Po",
MathSymbol => "Sm",
CurrencySymbol => "Sc",
ModifierSymbol => "Sk",
OtherSymbol => "So",
SpaceSeparator => "Zs",
LineSeparator => "Zl",
ParagraphSeparator => "Zp",
Control => "Cc",
Format => "Cf",
Surrogate => "Cs",
PrivateUse => "Co",
Unassigned => "Cn",
}
}
#[inline]
#[must_use]
pub const fn is_letter(self) -> bool {
matches!(self.group(), Group::Letter)
}
#[inline]
#[must_use]
pub const fn is_cased_letter(self) -> bool {
use GeneralCategory::*;
matches!(self, UppercaseLetter | LowercaseLetter | TitlecaseLetter)
}
#[inline]
#[must_use]
pub const fn is_mark(self) -> bool {
matches!(self.group(), Group::Mark)
}
#[inline]
#[must_use]
pub const fn is_number(self) -> bool {
matches!(self.group(), Group::Number)
}
#[inline]
#[must_use]
pub const fn is_punctuation(self) -> bool {
matches!(self.group(), Group::Punctuation)
}
#[inline]
#[must_use]
pub const fn is_symbol(self) -> bool {
matches!(self.group(), Group::Symbol)
}
#[inline]
#[must_use]
pub const fn is_separator(self) -> bool {
matches!(self.group(), Group::Separator)
}
#[inline]
#[must_use]
pub const fn is_other(self) -> bool {
matches!(self.group(), Group::Other)
}
#[inline]
#[must_use]
pub const fn is_assigned(self) -> bool {
!matches!(self, GeneralCategory::Unassigned)
}
}