#rtl #unicode #text #layout #bidi

no-std unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

22 releases

0.3.8 Apr 26, 2022
0.3.7 Oct 7, 2021
0.3.6 Aug 13, 2021
0.3.5 Apr 6, 2021
0.2.0 Jul 23, 2015

#64 in Encoding

Download history 601563/week @ 2022-04-20 635682/week @ 2022-04-27 640834/week @ 2022-05-04 607419/week @ 2022-05-11 641626/week @ 2022-05-18 537875/week @ 2022-05-25 616861/week @ 2022-06-01 655322/week @ 2022-06-08 642304/week @ 2022-06-15 620094/week @ 2022-06-22 625823/week @ 2022-06-29 651781/week @ 2022-07-06 687862/week @ 2022-07-13 692826/week @ 2022-07-20 714134/week @ 2022-07-27 708036/week @ 2022-08-03

2,925,683 downloads per month
Used in 13,558 crates (12 directly)

MIT/Apache

135KB
2.5K 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

# #[cfg(feature = "hardcoded-data")] {
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",
  "ג",
  "ב",
  "א",
]);
# } // feature = "hardcoded-data"

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–410KB