Sign in

    moonucd

    The Unicode Character Database for MoonBit.

    unicode
    ucd
    moonbit
    Download zip
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    189

    No dependencies

    moonucd

    moon add moonbitstack/moonucd

    @moonucd.category('Dž') // Lt
    @moonucd.upper("straße") // "STRASSE"
    @moonucd.fold("Straße") == @moonucd.fold("STRASSE") // true
    @name.name('中') // Some("CJK UNIFIED IDEOGRAPH-4E2D")
    @width.text_width("Hello 世界") // 10
    @segment.grapheme_clusters("🇨🇳e\u{301}!") // ["🇨🇳", "é", "!"]
    @linebreak.linebreaks("The quick 中文 fox") // ["The ", "quick ", "中", "文 ", "fox"]

    #Packages

    The root package holds the general character facts. The other eight carry their own tables, so a program links only the tables of the packages it imports.

    Every function is pure and runs on native, wasm, wasm-gc and js. Offsets into strings are UTF-16 code units, the index MoonBit strings use.

    #A few more

    @moonucd.has('_', XidContinue) // true
    @moonucd.lower("ΣΟΦΟΣ ΣΟΦΟΣ") // "σοφος σοφος"
    @age.age('€') // Some((2, 1))
    @block.range("Greek") // Some(('\u{370}', '\u{3FF}'))
    @name.lookup("copyright sign") // Some('©')
    @script.extensions('ー') // [Hiragana, Katakana]
    @normalize.normalize(NFKC, "hello") // "hello"
    @normalize.decomposition('½') // "<fraction> 0031 2044 0032"
    @width.width('α', ambiguous=2) // 2
    @segment.word_at("hello, world", 9) // (7, 12)
    @linebreak.breaks("one two\nthree") // [(4, false), (8, true)]

    The guide walks through every package; the API reference lists every function and type.

    #Examples

    ExampleShows
    01-tourcategory, numeric type, binary properties, case
    02-scriptsscript, extensions, Script::of
    03-widthwidth, east_asian_width, text_width
    04-normalizenormalize, is_normalized, decomposition
    05-segmentgrapheme_clusters, words, sentences
    06-linebreaklinebreaks, lb_property
    07-terminalwrapping and truncating text by terminal cells

    moon run src/examples/07-terminal

    #Tables

    Every table is generated from the Unicode Character Database by the scripts in scripts/tables. Every package reports the version in version(), and a new Unicode version is a regeneration that leaves the interfaces as they are.

    #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.
    impl Show for Bidi

    Bidi::equal

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

    Bidi::not_equal

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

    Bidi::output

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

    Bidi::to_string

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

    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
    Emoji
    EmojiPresentation
    EmojiModifier
    EmojiModifierBase
    EmojiComponent
    ExtendedPictographic
    } derive(Eq)

    A binary property from PropList, DerivedCoreProperties and emoji-data.

    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.