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

no-std unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

29 releases

0.3.15 Jan 17, 2024
0.3.14 Dec 6, 2023
0.3.13 Mar 20, 2023
0.3.8 Apr 26, 2022
0.2.0 Jul 23, 2015

#55 in Text processing

Download history 1517624/week @ 2023-12-07 1418176/week @ 2023-12-14 936454/week @ 2023-12-21 1082430/week @ 2023-12-28 1465131/week @ 2024-01-04 1507159/week @ 2024-01-11 1801007/week @ 2024-01-18 1719999/week @ 2024-01-25 1849626/week @ 2024-02-01 1805863/week @ 2024-02-08 1757247/week @ 2024-02-15 1847074/week @ 2024-02-22 1917297/week @ 2024-02-29 1828939/week @ 2024-03-07 1842416/week @ 2024-03-14 1547794/week @ 2024-03-21

7,460,233 downloads per month
Used in 25,436 crates (24 directly)

MIT/Apache

240KB
4K SLoC

unicode-bidi

This crate implements the Unicode Bidirectional Algorithm for display of mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the current stable release.

Documentation

CI AppVeyor


lib.rs:

This crate implements the Unicode Bidirectional Algorithm 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 unicode_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",
  "ג",
  "ב",
  "א",
]);

Features

  • std: Enabled by default, but can be disabled to make unicode_bidi #![no_std] + alloc compatible.
  • hardcoded-data: Enabled by default. Includes hardcoded Unicode bidi data and more convenient APIs.
  • serde: Adds serde::Serialize and serde::Deserialize implementations to relevant types.

Dependencies

~0–680KB
~11K SLoC