postscript/compact1/index/
strings.rs

1use crate::compact1::StringID;
2
3const NUMBER_OF_STANDARD_STRINGS: usize = 391;
4
5index! {
6    /// A string index.
7    pub Strings
8}
9
10impl Strings {
11    /// Return the string corresponding to a string identifier.
12    pub fn get(&self, string_id: StringID) -> Option<String> {
13        match string_id as usize {
14            i if i < NUMBER_OF_STANDARD_STRINGS => {
15                get_standard_string(string_id).map(|string| string.to_string())
16            }
17            i => self
18                .0
19                .get(i - NUMBER_OF_STANDARD_STRINGS)
20                .map(|chunk| String::from_utf8_lossy(chunk).into_owned()),
21        }
22    }
23}
24
25fn get_standard_string(string_id: StringID) -> Option<&'static str> {
26    Some(match string_id {
27        0 => ".notdef",
28        1 => "space",
29        2 => "exclam",
30        3 => "quotedbl",
31        4 => "numbersign",
32        5 => "dollar",
33        6 => "percent",
34        7 => "ampersand",
35        8 => "quoteright",
36        9 => "parenleft",
37        10 => "parenright",
38        11 => "asterisk",
39        12 => "plus",
40        13 => "comma",
41        14 => "hyphen",
42        15 => "period",
43        16 => "slash",
44        17 => "zero",
45        18 => "one",
46        19 => "two",
47        20 => "three",
48        21 => "four",
49        22 => "five",
50        23 => "six",
51        24 => "seven",
52        25 => "eight",
53        26 => "nine",
54        27 => "colon",
55        28 => "semicolon",
56        29 => "less",
57        30 => "equal",
58        31 => "greater",
59        32 => "question",
60        33 => "at",
61        34 => "A",
62        35 => "B",
63        36 => "C",
64        37 => "D",
65        38 => "E",
66        39 => "F",
67        40 => "G",
68        41 => "H",
69        42 => "I",
70        43 => "J",
71        44 => "K",
72        45 => "L",
73        46 => "M",
74        47 => "N",
75        48 => "O",
76        49 => "P",
77        50 => "Q",
78        51 => "R",
79        52 => "S",
80        53 => "T",
81        54 => "U",
82        55 => "V",
83        56 => "W",
84        57 => "X",
85        58 => "Y",
86        59 => "Z",
87        60 => "bracketleft",
88        61 => "backslash",
89        62 => "bracketright",
90        63 => "asciicircum",
91        64 => "underscore",
92        65 => "quoteleft",
93        66 => "a",
94        67 => "b",
95        68 => "c",
96        69 => "d",
97        70 => "e",
98        71 => "f",
99        72 => "g",
100        73 => "h",
101        74 => "i",
102        75 => "j",
103        76 => "k",
104        77 => "l",
105        78 => "m",
106        79 => "n",
107        80 => "o",
108        81 => "p",
109        82 => "q",
110        83 => "r",
111        84 => "s",
112        85 => "t",
113        86 => "u",
114        87 => "v",
115        88 => "w",
116        89 => "x",
117        90 => "y",
118        91 => "z",
119        92 => "braceleft",
120        93 => "bar",
121        94 => "braceright",
122        95 => "asciitilde",
123        96 => "exclamdown",
124        97 => "cent",
125        98 => "sterling",
126        99 => "fraction",
127        100 => "yen",
128        101 => "florin",
129        102 => "section",
130        103 => "currency",
131        104 => "quotesingle",
132        105 => "quotedblleft",
133        106 => "guillemotleft",
134        107 => "guilsinglleft",
135        108 => "guilsinglright",
136        109 => "fi",
137        110 => "fl",
138        111 => "endash",
139        112 => "dagger",
140        113 => "daggerdbl",
141        114 => "periodcentered",
142        115 => "paragraph",
143        116 => "bullet",
144        117 => "quotesinglbase",
145        118 => "quotedblbase",
146        119 => "quotedblright",
147        120 => "guillemotright",
148        121 => "ellipsis",
149        122 => "perthousand",
150        123 => "questiondown",
151        124 => "grave",
152        125 => "acute",
153        126 => "circumflex",
154        127 => "tilde",
155        128 => "macron",
156        129 => "breve",
157        130 => "dotaccent",
158        131 => "dieresis",
159        132 => "ring",
160        133 => "cedilla",
161        134 => "hungarumlaut",
162        135 => "ogonek",
163        136 => "caron",
164        137 => "emdash",
165        138 => "AE",
166        139 => "ordfeminine",
167        140 => "Lslash",
168        141 => "Oslash",
169        142 => "OE",
170        143 => "ordmasculine",
171        144 => "ae",
172        145 => "dotlessi",
173        146 => "lslash",
174        147 => "oslash",
175        148 => "oe",
176        149 => "germandbls",
177        150 => "onesuperior",
178        151 => "logicalnot",
179        152 => "mu",
180        153 => "trademark",
181        154 => "Eth",
182        155 => "onehalf",
183        156 => "plusminus",
184        157 => "Thorn",
185        158 => "onequarter",
186        159 => "divide",
187        160 => "brokenbar",
188        161 => "degree",
189        162 => "thorn",
190        163 => "threequarters",
191        164 => "twosuperior",
192        165 => "registered",
193        166 => "minus",
194        167 => "eth",
195        168 => "multiply",
196        169 => "threesuperior",
197        170 => "copyright",
198        171 => "Aacute",
199        172 => "Acircumflex",
200        173 => "Adieresis",
201        174 => "Agrave",
202        175 => "Aring",
203        176 => "Atilde",
204        177 => "Ccedilla",
205        178 => "Eacute",
206        179 => "Ecircumflex",
207        180 => "Edieresis",
208        181 => "Egrave",
209        182 => "Iacute",
210        183 => "Icircumflex",
211        184 => "Idieresis",
212        185 => "Igrave",
213        186 => "Ntilde",
214        187 => "Oacute",
215        188 => "Ocircumflex",
216        189 => "Odieresis",
217        190 => "Ograve",
218        191 => "Otilde",
219        192 => "Scaron",
220        193 => "Uacute",
221        194 => "Ucircumflex",
222        195 => "Udieresis",
223        196 => "Ugrave",
224        197 => "Yacute",
225        198 => "Ydieresis",
226        199 => "Zcaron",
227        200 => "aacute",
228        201 => "acircumflex",
229        202 => "adieresis",
230        203 => "agrave",
231        204 => "aring",
232        205 => "atilde",
233        206 => "ccedilla",
234        207 => "eacute",
235        208 => "ecircumflex",
236        209 => "edieresis",
237        210 => "egrave",
238        211 => "iacute",
239        212 => "icircumflex",
240        213 => "idieresis",
241        214 => "igrave",
242        215 => "ntilde",
243        216 => "oacute",
244        217 => "ocircumflex",
245        218 => "odieresis",
246        219 => "ograve",
247        220 => "otilde",
248        221 => "scaron",
249        222 => "uacute",
250        223 => "ucircumflex",
251        224 => "udieresis",
252        225 => "ugrave",
253        226 => "yacute",
254        227 => "ydieresis",
255        228 => "zcaron",
256        229 => "exclamsmall",
257        230 => "Hungarumlautsmall",
258        231 => "dollaroldstyle",
259        232 => "dollarsuperior",
260        233 => "ampersandsmall",
261        234 => "Acutesmall",
262        235 => "parenleftsuperior",
263        236 => "parenrightsuperior",
264        237 => "twodotenleader",
265        238 => "onedotenleader",
266        239 => "zerooldstyle",
267        240 => "oneoldstyle",
268        241 => "twooldstyle",
269        242 => "threeoldstyle",
270        243 => "fouroldstyle",
271        244 => "fiveoldstyle",
272        245 => "sixoldstyle",
273        246 => "sevenoldstyle",
274        247 => "eightoldstyle",
275        248 => "nineoldstyle",
276        249 => "commasuperior",
277        250 => "threequartersemdash",
278        251 => "periodsuperior",
279        252 => "questionsmall",
280        253 => "asuperior",
281        254 => "bsuperior",
282        255 => "centsuperior",
283        256 => "dsuperior",
284        257 => "esuperior",
285        258 => "isuperior",
286        259 => "lsuperior",
287        260 => "msuperior",
288        261 => "nsuperior",
289        262 => "osuperior",
290        263 => "rsuperior",
291        264 => "ssuperior",
292        265 => "tsuperior",
293        266 => "ff",
294        267 => "ffi",
295        268 => "ffl",
296        269 => "parenleftinferior",
297        270 => "parenrightinferior",
298        271 => "Circumflexsmall",
299        272 => "hyphensuperior",
300        273 => "Gravesmall",
301        274 => "Asmall",
302        275 => "Bsmall",
303        276 => "Csmall",
304        277 => "Dsmall",
305        278 => "Esmall",
306        279 => "Fsmall",
307        280 => "Gsmall",
308        281 => "Hsmall",
309        282 => "Ismall",
310        283 => "Jsmall",
311        284 => "Ksmall",
312        285 => "Lsmall",
313        286 => "Msmall",
314        287 => "Nsmall",
315        288 => "Osmall",
316        289 => "Psmall",
317        290 => "Qsmall",
318        291 => "Rsmall",
319        292 => "Ssmall",
320        293 => "Tsmall",
321        294 => "Usmall",
322        295 => "Vsmall",
323        296 => "Wsmall",
324        297 => "Xsmall",
325        298 => "Ysmall",
326        299 => "Zsmall",
327        300 => "colonmonetary",
328        301 => "onefitted",
329        302 => "rupiah",
330        303 => "Tildesmall",
331        304 => "exclamdownsmall",
332        305 => "centoldstyle",
333        306 => "Lslashsmall",
334        307 => "Scaronsmall",
335        308 => "Zcaronsmall",
336        309 => "Dieresissmall",
337        310 => "Brevesmall",
338        311 => "Caronsmall",
339        312 => "Dotaccentsmall",
340        313 => "Macronsmall",
341        314 => "figuredash",
342        315 => "hypheninferior",
343        316 => "Ogoneksmall",
344        317 => "Ringsmall",
345        318 => "Cedillasmall",
346        319 => "questiondownsmall",
347        320 => "oneeighth",
348        321 => "threeeighths",
349        322 => "fiveeighths",
350        323 => "seveneighths",
351        324 => "onethird",
352        325 => "twothirds",
353        326 => "zerosuperior",
354        327 => "foursuperior",
355        328 => "fivesuperior",
356        329 => "sixsuperior",
357        330 => "sevensuperior",
358        331 => "eightsuperior",
359        332 => "ninesuperior",
360        333 => "zeroinferior",
361        334 => "oneinferior",
362        335 => "twoinferior",
363        336 => "threeinferior",
364        337 => "fourinferior",
365        338 => "fiveinferior",
366        339 => "sixinferior",
367        340 => "seveninferior",
368        341 => "eightinferior",
369        342 => "nineinferior",
370        343 => "centinferior",
371        344 => "dollarinferior",
372        345 => "periodinferior",
373        346 => "commainferior",
374        347 => "Agravesmall",
375        348 => "Aacutesmall",
376        349 => "Acircumflexsmall",
377        350 => "Atildesmall",
378        351 => "Adieresissmall",
379        352 => "Aringsmall",
380        353 => "AEsmall",
381        354 => "Ccedillasmall",
382        355 => "Egravesmall",
383        356 => "Eacutesmall",
384        357 => "Ecircumflexsmall",
385        358 => "Edieresissmall",
386        359 => "Igravesmall",
387        360 => "Iacutesmall",
388        361 => "Icircumflexsmall",
389        362 => "Idieresissmall",
390        363 => "Ethsmall",
391        364 => "Ntildesmall",
392        365 => "Ogravesmall",
393        366 => "Oacutesmall",
394        367 => "Ocircumflexsmall",
395        368 => "Otildesmall",
396        369 => "Odieresissmall",
397        370 => "OEsmall",
398        371 => "Oslashsmall",
399        372 => "Ugravesmall",
400        373 => "Uacutesmall",
401        374 => "Ucircumflexsmall",
402        375 => "Udieresissmall",
403        376 => "Yacutesmall",
404        377 => "Thornsmall",
405        378 => "Ydieresissmall",
406        379 => "001.000",
407        380 => "001.001",
408        381 => "001.002",
409        382 => "001.003",
410        383 => "Black",
411        384 => "Bold",
412        385 => "Book",
413        386 => "Light",
414        387 => "Medium",
415        388 => "Regular",
416        389 => "Roman",
417        390 => "Semibold",
418        _ => return None,
419    })
420}
421
422#[cfg(test)]
423mod tests {
424    use super::get_standard_string;
425    use super::NUMBER_OF_STANDARD_STRINGS;
426    use crate::compact1::StringID;
427
428    #[test]
429    fn number_of_standard_strings() {
430        assert!(get_standard_string(NUMBER_OF_STANDARD_STRINGS as StringID - 1).is_some());
431        assert!(get_standard_string(NUMBER_OF_STANDARD_STRINGS as StringID).is_none());
432    }
433}