mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
proof: Malayalam chillus written with a joiner, Tamil SHRII and a dead KSSA
A Malayalam consonant, virama and ZWJ is a chillu and ends the syllable before, as a chillu letter does. Tamil keeps SHRII (with SA or SHA) whole, and a KSSA with a pulli closes the syllable before. Found by a local CodeRabbit review.
This commit is contained in:
1 parent
14016ef7c9
commit
c9f53a3f7e
1 file changed
+35
-11
+35
-11
@@ -21,11 +21,12 @@
|
||||
//!
|
||||
//! A dead consonant written as a letter of its own — Bengali's khanda ta (`ৎ`), Malayalam's chillus
|
||||
//! (`ൻ`, `ർ`), Telugu's and Kannada's nakaara pollu — ends the syllable before, as a mark does:
|
||||
//! `উৎ-সব`, `കർ-മ്മം`. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`.
|
||||
//! `উৎ-সব`, `കർ-മ്മം`. So does a chillu written the older way, as a consonant, the virama and a
|
||||
//! zero-width joiner (`ന്` U+200D): the one place a break follows a joiner. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`.
|
||||
//!
|
||||
//! **Tamil** joins no conjuncts: a consonant with a visible virama (pulli) closes the syllable
|
||||
//! before it, so the break goes after the pulli, not before the consonant (`பக்-கம்`, `தமிழ்-நா-டு`).
|
||||
//! The one conjunct, KSSA (`க்ஷ`), stays whole.
|
||||
//! Its two conjuncts, KSSA (`க்ஷ`) and SHRII (`ஸ்ரீ`), stay whole.
|
||||
//!
|
||||
//! A single akshara left at the end or start of a line is ruled out by the paragraph's
|
||||
//! [`Limits`](crate::hyphen::Limits), which count letters (vowel signs and anusvara count,
|
||||
@@ -219,21 +220,37 @@ pub fn points(script: Script, word: &[char]) -> Vec<usize> {
|
||||
}
|
||||
}
|
||||
};
|
||||
let chillu = |k: usize| script == Script::Malayalam && legacy_chillu(word, &kinds, k);
|
||||
let starts = |i: usize| match script {
|
||||
Script::Tamil => tamil_starts(word, &kinds, i),
|
||||
_ => at(i - 1) != Some(Kind::Virama) && live(i),
|
||||
Script::Tamil => at(i - 1) != Some(Kind::Joiner) && tamil_starts(word, &kinds, i),
|
||||
_ if chillu(i) => false,
|
||||
_ => (i >= 3 && chillu(i - 3)) || (!matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner)) && live(i)),
|
||||
};
|
||||
(1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && at(i - 1) != Some(Kind::Joiner) && starts(i)).collect()
|
||||
(1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && starts(i)).collect()
|
||||
}
|
||||
|
||||
/// Is a Malayalam chillu written the older way, as a consonant, the virama and a zero-width joiner
|
||||
/// (`ന്` U+200D), at `k`? Like a chillu letter (`ൻ`), it ends the syllable before.
|
||||
fn legacy_chillu(word: &[char], kinds: &[Kind], k: usize) -> bool {
|
||||
kinds.get(k) == Some(&Kind::Consonant) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&'\u{200D}')
|
||||
}
|
||||
|
||||
/// Does a syllable start at `i`, a consonant or vowel, in a Tamil word? Not at a consonant with a
|
||||
/// pulli, which closes the syllable before (`பக்-கம்`), nor inside KSSA (`க்ஷ`), one akshara.
|
||||
/// pulli, which closes the syllable before (`பக்-கம்`), nor inside one of the two conjuncts Tamil
|
||||
/// writes, KSSA (`க்ஷ`) and SHRII (`ஸ்ரீ`, `ஶ்ரீ`); a KSSA with a pulli closes the syllable too.
|
||||
fn tamil_starts(word: &[char], kinds: &[Kind], i: usize) -> bool {
|
||||
const KA: char = '\u{0B95}';
|
||||
const SSA: char = '\u{0BB7}';
|
||||
let kssa = |k: usize| word.get(k) == Some(&KA) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&SSA);
|
||||
let closes = kinds.get(i + 1) == Some(&Kind::Virama) && !kssa(i);
|
||||
!closes && !(i >= 2 && kssa(i - 2))
|
||||
let conjunct = |k: usize| {
|
||||
kinds.get(k + 1) == Some(&Kind::Virama)
|
||||
&& match (word.get(k).copied(), word.get(k + 2).copied()) {
|
||||
// KA, SSA.
|
||||
(Some('\u{0B95}'), Some('\u{0BB7}')) => true,
|
||||
// SA or SHA, RA, and the vowel sign II.
|
||||
(Some('\u{0BB8}' | '\u{0BB6}'), Some('\u{0BB0}')) => word.get(k + 3) == Some(&'\u{0BC0}'),
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
let closes = kinds.get(i + 1) == Some(&Kind::Virama) && !(conjunct(i) && kinds.get(i + 3) != Some(&Kind::Virama));
|
||||
!closes && !(i >= 2 && conjunct(i - 2))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -369,6 +386,10 @@ mod tests {
|
||||
assert_eq!(ml("മലയാളം"), "മ-ല-യാ-ളം");
|
||||
assert_eq!(ml("അവൻ"), "അ-വൻ");
|
||||
assert_eq!(ml("കർമ്മം"), "കർ-മ്മം");
|
||||
assert_eq!(ml("വൻമരം"), "വൻ-മ-രം");
|
||||
assert_eq!(ml("വന്\u{200D}മരം"), "വന്\u{200D}-മ-രം", "a chillu written with a joiner");
|
||||
assert_eq!(ml("അവന്\u{200D}"), "അ-വന്\u{200D}");
|
||||
assert_eq!(ml("കല\u{200D}മ"), "ക-ല\u{200D}മ", "a joiner after no virama still binds");
|
||||
}
|
||||
|
||||
/// Tamil: the break goes after a pulli, never before a consonant that carries one; KSSA is
|
||||
@@ -380,6 +401,9 @@ mod tests {
|
||||
assert_eq!(ta("பக்கம்"), "பக்-கம்");
|
||||
assert_eq!(ta("தமிழ்நாடு"), "த-மிழ்-நா-டு");
|
||||
assert_eq!(ta("அக்ஷரம்"), "அ-க்ஷ-ரம்");
|
||||
assert_eq!(ta("லக்ஷ்மி"), "லக்ஷ்-மி", "a KSSA with a pulli closes the syllable");
|
||||
assert_eq!(ta("ஸ்ரீலங்கா"), "ஸ்ரீ-லங்-கா", "SHRII with SA");
|
||||
assert_eq!(ta("ஶ்ரீலங்கா"), "ஶ்ரீ-லங்-கா", "SHRII with SHA");
|
||||
}
|
||||
|
||||
/// Gujarati, Hindi and the pack languages written in these scripts (by any of their tags) are
|
||||
|
||||
Reference in new issue
Block a user