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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//! Languages we can hyphenate and their default parameters, as provided by
//! the TeX `hyph-utf8` package.

#![allow(non_camel_case_types)]

use hyphenation_commons::{Exceptions, Patterns};

/// A `Corpus` carries hyphenation data and parameters.
///
/// It comprises the working language, the set of applicable patterns and
/// exceptions, as well as the left and right intra-word hyphenation boundaries.
#[derive(Clone, Debug)]
pub struct Corpus {
    pub language: Language,
    pub patterns: Patterns,
    pub exceptions: Exceptions,
    pub left_min: usize,
    pub right_min: usize
}


use self::Language::*;

/// The set of available languages.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Language {
    Afrikaans,
    Armenian,
    Assamese,
    Basque,
    Bengali,
    Bulgarian,
    Catalan,
    Chinese,
    Coptic,
    Croatian,
    Czech,
    Danish,
    Dutch,
    English_GB,
    English_US,
    Esperanto,
    Estonian,
    Ethiopic,
    Finnish,
    French,
    Friulan,
    Galician,
    Georgian,
    German_1901,
    German_1996,
    German_Swiss,
    Greek_Ancient,
    Greek_Mono,
    Greek_Poly,
    Gujarati,
    Hindi,
    Hungarian,
    Icelandic,
    Indonesian,
    Interlingua,
    Irish,
    Italian,
    Kannada,
    Kurmanji,
    Latin_Classic,
    Latin,
    Latvian,
    Lithuanian,
    Malayalam,
    Marathi,
    Mongolian,
    Norwegian_Bokmal,
    Norwegian_Nynorsk,
    Occitan,
    Oriya,
    Panjabi,
    Piedmontese,
    Polish,
    Portuguese,
    Romanian,
    Romansh,
    Russian,
    Sanskrit,
    Serbian_Cyrillic,
    Serbocroatian_Cyrillic,
    Serbocroatian_Latin,
    Slavonic_Church,
    Slovak,
    Slovenian,
    Spanish,
    Swedish,
    Tamil,
    Telugu,
    Thai,
    Turkish,
    Turkmen,
    Ukrainian,
    Uppersorbian,
    Welsh
}


/// The TeX tag for a given language.
pub fn tag(lang: Language) -> &'static str {
    match lang {
        Afrikaans => "af",
        Armenian => "hy",
        Assamese => "as",
        Basque => "eu",
        Bengali => "bn",
        Bulgarian => "bg",
        Catalan => "ca",
        Chinese => "zh-latn-pinyin",
        Coptic => "cop",
        Croatian => "hr",
        Czech => "cs",
        Danish => "da",
        Dutch => "nl",
        English_GB => "en-gb",
        English_US => "en-us",
        Esperanto => "eo",
        Estonian => "et",
        Ethiopic => "mul-ethi",
        Finnish => "fi",
        French => "fr",
        Friulan => "fur",
        Galician => "gl",
        Georgian => "ka",
        German_1901  => "de-1901",
        German_1996  => "de-1996",
        German_Swiss => "de-ch-1901",
        Greek_Ancient => "grc",
        Greek_Mono => "el-monoton",
        Greek_Poly => "el-polyton",
        Gujarati => "gu",
        Hindi => "hi",
        Hungarian => "hu",
        Icelandic => "is",
        Indonesian => "id",
        Interlingua => "ia",
        Irish => "ga",
        Italian => "it",
        Kannada => "kn",
        Kurmanji => "kmr",
        Latin => "la",
        Latin_Classic => "la-x-classic",
        Latvian => "lv",
        Lithuanian => "lt",
        Malayalam => "ml",
        Marathi => "mr",
        Mongolian => "mn-cyrl",
        Norwegian_Bokmal  => "nb",
        Norwegian_Nynorsk => "nn",
        Occitan => "oc",
        Oriya => "or",
        Panjabi => "pa",
        Piedmontese => "pms",
        Polish => "pl",
        Portuguese => "pt",
        Romanian => "ro",
        Romansh => "rm",
        Russian => "ru",
        Sanskrit => "sa",
        Serbian_Cyrillic => "sr-cyrl",
        Serbocroatian_Cyrillic => "sh-cyrl",
        Serbocroatian_Latin => "sh-latn",
        Slavonic_Church => "cu",
        Slovak => "sk",
        Slovenian => "sl",
        Spanish => "es",
        Swedish => "sv",
        Tamil => "ta",
        Telugu => "te",
        Thai => "th",
        Turkish => "tr",
        Turkmen => "tk",
        Ukrainian => "uk",
        Uppersorbian => "hsb",
        Welsh => "cy"
    }
}

/// The default number of characters from the start and end of a word
/// which shall not be hyphenated.
pub fn mins(lang: Language) -> (usize, usize) {
    // NOTE: These values were taken directly from the relevant TeX packages, but
    // it is unclear how well they map to the notion of Unicode `char` in Rust.
    //
    // In the worst case, a language featuring graphemes larger than 1 `char` may
    // set boundaries mid-grapheme. This should be of no practical consequence,
    // since well-formed hyphenation patterns only match full graphemes.
    match lang {
        Afrikaans => (1, 2),
        Armenian => (1, 2),
        Assamese => (1, 1),
        Basque => (2, 2),
        Bengali => (1, 1),
        Bulgarian => (2, 2),
        Catalan => (2, 2),
        Chinese => (1, 1),
        Coptic => (1, 1),
        Croatian => (2, 2),
        Czech => (2, 3),
        Danish => (2, 2),
        Dutch => (2, 2),
        English_GB => (2, 3),
        English_US => (2, 3),
        Esperanto => (2, 2),
        Estonian => (2, 3),
        Ethiopic => (1, 1),
        Finnish => (2, 2),
        French => (2, 3),
        Friulan => (2, 2),
        Galician => (2, 2),
        Georgian => (1, 2),
        German_1901 => (2, 2),
        German_1996 => (2, 2),
        German_Swiss => (2, 2),
        Greek_Ancient => (1, 1),
        Greek_Mono => (1, 1),
        Greek_Poly => (1, 1),
        Gujarati => (1, 1),
        Hindi => (1, 1),
        Hungarian => (2, 2),
        Icelandic => (2, 2),
        Indonesian => (2, 2),
        Interlingua => (2, 2),
        Irish => (2, 3),
        Italian => (2, 2),
        Kannada => (1, 1),
        Kurmanji => (2, 2),
        Latin => (2, 2),
        Latin_Classic => (2, 2),
        Latvian => (2, 2),
        Lithuanian => (2, 2),
        Malayalam => (1, 1),
        Marathi => (1, 1),
        Mongolian => (2, 2),
        Norwegian_Bokmal => (2, 2),
        Norwegian_Nynorsk => (2, 2),
        Occitan => (2, 2),
        Oriya => (1, 1),
        Panjabi => (1, 1),
        Piedmontese => (2, 2),
        Polish => (2, 2),
        Portuguese => (2, 3),
        Romanian => (2, 2),
        Romansh => (2, 2),
        Russian => (2, 2),
        Sanskrit => (1, 3),
        Serbian_Cyrillic => (2, 2),
        Serbocroatian_Cyrillic => (2, 2),
        Serbocroatian_Latin => (2, 2),
        Slavonic_Church => (1, 2),
        Slovak => (2, 3),
        Slovenian => (2, 2),
        Spanish => (2, 2),
        Swedish => (2, 2),
        Tamil => (1, 1),
        Telugu => (1, 1),
        Thai => (2, 3),
        Turkish => (2, 2),
        Turkmen => (2, 2),
        Ukrainian => (2, 2),
        Uppersorbian => (2, 2),
        Welsh => (2, 3)
    }
}