#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

#1491 in Text processing

Download history 1586/week @ 2023-12-04 2148/week @ 2023-12-11 1384/week @ 2023-12-18 1077/week @ 2023-12-25 1145/week @ 2024-01-01 1260/week @ 2024-01-08 1276/week @ 2024-01-15 1296/week @ 2024-01-22 1175/week @ 2024-01-29 1383/week @ 2024-02-05 1015/week @ 2024-02-12 1200/week @ 2024-02-19 1111/week @ 2024-02-26 1273/week @ 2024-03-04 1154/week @ 2024-03-11 1222/week @ 2024-03-18

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