#unicode #unicode-text #rtl #bidi #layout #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

#1794 in Text processing

Download history 1232/week @ 2024-07-20 1154/week @ 2024-07-27 1037/week @ 2024-08-03 1781/week @ 2024-08-10 1833/week @ 2024-08-17 1356/week @ 2024-08-24 1561/week @ 2024-08-31 1216/week @ 2024-09-07 1378/week @ 2024-09-14 1433/week @ 2024-09-21 1133/week @ 2024-09-28 940/week @ 2024-10-05 1234/week @ 2024-10-12 1630/week @ 2024-10-19 959/week @ 2024-10-26 1050/week @ 2024-11-02

4,980 downloads per month
Used in 80 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

~205KB