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", "ג", "ב", "א"]);
Reexports
pub use tables::{BidiClass, bidi_class, UNICODE_VERSION}; |
Modules
tables |
Structs
BidiInfo |
Output of |
InitialProperties |
Output of |
ParagraphInfo |
Info about a single paragraph |
Functions
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. |