package

github.com/dsisnero/bidi

0.5.0 / published May 19, 2026 / repository

This crate implements the [Unicode Bidirectional Algorithm][tr9] for display of

bidi

Crystal port of the Rust unicode-bidi crate (v0.3.18) — Unicode Bidirectional Algorithm implementation for mixed RTL/LTR text display.

Build Status License


Quick Start

git clone https://github.com/dsisnero/bidi.git
cd bidi
git submodule update --init
make install
make test

Example

require "bidi"

text = "Hello שלום"  # Mixed LTR/RTL text
info = Bidi::BidiInfo.new(text, nil)

para = info.paragraphs[0]
reordered = info.reorder_line(para, para.range)
puts reordered  # "Hello םולש"

# Single paragraph API
info = Bidi::ParagraphBidiInfo.new(text, nil)
puts info.reorder_line(0...text.bytesize)

# Base direction detection
puts Bidi.get_base_direction("Hello")  # Ltr
puts Bidi.get_base_direction("שלום")   # Rtl

API

Rust APICrystalStatus
BidiInfoBidi::BidiInfo
ParagraphBidiInfoBidi::ParagraphBidiInfo
UTF16::BidiInfoBidi::UTF16::BidiInfo
UTF16::ParagraphBidiInfoBidi::UTF16::ParagraphBidiInfo
LevelBidi::Level
BidiClassBidi::BidiClass
DirectionBidi::Direction
get_base_directionBidi.get_base_direction
reorder_visualBidi::BidiInfo.reorder_visual

Source Map

Rust (vendor/unicode-bidi/src/)Crystal (src/bidi/)
char_data/mod.rs, tables.rschar_data.cr, char_data/tables.cr, char_data/tables_data.cr
level.rslevel.cr
format_chars.rsformat_chars.cr
data_source.rsdata_source.cr
explicit.rsexplicit.cr
prepare.rsprepare.cr
implicit.rsimplicit.cr
lib.rsinfo.cr, bidi_info_common.cr
utf16.rsutf16.cr
deprecated.rs(not ported)

Development

make install    # Install dependencies (shards install)
make update     # Update dependencies (shards update)
make format     # Format code (crystal tool format)
make lint       # Lint code (format check + ameba)
make test       # Run tests (crystal spec)
make clean      # Clean build artifacts

Documentation

DocumentPurpose
ArchitectureSystem design, data flow, type mappings
DevelopmentSetup, workflow, debugging
Coding GuidelinesCode style, error handling, naming
TestingTest commands, spec file layout
ExamplesUsage examples for common scenarios
PR WorkflowCommits, PRs, review process
Parity TrackerPort status, feature checklist, work plan

Test Status

SuiteCountPassFailErrorsPending
Full spec123123000
Unit tests (make test)9292000
Rust upstream tests4242000
Parity manifest checks330

Upstream

License

MIT — see LICENSE.

API