Crate ar_reshaper
source ·Expand description
ArabicReshaper
Reconstruct Arabic sentences to be used in applications that don’t support Arabic script.
Usage:
reshape a single string
use ar_reshaper::{ArabicReshaper, reshape_line};
let reshaper = ArabicReshaper::default();
// You can reshape just a single string using
println!("{}", reshaper.reshape("سلام دنیا"));
// or `reshape_line` method if you dont want to construct the [ArabicReshaper]
// and you just want to reshape a line with default settings
println!("{}", reshape_line("سلام دنیا"));
// Both will reconstruct the string and print `ﺳﻼﻡ ﺩﻧﯿﺎ`
reshape a slice of strings
use ar_reshaper::ArabicReshaper;
let reshaper = ArabicReshaper::default();
println!("{:#?}", reshaper.reshape_lines(["سلام خوبی؟", "عالیم ممنون"]));
// this will reconstruct the string and print ["ﺳﻼﻡ ﺧﻮﺑﯽ؟", "ﻋﺎﻟﯿﻢ ﻣﻤﻨﻮﻥ"]
You can also reshape strings on a iterator
use ar_reshaper::prelude::*;
for line in ["یک", "دو"].iter().reshape_default() {
println!("{line}");
}
You can also check if a text need reshaping or not, this method can be useful when you dont want a copy of original string in case of no reshape.
use ar_reshaper::ArabicReshaper;
let reshaper = ArabicReshaper::default();
let text = "من به reshape نیاز دارم";
if reshaper.need_reshape(text) {
println!("{}", reshaper.reshape(text));
}
A rusty rewrite of python-arabic-reshaper You can check the original repository for more information.
Re-exports
pub use config::Language;
pub use config::ReshaperConfig;
Modules
Structs
- ArabicReshaper
Functions
- Reshape the given text with the default ArabicReshaper configuration.
Keep in mind that if you want to reshape a large amount of lines its better to first create a ArabicReshaper and then use thereshape
orreshape_lines
methods of it instead.