#rtl #unicode #text #layout #bidi

no-std unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

20 releases

0.3.6 Aug 13, 2021
0.3.5 Apr 6, 2021
0.3.4 Jul 6, 2017
0.2.5 Feb 10, 2017
0.2.0 Jul 23, 2015

#20 in No standard library

Download history 307092/week @ 2021-05-31 333596/week @ 2021-06-07 339210/week @ 2021-06-14 337961/week @ 2021-06-21 333458/week @ 2021-06-28 327032/week @ 2021-07-05 327386/week @ 2021-07-12 336777/week @ 2021-07-19 357919/week @ 2021-07-26 367058/week @ 2021-08-02 390286/week @ 2021-08-09 451054/week @ 2021-08-16 418254/week @ 2021-08-23 415066/week @ 2021-08-30 402249/week @ 2021-09-06 429683/week @ 2021-09-13

1,440,614 downloads per month
Used in 9,826 crates (7 directly)

MIT/Apache

120KB
2K 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

Travis-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.
  • serde: Adds [serde::Serialize] and [serde::Deserialize] implementations to relevant types.

Dependencies

~0–455KB