Hebrew numbering (#446)

This commit is contained in:
Naim A 2023-04-01 17:05:06 +03:00 committed by GitHub
parent ed79ecbb44
commit 66a22b5555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 1 deletions

View File

@ -215,7 +215,7 @@ impl FromStr for NumberingPattern {
let prefix = pattern[handled..i].into();
let case = if c.is_uppercase() { Case::Upper } else { Case::Lower };
pieces.push((prefix, kind, case));
handled = i + 1;
handled = c.len_utf8() + i;
}
let suffix = pattern[handled..].into();
@ -255,6 +255,7 @@ enum NumberingKind {
Letter,
Roman,
Symbol,
Hebrew,
}
impl NumberingKind {
@ -265,6 +266,7 @@ impl NumberingKind {
'a' => NumberingKind::Letter,
'i' => NumberingKind::Roman,
'*' => NumberingKind::Symbol,
'א' => NumberingKind::Hebrew,
_ => return None,
})
}
@ -276,6 +278,7 @@ impl NumberingKind {
Self::Letter => 'a',
Self::Roman => 'i',
Self::Symbol => '*',
Self::Hebrew => 'א',
}
}
@ -360,6 +363,59 @@ impl NumberingKind {
let symbol = SYMBOLS[(n - 1) % SYMBOLS.len()];
let amount = ((n - 1) / SYMBOLS.len()) + 1;
std::iter::repeat(symbol).take(amount).collect()
},
Self::Hebrew => {
if n == 0 {
return '-'.into();
}
let mut fmt = EcoString::new();
'outer: for &(name, value) in &[
('ת', 400),
('ש', 300),
('ר', 200),
('ק', 100),
('צ', 90),
('פ', 80),
('ע', 70),
('ס', 60),
('נ', 50),
('מ', 40),
('ל', 30),
('כ', 20),
('י', 10),
('ט', 9),
('ח', 8),
('ז', 7),
('ו', 6),
('ה', 5),
('ד', 4),
('ג', 3),
('ב', 2),
('א', 1),
] {
while n >= value {
match n {
15 => fmt.push_str("ט״ו"),
16 => fmt.push_str("ט״ז"),
_ => {
let append_geresh = n == value && fmt.is_empty();
if n == value && !fmt.is_empty() {
fmt.push('״');
}
fmt.push(name);
if append_geresh {
fmt.push('׳');
}
n -= value;
continue;
},
}
break 'outer;
}
}
fmt
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -12,3 +12,12 @@
---
// Error: 17-19 number must be at least zero
#numbering("1", -1)
---
#set text(lang: "he")
#for i in range(9, 21, step: 2) {
numbering("א.", i)
[ עבור #i]
parbreak()
}