#rtl #unicode #text #layout #bidi

unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

18 releases

0.3.4 Jul 6, 2017
0.2.6 May 17, 2017
0.2.5 Feb 10, 2017
0.2.4 Dec 19, 2016
0.2.0 Jul 23, 2015

#4 in Text processing

Download history 32567/week @ 2018-07-23 34237/week @ 2018-07-30 38494/week @ 2018-08-06 36728/week @ 2018-08-13 34978/week @ 2018-08-20 36101/week @ 2018-08-27 37710/week @ 2018-09-03 40838/week @ 2018-09-10 41932/week @ 2018-09-17 41028/week @ 2018-09-24 41212/week @ 2018-10-01 43484/week @ 2018-10-08 43830/week @ 2018-10-15

125,525 downloads per month
Used in 2,535 crates (2 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

~1MB
~11K SLoC