#rtl #unicode #text #layout #bidi

no-std unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

21 releases

0.3.7 Oct 7, 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

#55 in Encoding

Download history 445107/week @ 2021-09-27 483696/week @ 2021-10-04 518804/week @ 2021-10-11 513917/week @ 2021-10-18 496290/week @ 2021-10-25 515168/week @ 2021-11-01 504792/week @ 2021-11-08 508576/week @ 2021-11-15 440733/week @ 2021-11-22 520258/week @ 2021-11-29 522810/week @ 2021-12-06 515760/week @ 2021-12-13 390105/week @ 2021-12-20 306622/week @ 2021-12-27 482948/week @ 2022-01-03 509819/week @ 2022-01-10

1,730,790 downloads per month
Used in 10,739 crates (10 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–425KB

G _a