#unicode #unic #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

#1707 in Text processing

Download history 1551/week @ 2024-04-15 1206/week @ 2024-04-22 1089/week @ 2024-04-29 1168/week @ 2024-05-06 1255/week @ 2024-05-13 1198/week @ 2024-05-20 1327/week @ 2024-05-27 1154/week @ 2024-06-03 1185/week @ 2024-06-10 1268/week @ 2024-06-17 1226/week @ 2024-06-24 769/week @ 2024-07-01 1239/week @ 2024-07-08 1136/week @ 2024-07-15 1304/week @ 2024-07-22 1080/week @ 2024-07-29

4,826 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

~210KB