moonucdUnicode for MoonBit

Interactive · the algorithms, on your text

The sorting office

A string arrives as a parcel. Behind these four desks the compiled moonucd opens it: it presses the text into a normalization form, sorts it into grapheme clusters, words and sentences, measures it in terminal cells, cuts it where a line may break, and files every character under its case forms. Nothing below is a re-implementation — every number and every glyph comes from the library's own tables, running as JavaScript in this page.

The parcel

Type something

Up to 80 code points. Emoji, combining marks and right-to-left text are all fair game.

Code points
—
UTF-16 units
—
Grapheme clusters
—
Cells
—
Break chances
—
Words
—

Desk one

The press

Normalization is a press with three plates: decompose every character, put the marks in canonical order, then compose what may be composed. The same text can look identical and be different — é as one code point or as e and a combining acute. Run the plates and see which characters move.

As written
Decomposed, canonically ordered
NFC

Desk two

The belt

A terminal, a cursor and a line wrapper all count in cells, and they may only cut between grapheme clusters: a flag, an emoji sequence and a letter with its accents are one cluster each. The belt is drawn at one character per cell, so what you see is what a terminal would give the text.

Grapheme clusters
Words
Sentences

Hover a tile for the code point and the property the boundary was drawn from.

Desk three

The guillotine

UAX #14 says where a line may end. Each cut below is a rule from that algorithm: a dashed perforation may break, a solid one must. The pair of classes on each side is what the rule looked at.

may break must break no break
20 cells

Desk four

The case rack

Every character is filed under six answers: the full uppercase, lowercase and titlecase mappings, which may turn one character into several; the simple ones, one character in and one out; the full fold used to compare without case; and the class the simple fold joins, which is how a matcher closes a set under case without walking the code space.

A dash means the mapping changes nothing. The orbit is the whole class, itself included.

Under the counter

What the page calls

The whole page is two calls into the compiled library: inspect(cp) for the character dossier on the home page, and analyse(text) for everything here — clusters, offsets, widths, break classes, the four normalizations and the case forms, as one JSON object.

// the glue in src/examples/browser, built to docs/engine/moonucd.js
pub fn analyse(text : String) -> String