#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

#16 in Internationalization (i18n)

Download history 57315/week @ 2019-01-23 56352/week @ 2019-01-30 63584/week @ 2019-02-06 61580/week @ 2019-02-13 62647/week @ 2019-02-20 68311/week @ 2019-02-27 64637/week @ 2019-03-06 64979/week @ 2019-03-13 59125/week @ 2019-03-20 58174/week @ 2019-03-27 65451/week @ 2019-04-03 67029/week @ 2019-04-10 57192/week @ 2019-04-17 59770/week @ 2019-04-24 58796/week @ 2019-05-01

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