mirror of
https://github.com/typst/typst
synced 2025-08-23 19:24:14 +08:00
use slices
This commit is contained in:
parent
29cc4a23e7
commit
9e2419eb66
@ -381,10 +381,10 @@ impl NumberingKind {
|
|||||||
pub fn apply(self, n: u64) -> EcoString {
|
pub fn apply(self, n: u64) -> EcoString {
|
||||||
match self {
|
match self {
|
||||||
Self::Arabic => {
|
Self::Arabic => {
|
||||||
numeric(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], n)
|
numeric(&['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], n)
|
||||||
}
|
}
|
||||||
Self::LowerRoman => additive(
|
Self::LowerRoman => additive(
|
||||||
[
|
&[
|
||||||
("m̅", 1000000),
|
("m̅", 1000000),
|
||||||
("d̅", 500000),
|
("d̅", 500000),
|
||||||
("c̅", 100000),
|
("c̅", 100000),
|
||||||
@ -410,7 +410,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::UpperRoman => additive(
|
Self::UpperRoman => additive(
|
||||||
[
|
&[
|
||||||
("M̅", 1000000),
|
("M̅", 1000000),
|
||||||
("D̅", 500000),
|
("D̅", 500000),
|
||||||
("C̅", 100000),
|
("C̅", 100000),
|
||||||
@ -436,7 +436,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::LowerGreek => additive(
|
Self::LowerGreek => additive(
|
||||||
[
|
&[
|
||||||
("͵θ", 9000),
|
("͵θ", 9000),
|
||||||
("͵η", 8000),
|
("͵η", 8000),
|
||||||
("͵ζ", 7000),
|
("͵ζ", 7000),
|
||||||
@ -478,7 +478,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::UpperGreek => additive(
|
Self::UpperGreek => additive(
|
||||||
[
|
&[
|
||||||
("͵Θ", 9000),
|
("͵Θ", 9000),
|
||||||
("͵Η", 8000),
|
("͵Η", 8000),
|
||||||
("͵Ζ", 7000),
|
("͵Ζ", 7000),
|
||||||
@ -520,7 +520,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::Hebrew => additive(
|
Self::Hebrew => additive(
|
||||||
[
|
&[
|
||||||
("י׳", 10000),
|
("י׳", 10000),
|
||||||
("ט׳", 9000),
|
("ט׳", 9000),
|
||||||
("ח׳", 8000),
|
("ח׳", 8000),
|
||||||
@ -563,21 +563,21 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::LowerLatin => alphabetic(
|
Self::LowerLatin => alphabetic(
|
||||||
[
|
&[
|
||||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||||
],
|
],
|
||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::UpperLatin => alphabetic(
|
Self::UpperLatin => alphabetic(
|
||||||
[
|
&[
|
||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||||
],
|
],
|
||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::HiraganaAiueo => alphabetic(
|
Self::HiraganaAiueo => alphabetic(
|
||||||
[
|
&[
|
||||||
'あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ',
|
'あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ',
|
||||||
'し', 'す', 'せ', 'そ', 'た', 'ち', 'つ', 'て', 'と', 'な', 'に',
|
'し', 'す', 'せ', 'そ', 'た', 'ち', 'つ', 'て', 'と', 'な', 'に',
|
||||||
'ぬ', 'ね', 'の', 'は', 'ひ', 'ふ', 'へ', 'ほ', 'ま', 'み', 'む',
|
'ぬ', 'ね', 'の', 'は', 'ひ', 'ふ', 'へ', 'ほ', 'ま', 'み', 'む',
|
||||||
@ -587,7 +587,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::HiraganaIroha => alphabetic(
|
Self::HiraganaIroha => alphabetic(
|
||||||
[
|
&[
|
||||||
'い', 'ろ', 'は', 'に', 'ほ', 'へ', 'と', 'ち', 'り', 'ぬ', 'る',
|
'い', 'ろ', 'は', 'に', 'ほ', 'へ', 'と', 'ち', 'り', 'ぬ', 'る',
|
||||||
'を', 'わ', 'か', 'よ', 'た', 'れ', 'そ', 'つ', 'ね', 'な', 'ら',
|
'を', 'わ', 'か', 'よ', 'た', 'れ', 'そ', 'つ', 'ね', 'な', 'ら',
|
||||||
'む', 'う', 'ゐ', 'の', 'お', 'く', 'や', 'ま', 'け', 'ふ', 'こ',
|
'む', 'う', 'ゐ', 'の', 'お', 'く', 'や', 'ま', 'け', 'ふ', 'こ',
|
||||||
@ -597,7 +597,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::KatakanaAiueo => alphabetic(
|
Self::KatakanaAiueo => alphabetic(
|
||||||
[
|
&[
|
||||||
'ア', 'イ', 'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ', 'サ',
|
'ア', 'イ', 'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ', 'サ',
|
||||||
'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト', 'ナ', 'ニ',
|
'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト', 'ナ', 'ニ',
|
||||||
'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ', 'マ', 'ミ', 'ム',
|
'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ', 'マ', 'ミ', 'ム',
|
||||||
@ -607,7 +607,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::KatakanaIroha => alphabetic(
|
Self::KatakanaIroha => alphabetic(
|
||||||
[
|
&[
|
||||||
'イ', 'ロ', 'ハ', 'ニ', 'ホ', 'ヘ', 'ト', 'チ', 'リ', 'ヌ', 'ル',
|
'イ', 'ロ', 'ハ', 'ニ', 'ホ', 'ヘ', 'ト', 'チ', 'リ', 'ヌ', 'ル',
|
||||||
'ヲ', 'ワ', 'カ', 'ヨ', 'タ', 'レ', 'ソ', 'ツ', 'ネ', 'ナ', 'ラ',
|
'ヲ', 'ワ', 'カ', 'ヨ', 'タ', 'レ', 'ソ', 'ツ', 'ネ', 'ナ', 'ラ',
|
||||||
'ム', 'ウ', 'ヰ', 'ノ', 'オ', 'ク', 'ヤ', 'マ', 'ケ', 'フ', 'コ',
|
'ム', 'ウ', 'ヰ', 'ノ', 'オ', 'ク', 'ヤ', 'マ', 'ケ', 'フ', 'コ',
|
||||||
@ -617,21 +617,21 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::KoreanJamo => alphabetic(
|
Self::KoreanJamo => alphabetic(
|
||||||
[
|
&[
|
||||||
'ㄱ', 'ㄴ', 'ㄷ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅅ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ',
|
'ㄱ', 'ㄴ', 'ㄷ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅅ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ',
|
||||||
'ㅌ', 'ㅍ', 'ㅎ',
|
'ㅌ', 'ㅍ', 'ㅎ',
|
||||||
],
|
],
|
||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::KoreanSyllable => alphabetic(
|
Self::KoreanSyllable => alphabetic(
|
||||||
[
|
&[
|
||||||
'가', '나', '다', '라', '마', '바', '사', '아', '자', '차', '카',
|
'가', '나', '다', '라', '마', '바', '사', '아', '자', '차', '카',
|
||||||
'타', '파', '하',
|
'타', '파', '하',
|
||||||
],
|
],
|
||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::BengaliLetter => alphabetic(
|
Self::BengaliLetter => alphabetic(
|
||||||
[
|
&[
|
||||||
'ক', 'খ', 'গ', 'ঘ', 'ঙ', 'চ', 'ছ', 'জ', 'ঝ', 'ঞ', 'ট', 'ঠ', 'ড', 'ঢ',
|
'ক', 'খ', 'গ', 'ঘ', 'ঙ', 'চ', 'ছ', 'জ', 'ঝ', 'ঞ', 'ট', 'ঠ', 'ড', 'ঢ',
|
||||||
'ণ', 'ত', 'থ', 'দ', 'ধ', 'ন', 'প', 'ফ', 'ব', 'ভ', 'ম', 'য', 'র', 'ল',
|
'ণ', 'ত', 'থ', 'দ', 'ধ', 'ন', 'প', 'ফ', 'ব', 'ভ', 'ম', 'য', 'র', 'ল',
|
||||||
'শ', 'ষ', 'স', 'হ',
|
'শ', 'ষ', 'স', 'হ',
|
||||||
@ -639,7 +639,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::CircledNumber => fixed(
|
Self::CircledNumber => fixed(
|
||||||
[
|
&[
|
||||||
'⓪', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩', '⑪', '⑫', '⑬',
|
'⓪', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩', '⑪', '⑫', '⑬',
|
||||||
'⑭', '⑮', '⑯', '⑰', '⑱', '⑲', '⑳', '㉑', '㉒', '㉓', '㉔', '㉕',
|
'⑭', '⑮', '⑯', '⑰', '⑱', '⑲', '⑳', '㉑', '㉒', '㉓', '㉔', '㉕',
|
||||||
'㉖', '㉗', '㉘', '㉙', '㉚', '㉛', '㉜', '㉝', '㉞', '㉟', '㊱',
|
'㉖', '㉗', '㉘', '㉙', '㉚', '㉛', '㉜', '㉝', '㉞', '㉟', '㊱',
|
||||||
@ -649,7 +649,7 @@ impl NumberingKind {
|
|||||||
n,
|
n,
|
||||||
),
|
),
|
||||||
Self::DoubleCircledNumber => {
|
Self::DoubleCircledNumber => {
|
||||||
fixed(['0', '⓵', '⓶', '⓷', '⓸', '⓹', '⓺', '⓻', '⓼', '⓽', '⓾'], n)
|
fixed(&['0', '⓵', '⓶', '⓷', '⓸', '⓹', '⓺', '⓻', '⓼', '⓽', '⓾'], n)
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::LowerSimplifiedChinese => {
|
Self::LowerSimplifiedChinese => {
|
||||||
@ -666,18 +666,18 @@ impl NumberingKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Self::EasternArabic => {
|
Self::EasternArabic => {
|
||||||
numeric(['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'], n)
|
numeric(&['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'], n)
|
||||||
}
|
}
|
||||||
Self::EasternArabicPersian => {
|
Self::EasternArabicPersian => {
|
||||||
numeric(['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'], n)
|
numeric(&['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'], n)
|
||||||
}
|
}
|
||||||
Self::DevanagariNumber => {
|
Self::DevanagariNumber => {
|
||||||
numeric(['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'], n)
|
numeric(&['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'], n)
|
||||||
}
|
}
|
||||||
Self::BengaliNumber => {
|
Self::BengaliNumber => {
|
||||||
numeric(['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'], n)
|
numeric(&['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'], n)
|
||||||
}
|
}
|
||||||
Self::Symbol => symbolic(['*', '†', '‡', '§', '¶', '‖'], n),
|
Self::Symbol => symbolic(&['*', '†', '‡', '§', '¶', '‖'], n),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -700,13 +700,10 @@ impl NumberingKind {
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// where this is the start of the familiar Roman numeral system.
|
/// where this is the start of the familiar Roman numeral system.
|
||||||
fn additive<const N_DIGITS: usize>(
|
fn additive(symbols: &[(&str, u64)], mut n: u64) -> EcoString {
|
||||||
symbols: [(&str, u64); N_DIGITS],
|
|
||||||
mut n: u64,
|
|
||||||
) -> EcoString {
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
for (symbol, weight) in symbols {
|
for (symbol, weight) in symbols {
|
||||||
if weight == 0 {
|
if *weight == 0 {
|
||||||
return (*symbol).into();
|
return (*symbol).into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -715,7 +712,7 @@ fn additive<const N_DIGITS: usize>(
|
|||||||
|
|
||||||
let mut s = EcoString::new();
|
let mut s = EcoString::new();
|
||||||
for (symbol, weight) in symbols {
|
for (symbol, weight) in symbols {
|
||||||
if weight == 0 || weight > n {
|
if *weight == 0 || *weight > n {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let reps = n / weight;
|
let reps = n / weight;
|
||||||
@ -748,8 +745,8 @@ fn additive<const N_DIGITS: usize>(
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// This system is commonly used in spreadsheet software.
|
/// This system is commonly used in spreadsheet software.
|
||||||
fn alphabetic<const N_DIGITS: usize>(symbols: [char; N_DIGITS], mut n: u64) -> EcoString {
|
fn alphabetic(symbols: &[char], mut n: u64) -> EcoString {
|
||||||
let n_digits = N_DIGITS as u64;
|
let n_digits = symbols.len() as u64;
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return '-'.into();
|
return '-'.into();
|
||||||
}
|
}
|
||||||
@ -775,8 +772,8 @@ fn alphabetic<const N_DIGITS: usize>(symbols: [char; N_DIGITS], mut n: u64) -> E
|
|||||||
/// ...
|
/// ...
|
||||||
/// n => 'n'
|
/// n => 'n'
|
||||||
/// ```
|
/// ```
|
||||||
fn fixed<const N_DIGITS: usize>(symbols: [char; N_DIGITS], n: u64) -> EcoString {
|
fn fixed(symbols: &[char], n: u64) -> EcoString {
|
||||||
let n_digits = N_DIGITS as u64;
|
let n_digits = symbols.len() as u64;
|
||||||
if n < n_digits {
|
if n < n_digits {
|
||||||
return symbols[(n) as usize].into();
|
return symbols[(n) as usize].into();
|
||||||
}
|
}
|
||||||
@ -799,8 +796,8 @@ fn fixed<const N_DIGITS: usize>(symbols: [char; N_DIGITS], n: u64) -> EcoString
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// which is the familiar trinary counting system.
|
/// which is the familiar trinary counting system.
|
||||||
fn numeric<const N_DIGITS: usize>(symbols: [char; N_DIGITS], mut n: u64) -> EcoString {
|
fn numeric(symbols: &[char], mut n: u64) -> EcoString {
|
||||||
let n_digits = N_DIGITS as u64;
|
let n_digits = symbols.len() as u64;
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return symbols[0].into();
|
return symbols[0].into();
|
||||||
}
|
}
|
||||||
@ -826,8 +823,8 @@ fn numeric<const N_DIGITS: usize>(symbols: [char; N_DIGITS], mut n: u64) -> EcoS
|
|||||||
/// 7 => 'AAA'
|
/// 7 => 'AAA'
|
||||||
/// ...
|
/// ...
|
||||||
/// ```
|
/// ```
|
||||||
fn symbolic<const N_DIGITS: usize>(symbols: [char; N_DIGITS], n: u64) -> EcoString {
|
fn symbolic(symbols: &[char], n: u64) -> EcoString {
|
||||||
let n_digits = N_DIGITS as u64;
|
let n_digits = symbols.len() as u64;
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return '-'.into();
|
return '-'.into();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user