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 Rust 1.0 and later.

Example

use unicode_bidi::{process_paragraph, reorder_line};

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

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

// This paragraph has embedding level 1 because its first strong character is RTL.
assert_eq!(info.para_level, 1);

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

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

Reexports

pub use tables::{BidiClass, bidi_class, UNICODE_VERSION};

Modules

tables

Structs

InitialProperties

Output of initial_scan

ParagraphInfo

Output of process_paragraph

Functions

initial_scan

Find the paragraph embedding level, and the BidiClass for each character.

is_ltr

Even embedding levels are left-to-right.

is_rtl

Odd levels are right-to-left.

process_paragraph

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.