1 unstable release
new 0.3.17 | Nov 4, 2024 |
---|
#6 in #rtl
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.
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 makeunicode_bidi
#![no_std]
+alloc
compatible.hardcoded-data
: Enabled by default. Includes hardcoded Unicode bidi data and more convenient APIs.serde
: Addsserde::Serialize
andserde::Deserialize
implementations to relevant types.
Dependencies
~0–590KB