Sign in

    moonucd

    Unicode character database for MoonBit: general category, bidi class, numeric type, binary properties, full case mapping and folding, generated from the UCD.

    unicode
    ucd
    case
    category
    moonbit
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    12 hours ago
    Downloads
    20

    No dependencies

    #moonucd

    The Unicode Character Database, queried from MoonBit: what kind of character something is, which properties it has, and how it changes case — for every code point of Unicode 17.0.0.

    @moonucd.category('Dž') // Lt
    @moonucd.has('中', Alphabetic) // true
    @moonucd.numeric('٣') // Some(Decimal)
    @moonucd.upper("straße") // "STRASSE"
    @moonucd.lower("ΟΔΟΣ") // "οδος"
    @moonucd.fold("Straße") == @moonucd.fold("STRASSE") // true

    moon add moonbitstack/moonucd

    #What a character is

    CallAnswers
    category(ch)its General_Category, one of 30 two-letter values; unassigned code points are Cn
    bidi(ch)its Bidi_Class, with the defaults Unicode gives unassigned code points
    numeric(ch)Decimal, Digit or Numeric for characters with a numeric value, else None
    has(ch, property)whether it has one of 44 binary properties: Alphabetic, Uppercase, Lowercase, Cased, CaseIgnorable, WhiteSpace, XidStart, XidContinue, Math, Dash, Ideographic, RegionalIndicator…

    #Changing case

    All four take a string and return a new one, because one character can become several.

    CallDoes
    upper(text)full uppercase mapping: ß becomes SS, ffi becomes FFI
    lower(text)full lowercase mapping; a capital sigma ending a word becomes ς
    title(text)each character to its titlecase form: dž becomes Dž; which characters start a word is the caller's call
    fold(text)full case folding, for comparing text without regard to case

    The mappings are the ones that hold in every language. Turkish and Lithuanian rules that depend on a locale are left to the caller.

    #Version

    version() returns "17.0.0". The tables are generated from the Unicode Character Database by scripts/gen_tables.py; a new Unicode release is a regeneration, not a code change.

    Runs on every MoonBit backend: native, wasm, wasm-gc and js.

    #Licence

    Apache-2.0.

    Bidi

    pub(all) enum Bidi {
    L
    R
    AL
    EN
    ES
    ET
    AN
    CS
    NSM
    BN
    B
    S
    WS
    ON
    LRE
    LRO
    RLE
    RLO
    PDF
    LRI
    RLI
    FSI
    PDI
    } derive(Eq)

    Bidi_Class.

    Bidi::equal

    fn Bidi::equal(Bidi, Bidi) -> Bool

    Bidi::not_equal

    fn Bidi::not_equal(x : Bidi, y : Bidi) -> Bool

    Category

    pub(all) enum Category {
    Lu
    Ll
    Lt
    Lm
    Lo
    Mn
    Mc
    Me
    Nd
    Nl
    No
    Pc
    Pd
    Ps
    Pe
    Pi
    Pf
    Po
    Sm
    Sc
    Sk
    So
    Zs
    Zl
    Zp
    Cc
    Cf
    Cs
    Co
    Cn
    } derive(Eq)

    General_Category.
    impl Show for Category

    Category::equal

    fn Category::equal(Category, Category) -> Bool

    Category::not_equal

    fn Category::not_equal(x : Category, y : Category) -> Bool

    Category::output

    fn Category::output(self : Category, logger : &Logger) -> Unit

    Category::to_string

    fn Category::to_string(self : Category) -> String

    Numeric

    pub(all) enum Numeric {
    Decimal
    Digit
    Numeric
    } derive(Eq)

    Numeric_Type, for characters that have one.

    Numeric::equal

    fn Numeric::equal(Numeric, Numeric) -> Bool

    Numeric::not_equal

    fn Numeric::not_equal(x : Numeric, y : Numeric) -> Bool

    Property

    pub(all) enum Property {
    Alphabetic
    Lowercase
    Uppercase
    Cased
    CaseIgnorable
    ChangesWhenLowercased
    ChangesWhenUppercased
    ChangesWhenTitlecased
    ChangesWhenCasefolded
    ChangesWhenCasemapped
    IdStart
    IdContinue
    XidStart
    XidContinue
    DefaultIgnorableCodePoint
    GraphemeExtend
    GraphemeBase
    Math
    WhiteSpace
    BidiControl
    JoinControl
    Dash
    Hyphen
    QuotationMark
    TerminalPunctuation
    HexDigit
    AsciiHexDigit
    Ideographic
    Diacritic
    Extender
    NoncharacterCodePoint
    IdsBinaryOperator
    IdsTrinaryOperator
    Radical
    UnifiedIdeograph
    Deprecated
    SoftDotted
    LogicalOrderException
    SentenceTerminal
    VariationSelector
    PatternWhiteSpace
    PatternSyntax
    PrependedConcatenationMark
    RegionalIndicator
    } derive(Eq)

    A binary property from PropList and DerivedCoreProperties.

    Property::equal

    fn Property::equal(Property, Property) -> Bool

    Property::not_equal

    fn Property::not_equal(x : Property, y : Property) -> Bool

    bidi

    fn bidi(ch : Char) -> Bidi

    The bidirectional class of ch, with the defaults the UCD assigns to unassigned code points.

    category

    fn category(ch : Char) -> Category

    The category of ch; unassigned code points are Cn.

    fold

    fn fold(text : StringView) -> String

    text case-folded with the full foldings, for caseless comparison.

    has

    fn has(ch : Char, property : Property) -> Bool

    Whether ch has property.

    lower

    fn lower(text : StringView) -> String

    text in lowercase, with the full mappings; a capital sigma at the end of a word becomes ς.

    numeric

    fn numeric(ch : Char) -> Numeric?

    The numeric type of ch; None for characters without a numeric value.

    title

    fn title(text : StringView) -> String

    Every character of text mapped to its titlecase form. Words are not found here: callers decide which characters start one.

    upper

    fn upper(text : StringView) -> String

    text in uppercase, with the full mappings: ß becomes SS.

    version

    fn version() -> String

    The version of the Unicode Character Database the tables come from.