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

#49 in Text processing

Download history 1725860/week @ 2024-01-22 1842758/week @ 2024-01-29 1812212/week @ 2024-02-05 1790079/week @ 2024-02-12 1781033/week @ 2024-02-19 1880310/week @ 2024-02-26 1865386/week @ 2024-03-04 1836970/week @ 2024-03-11 1847584/week @ 2024-03-18 1802198/week @ 2024-03-25 1844091/week @ 2024-04-01 1866932/week @ 2024-04-08 1863420/week @ 2024-04-15 1916203/week @ 2024-04-22 1724523/week @ 2024-04-29 1746534/week @ 2024-05-06

7,360,842 downloads per month
Used in 26,196 crates (28 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–670KB
~10K SLoC