#text #unicode #bidi #rtl #layout

unic-bidi

UNIC — Unicode Bidirectional Algorithm

8 releases (breaking)

0.9.0 Mar 3, 2019
0.8.0 Jan 2, 2019
0.7.0 Feb 7, 2018
0.6.0 Sep 22, 2017
0.1.0 Jun 20, 2017

#11 in #layout

Download history 1232/week @ 2021-01-13 816/week @ 2021-01-20 1353/week @ 2021-01-27 1653/week @ 2021-02-03 1861/week @ 2021-02-10 2467/week @ 2021-02-17 1148/week @ 2021-02-24 1882/week @ 2021-03-03 2269/week @ 2021-03-10 2606/week @ 2021-03-17 2205/week @ 2021-03-24 2020/week @ 2021-03-31 1524/week @ 2021-04-07 1622/week @ 2021-04-14 1262/week @ 2021-04-21 1744/week @ 2021-04-28

5,997 downloads per month
Used in 23 crates (4 directly)

MIT/Apache

130KB
2.5K SLoC

UNIC — Unicode Bidirectional Algorithm

Crates.io Documentation

This UNIC component implements algorithms from Unicode® Standard Annex #9 - Unicode Bidirectional Algorithm, a.k.a. UBA, used for display of mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the current stable release.

Notes

Initial code for this component is based on unicode-bidi.


lib.rs:

UNIC — Unicode Bidirectional Algorithm

A component of unic: Unicode and Internationalization Crates for Rust.

This UNIC component implements algorithms from Unicode Standard Annex #9 - Unicode Bidirectional Algorithm, a.k.a. UBA, used 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 unic_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

~220KB