#rtl #unicode #text #layout #bidi

unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

19 releases

0.3.5 Apr 6, 2021
0.3.4 Jul 6, 2017
0.3.3 May 29, 2017
0.2.5 Feb 10, 2017
0.2.0 Jul 23, 2015

#32 in Algorithms

Download history 151381/week @ 2020-12-25 211491/week @ 2021-01-01 254222/week @ 2021-01-08 234437/week @ 2021-01-15 260626/week @ 2021-01-22 261694/week @ 2021-01-29 260460/week @ 2021-02-05 265472/week @ 2021-02-12 286222/week @ 2021-02-19 287826/week @ 2021-02-26 273220/week @ 2021-03-05 286038/week @ 2021-03-12 282877/week @ 2021-03-19 303159/week @ 2021-03-26 301453/week @ 2021-04-02 288829/week @ 2021-04-09

1,152,647 downloads per month
Used in 8,458 crates (6 directly)

MIT/Apache

120KB
2K SLoC

unicode-bidi

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.

Documentation

Travis-CI AppVeyor


lib.rs:

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::BidiInfo;

// 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 bidi_info = BidiInfo::new(&text, None);

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

// 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 = para.range.clone();

let display = bidi_info.reorder_line(para, line);
assert_eq!(display, concat![
  "a",
  "b",
  "c",
  "ג",
  "ב",
  "א",
]);

Dependencies

~3–440KB