#unicode #rtl #unicode-text #layout #bidi #text

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

#1375 in Text processing

Download history 1248/week @ 2024-01-03 1274/week @ 2024-01-10 1367/week @ 2024-01-17 1150/week @ 2024-01-24 1224/week @ 2024-01-31 1277/week @ 2024-02-07 1076/week @ 2024-02-14 1090/week @ 2024-02-21 1236/week @ 2024-02-28 1323/week @ 2024-03-06 1015/week @ 2024-03-13 1422/week @ 2024-03-20 1323/week @ 2024-03-27 1324/week @ 2024-04-03 1308/week @ 2024-04-10 1181/week @ 2024-04-17

5,412 downloads per month
Used in 75 crates (3 directly)

MIT/Apache

135KB
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

~215KB