ar_reshaper/
lib.rs

1//! # ArabicReshaper
2//!
3//! Reconstruct Arabic sentences to be used in applications that don't support Arabic script.
4//!
5//! ## Usage:
6//! reshape a single string
7//! ```rust
8//! use ar_reshaper::{ArabicReshaper, reshape_line};
9//!
10//! let reshaper = ArabicReshaper::default();
11//!
12//! // You can reshape just a single string using
13//! println!("{}", reshaper.reshape("سلام دنیا"));
14//! // or `reshape_line` method if you dont want to construct the [ArabicReshaper]
15//! // and you just want to reshape a line with default settings
16//! println!("{}", reshape_line("سلام دنیا"));
17//! // Both will reconstruct the string and print `ﺳﻼﻡ ﺩﻧﯿﺎ`
18//! ```
19//!
20//! reshape a slice of strings
21//! ```rust
22//! use ar_reshaper::ArabicReshaper;
23//!
24//! let reshaper = ArabicReshaper::default();
25//!
26//! println!("{:#?}", reshaper.reshape_lines(["سلام خوبی؟", "عالیم ممنون"]));
27//! // this will reconstruct the string and print  ["ﺳﻼﻡ ﺧﻮﺑﯽ؟", "ﻋﺎﻟﯿﻢ ﻣﻤﻨﻮﻥ"]
28//! ```
29//!
30//! You can also reshape strings on a iterator
31//! ```rust
32//! use ar_reshaper::prelude::*;
33//!
34//! for line in ["یک", "دو"].iter().reshape_default() {
35//!     println!("{line}");
36//! }
37//! ```
38//!
39//! You can also check if a text need reshaping or not, this method can be
40//! useful when you dont want a copy of original string in case of no reshape.
41//! ```rust
42//! use ar_reshaper::ArabicReshaper;
43//!
44//! let reshaper = ArabicReshaper::default();
45//!
46//! let text = "من به reshape نیاز دارم";
47//! if reshaper.need_reshape(text) {
48//!     println!("{}", reshaper.reshape(text));
49//! }
50//! ```
51//!
52//! A rusty rewrite of [python-arabic-reshaper](https://github.com/mpcabd/python-arabic-reshaper)
53//! You can check the original repository for more information.
54#![no_std]
55#![forbid(unsafe_code)]
56#![warn(missing_copy_implementations)]
57
58extern crate alloc;
59
60use alloc::string::String;
61
62pub use config::{Language, ReshaperConfig};
63pub use reshaper::ArabicReshaper;
64
65pub mod config;
66pub mod form;
67pub mod iterator;
68pub mod letters;
69mod ligatures;
70mod reshaper;
71
72pub mod prelude {
73    pub use crate::config::*;
74    pub use crate::iterator::*;
75    pub use crate::ligatures::LigatureNames;
76    pub use crate::reshaper::ArabicReshaper;
77}
78
79/// Reshape the given text with the default [ArabicReshaper] configuration.\
80/// Keep in mind that if you want to reshape a large amount of lines its better
81/// to first create a [ArabicReshaper] and then use the `reshape` or `reshape_lines`
82/// methods of it instead.
83pub fn reshape_line<S>(text: S) -> String
84where
85    S: AsRef<str>,
86{
87    let reshaper = ArabicReshaper::default();
88
89    reshaper.reshape(text)
90}