Crate unicode_bidi [] [src]

This crate implements the Unicode Bidirectional Algorithm for display of mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the current stable release.

Example

use unicode_bidi::{process_text, reorder_line};

// This example text is defined using `concat!` because some browsers
// and text editors have trouble displaying bidi strings.
let text = concat!["א",
                   "ב",
                   "ג",
                   "a",
                   "b",
                   "c"];

// Resolve embedding levels within the text.  Pass `None` to detect the
// paragraph level automatically.
let info = process_text(&text, None);

// This paragraph has embedding level 1 because its first strong character is RTL.
assert_eq!(info.paragraphs.len(), 1);
let paragraph_info = &info.paragraphs[0];
assert_eq!(paragraph_info.level, 1);

// Re-ordering is done after wrapping each paragraph into a sequence of
// lines. For this example, I'll just use a single line that spans the
// entire paragraph.
let line = paragraph_info.range.clone();

let display = reorder_line(&text, line, &info.levels);
assert_eq!(display, concat!["a",
                            "b",
                            "c",
                            "ג",
                            "ב",
                            "א"]);

Modules

tables

Structs

BidiInfo

Output of process_text

InitialProperties

Output of initial_scan

ParagraphInfo

Info about a single paragraph

Enums

BidiClass

Represents values of the Unicode character property Bidi_Class, also known as the bidirectional character type.

Constants

UNICODE_VERSION

The Unicode version of data

Functions

bidi_class

Find the BidiClass of a single char.

initial_scan

Find the paragraphs and BidiClasses in a string of text.

is_ltr

Even embedding levels are left-to-right.

is_rtl

Odd levels are right-to-left.

process_text

Determine the bidirectional embedding levels for a single paragraph.

reorder_line

Re-order a line based on resolved levels.

visual_runs

Find the level runs within a line and return them in visual order.

Type Definitions

LevelRun

A maximal substring of characters with the same embedding level.