bidi

Unicode Bidirectional Algorithm for MoonBit

unicode
bidi
uax9
rtl
moon add tonyfettes/bidi@0.4.0
Download zip
Version
0.4.0
License
Apache-2.0
Last updated
last month
Downloads
7
README

#bidi

Unicode Bidirectional Algorithm implementation for MoonBit, targeting UAX #9 and Unicode 16.0.0.

moon add tonyfettes/bidi

See the repository root README for API documentation and examples.

#
BidiError

pub(all) suberror BidiError {
InvalidIsolate(String)
StackOverflow
}

Error types for Bidi processing

#
BidiClass

pub(all) enum BidiClass {
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)

All 23 Bidi_Class values from UAX #9
impl Show for BidiClass

#
BidiClass::is_explicit

fn BidiClass::is_explicit(self : BidiClass) -> Bool

#
BidiClass::is_isolate_initiator

fn BidiClass::is_isolate_initiator(self : BidiClass) -> Bool

#
BidiClass::is_neutral

fn BidiClass::is_neutral(self : BidiClass) -> Bool

#
BidiClass::is_neutral_or_isolate

fn BidiClass::is_neutral_or_isolate(self : BidiClass) -> Bool

#
BidiClass::is_strong

fn BidiClass::is_strong(self : BidiClass) -> Bool

#
BidiClass::is_strong_rtl

fn BidiClass::is_strong_rtl(self : BidiClass) -> Bool

#
BidiClass::is_weak

fn BidiClass::is_weak(self : BidiClass) -> Bool

#
BidiClass::is_x9_removed

fn BidiClass::is_x9_removed(self : BidiClass) -> Bool

#
BidiParagraph

pub(all) struct BidiParagraph {
chars : Array[Char]
original_classes : Array[BidiClass]
resolved_classes : Array[BidiClass]
levels : Array[Int]
base_level : Int
}

Result of bidi processing - a paragraph with resolved levels

#
Direction

pub(all) enum Direction {
LTR
RTL
} derive(Eq)

Direction of text
impl Show for Direction

#
Direction::level

fn Direction::level(self : Direction) -> Int

Get embedding level for direction

#
bidi_class

fn bidi_class(c : Char) -> BidiClass

Look up Bidi_Class for a character

#
detect_direction

fn detect_direction(text : String) -> Direction

Detect the base direction of text (P2-P3) Returns the direction of the first strong character, or LTR if no strong character is found

#
direction_from_level

fn direction_from_level(level : Int) -> Direction

Get direction from embedding level

#
get_mirrored

fn get_mirrored(c : Char, level : Int) -> Char

Get the mirrored glyph for a character if in RTL context

#
process

fn process(text : String, direction? : Direction) -> BidiParagraph

Process text according to the Unicode Bidirectional Algorithm If direction is omitted, infer it from the first strong character. Returns a BidiParagraph with resolved embedding levels for each character

#
process_with_base_level

#deprecated("Use process(text, direction=LTR or RTL) instead")
fn process_with_base_level(text : String, base_level : Int) -> BidiParagraph

Process text with explicit base level

#
process_with_direction

#deprecated("Use process(text, direction=direction) instead")
fn process_with_direction(text : String, direction : Direction) -> BidiParagraph

Process text with explicit base direction Use when the paragraph direction is known externally

#
reorder

fn reorder(para : BidiParagraph) -> Array[Int]

Reorder text for display according to resolved levels Returns array of character indices in visual order X9-removed characters (LRE, RLE, LRO, RLO, PDF, BN) are excluded

#
reorder_string

fn reorder_string(para : BidiParagraph) -> String

Reorder text and return the visually-ordered string

#
requires_bidi

fn requires_bidi(text : String) -> Bool

Check if text requires bidi processing Returns false for pure LTR text (optimization)

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io