| 1 |
use finl_unicode::categories::CharacterCategories; |
| 2 |
|
| 3 |
pub(crate) trait FlankingCheckHelper |
| 4 |
where |
| 5 |
Self: Sized + Copy, |
| 6 |
{ |
| 7 |
fn is_cjk_ambiguous_punctuation_candidate(&self) -> bool; |
| 8 |
fn is_ideographic_vs(&self) -> bool; |
| 9 |
fn is_cjk(&self) -> bool; |
| 10 |
#[inline] |
| 11 |
fn is_cjk_or_ideographic_vs(&self) -> bool { |
| 12 |
self.is_cjk() || self.is_ideographic_vs() |
| 13 |
} |
| 14 |
fn is_non_emoji_general_purpose_vs(&self) -> bool; |
| 15 |
fn is_cmark_punctuation(&self) -> bool; |
| 16 |
} |
| 17 |
|
| 18 |
impl FlankingCheckHelper for char { |
| 19 |
/// https://github.com/tats-u/markdown-cjk-friendly/blob/main/ranges.md#cjk-characters |
| 20 |
#[inline] |
| 21 |
fn is_cjk(&self) -> bool { |
| 22 |
// Snapshot as of Unicode 16 |
| 23 |
matches!( |
| 24 |
u32::from(*self), |
| 25 |
0x1100..=0x11ff |
| 26 |
| 0x20a9 |
| 27 |
| 0x2329..=0x232a |
| 28 |
| 0x2630..=0x2637 |
| 29 |
| 0x268a..=0x268f |
| 30 |
| 0x2e80..=0x2e99 |
| 31 |
| 0x2e9b..=0x2ef3 |
| 32 |
| 0x2f00..=0x2fd5 |
| 33 |
| 0x2ff0..=0x303e |
| 34 |
| 0x3041..=0x3096 |
| 35 |
| 0x3099..=0x30ff |
| 36 |
| 0x3105..=0x312f |
| 37 |
| 0x3131..=0x318e |
| 38 |
| 0x3190..=0x31e5 |
| 39 |
| 0x31ef..=0x321e |
| 40 |
| 0x3220..=0x3247 |
| 41 |
| 0x3250..=0xa48c |
| 42 |
| 0xa490..=0xa4c6 |
| 43 |
| 0xa960..=0xa97c |
| 44 |
| 0xac00..=0xd7a3 |
| 45 |
| 0xd7b0..=0xd7c6 |
| 46 |
| 0xd7cb..=0xd7fb |
| 47 |
| 0xf900..=0xfaff |
| 48 |
| 0xfe10..=0xfe19 |
| 49 |
| 0xfe30..=0xfe52 |
| 50 |
| 0xfe54..=0xfe66 |
| 51 |
| 0xfe68..=0xfe6b |
| 52 |
| 0xff01..=0xffbe |
| 53 |
| 0xffc2..=0xffc7 |
| 54 |
| 0xffca..=0xffcf |
| 55 |
| 0xffd2..=0xffd7 |
| 56 |
| 0xffda..=0xffdc |
| 57 |
| 0xffe0..=0xffe6 |
| 58 |
| 0xffe8..=0xffee |
| 59 |
| 0x16fe0..=0x16fe4 |
| 60 |
| 0x16ff0..=0x16ff6 |
| 61 |
| 0x17000..=0x18cd5 |
| 62 |
| 0x18cff..=0x18d1e |
| 63 |
| 0x18d80..=0x18df2 |
| 64 |
| 0x1aff0..=0x1aff3 |
| 65 |
| 0x1aff5..=0x1affb |
| 66 |
| 0x1affd..=0x1affe |
| 67 |
| 0x1b000..=0x1b122 |
| 68 |
| 0x1b132 |
| 69 |
| 0x1b150..=0x1b152 |
| 70 |
| 0x1b155 |
| 71 |
| 0x1b164..=0x1b167 |
| 72 |
| 0x1b170..=0x1b2fb |
| 73 |
| 0x1d300..=0x1d356 |
| 74 |
| 0x1d360..=0x1d376 |
| 75 |
| 0x1f200 |
| 76 |
| 0x1f202 |
| 77 |
| 0x1f210..=0x1f219 |
| 78 |
| 0x1f21b..=0x1f22e |
| 79 |
| 0x1f230..=0x1f231 |
| 80 |
| 0x1f237 |
| 81 |
| 0x1f23b |
| 82 |
| 0x1f240..=0x1f248 |
| 83 |
| 0x1f260..=0x1f265 |
| 84 |
| 0x20000..=0x3fffd |
| 85 |
) |
| 86 |
} |
| 87 |
|
| 88 |
#[inline] |
| 89 |
fn is_non_emoji_general_purpose_vs(&self) -> bool { |
| 90 |
matches!(u32::from(*self), 0xFE00..=0xFE0E) |
| 91 |
} |
| 92 |
|
| 93 |
#[inline] |
| 94 |
fn is_ideographic_vs(&self) -> bool { |
| 95 |
matches!(u32::from(*self), 0xE0100..=0xE01EF) |
| 96 |
} |
| 97 |
#[inline] |
| 98 |
fn is_cmark_punctuation(&self) -> bool { |
| 99 |
self.is_punctuation() || self.is_symbol() |
| 100 |
} |
| 101 |
#[inline] |
| 102 |
fn is_cjk_ambiguous_punctuation_candidate(&self) -> bool { |
| 103 |
matches!(u32::from(*self), 0x2018 | 0x2019 | 0x201c | 0x201d) |
| 104 |
} |
| 105 |
} |