#rtl #unicode #text #layout #bidi

no-std unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

27 releases

new 0.3.13 Mar 20, 2023
0.3.10 Jan 20, 2023
0.3.8 Apr 26, 2022
0.3.7 Oct 7, 2021
0.2.0 Jul 23, 2015

#74 in Text processing

Download history 818223/week @ 2022-11-28 748112/week @ 2022-12-05 744104/week @ 2022-12-12 675215/week @ 2022-12-19 452884/week @ 2022-12-26 662040/week @ 2023-01-02 801068/week @ 2023-01-09 843013/week @ 2023-01-16 901664/week @ 2023-01-23 960540/week @ 2023-01-30 929935/week @ 2023-02-06 943640/week @ 2023-02-13 966684/week @ 2023-02-20 1004465/week @ 2023-02-27 1063066/week @ 2023-03-06 1007164/week @ 2023-03-13

4,106,697 downloads per month
Used in 17,407 crates (15 directly)

MIT/Apache

170KB
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–475KB