#arabic #persian #turkish #reshape #no-std #line-string #default-config

no-std ar-reshaper

A no-std crate to reconstruct Arabic, turkish and persian sentences to be used in applications that don't support Arabic script

14 releases (5 stable)

1.5.0 Jan 20, 2024
1.3.1 Oct 31, 2023
1.0.0 Aug 23, 2023
0.3.4 Jun 19, 2023
0.2.4 Jun 14, 2023

#606 in Algorithms

45 downloads per month
Used in ghe2d

MIT license

105KB
2.5K SLoC

Arabic Reshaper Rust

Latest version Documentation Build Status unsafe forbidden MIT

A no-std crate to reconstruct Arabic, Turkish and Persian sentences to be used in applications that don't support Arabic script.

Usage:

resahpe a single line of string

use ar_reshaper::{ArabicReshaper, reshape_line};

let reshaper = ArabicReshaper::default();

// You can reshape just a single string using
println!("{}", reshaper.reshape("سلام دنیا"));
// or using `reshape_line` method if you dont want to construct the [ArabicReshaper]
// and you just want to reshape a few strings with default config
println!("{}", reshape_line("سلام دنیا"));
// Both will reconstruct the string and print `ﺳﻼﻡ ﺩﻧﯿﺎ`

reshape a slice of strings

use ar_reshaper::ArabicReshaper;

let reshaper = ArabicReshaper::default();

let lines = [
    "سلام",
    "سلام، خوبی؟",
];

println!("{:#?}", reshaper.reshape_lines(lines));
// or you can just use reshape method in a loop... the choice is yours.

reshape strings on a iterator

use ar_reshaper::prelude::*;

for line in ["یک", "دو"].iter().reshape_default() {
    println!("{line}");
}

You can check examples or tests directory for more examples.

features:

  • serde: if this feature is enabled the ReshaperConfig can be serialized and de-serialized using serde.
  • ttf-parser: if you enable this feature the ReshaperConfig method will have another extra method named from_font that can be used to enable ligatures only if they exist in the input font.

notes:

  • keep in mind that this crate need a allocator to work, because we depend on alloc internally.

Credits:

this project is based on the awesome python-arabic-reshaper.

Dependencies

~0–350KB