is_rtl/
lib.rs

1//! This crate provides a simple [`is_rtl`] function that checks whether a character belongs to a
2//! Right-To-Left alphabet or not.
3
4/// This returns true if the character belongs in a right-to-left (RTL) alphabet
5///
6/// The unicode ranges used in this function were taken from
7/// [here](https://www.unicodepedia.com/groups/) and the list of RTL alphabets was taken
8/// from [here](https://www.worldatlas.com/articles/which-languages-are-written-from-right-to-left.html).
9///
10/// ## Unicode Groups
11///
12/// Not all the RTL alphabets seem to be represented in the unicode standard so these are the ones
13/// the code *actually* looks for:
14///
15/// - Arabic
16/// - Imperial Aramaic
17/// - Hebrew
18/// - Old Persian
19/// - Syrian
20// TODO: Move this to a separate crate and publish it as it might actually be useful
21pub const fn is_rtl(c: char) -> bool {
22  match c {
23    '\u{600}'..='\u{6FF}'|         // Arabic
24    '\u{10840}'..='\u{1085F}' |    // Imperial Aramaic
25    '\u{591}'..='\u{5F4}'|         // Hebrew
26    '\u{103A0}'..='\u{103D5}' |    // Old Persian
27    '\u{700}'..='\u{74F}' => true, // Syrian
28    _ => false
29  }
30}