30 releases

0.3.17 Oct 2, 2024
0.3.15 Jan 17, 2024
0.3.14 Dec 6, 2023
0.3.13 Mar 20, 2023
0.2.0 Jul 23, 2015

#11 in Text processing

Download history 2009304/week @ 2024-07-21 1989846/week @ 2024-07-28 2024161/week @ 2024-08-04 2096130/week @ 2024-08-11 2032376/week @ 2024-08-18 2040619/week @ 2024-08-25 2044624/week @ 2024-09-01 2045136/week @ 2024-09-08 1930951/week @ 2024-09-15 2190964/week @ 2024-09-22 2450315/week @ 2024-09-29 2983113/week @ 2024-10-06 2939752/week @ 2024-10-13 2716934/week @ 2024-10-20 2275722/week @ 2024-10-27 2005222/week @ 2024-11-03

10,272,920 downloads per month
Used in 7,255 crates (28 directly)

MIT/Apache

245KB
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–710KB
~11K SLoC