1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! This module contains the functions related to ligatures.
/// Ligates a string.
///
/// From https://en.wikipedia.org/wiki/List_of_precomposed_Latin_characters_in_Unicode#Digraphs_and_ligatures
pub fn ligature(input: &str) -> String {
let mut output = String::new();
let mut first = input.chars();
let mut second = input.chars().skip(1);
let mut third = input.chars().skip(2);
loop {
let f = first.next();
let s = second.next();
let t = third.next();
match (f, s, t) {
(Some('f'), Some('f'), Some('i')) => {
output.push('ffi');
first.next();
second.next();
third.next();
first.next();
second.next();
third.next();
}
(Some('f'), Some('f'), Some('l')) => {
output.push('ffl');
first.next();
second.next();
third.next();
first.next();
second.next();
third.next();
}
(Some('f'), Some('f'), _) => {
output.push('ff');
first.next();
second.next();
third.next();
}
(Some('f'), Some('i'), _) => {
output.push('fi');
first.next();
second.next();
third.next();
}
(Some('f'), Some('l'), _) => {
output.push('fl');
first.next();
second.next();
third.next();
}
(Some('I'), Some('J'), _) => {
output.push('IJ');
first.next();
second.next();
third.next();
}
(Some('i'), Some('j'), _) => {
output.push('ij');
first.next();
second.next();
third.next();
}
(Some('L'), Some('J'), _) => {
output.push('LJ');
first.next();
second.next();
third.next();
}
(Some('L'), Some('j'), _) => {
output.push('Lj');
first.next();
second.next();
third.next();
}
(Some('l'), Some('j'), _) => {
output.push('lj');
first.next();
second.next();
third.next();
}
(Some('N'), Some('J'), _) => {
output.push('NJ');
first.next();
second.next();
third.next();
}
(Some('N'), Some('j'), _) => {
output.push('Nj');
first.next();
second.next();
third.next();
}
(Some('n'), Some('j'), _) => {
output.push('nj');
first.next();
second.next();
third.next();
}
(Some(c), _, _) => output.push(c),
_ => break,
}
}
output
}