bdinfo-rs-core 2.0.0

Memory-safe Blu-ray (BDMV/M2TS) disc and stream analyzer.
Documentation
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
//! ISO-639 language-code -> English-name lookup.
//!
//! Each code maps to a display name; an unrecognized code maps to itself, so a
//! stream's language field is never lost — at worst the raw code is shown.
//!
//! The mapping is a `static` table plus a linear scan (the
//! same shape as [`crate::discovery`]'s small lookup tables) — deliberately not a
//! hash map: the result feeds the stream model's language name, an output-path
//! value whose ordering must stay deterministic (the house rule: never a hash
//! map in an output path). The table is stored sorted by code; the lookup is an
//! exact match on the code, so storage order is non-observable.

/// ISO-639 code -> English language name, sorted by code.
///
/// The ISO-639-2 bibliographic/terminological aliases (e.g. `alb`/`sqi` ->
/// `Albanian`, `ger`/`deu` -> `German`) are kept as separate entries mapping to
/// the same name.
static LANGUAGE_CODES: &[(&str, &str)] = &[
    ("aar", "Afar"),
    ("abk", "Abkhazian"),
    ("ace", "Achinese"),
    ("ach", "Acoli"),
    ("ada", "Adangme"),
    ("afa", "Afro-Asiatic (Other)"),
    ("afh", "Afrihili"),
    ("afr", "Afrikaans"),
    ("aka", "Akan"),
    ("akk", "Akkadian"),
    ("alb", "Albanian"),
    ("ale", "Aleut"),
    ("alg", "Algonquian languages"),
    ("amh", "Amharic"),
    ("ang", "English, Old (ca.450-1100)"),
    ("apa", "Apache languages"),
    ("ara", "Arabic"),
    ("arc", "Aramaic"),
    ("arm", "Armenian"),
    ("arn", "Araucanian"),
    ("arp", "Arapaho"),
    ("art", "Artificial (Other)"),
    ("arw", "Arawak"),
    ("asm", "Assamese"),
    ("ath", "Athapascan languages"),
    ("aus", "Australian languages"),
    ("ava", "Avaric"),
    ("ave", "Avestan"),
    ("awa", "Awadhi"),
    ("aym", "Aymara"),
    ("aze", "Azerbaijani"),
    ("bad", "Banda"),
    ("bai", "Bamileke languages"),
    ("bak", "Bashkir"),
    ("bal", "Baluchi"),
    ("bam", "Bambara"),
    ("ban", "Balinese"),
    ("baq", "Basque"),
    ("bas", "Basa"),
    ("bat", "Baltic (Other)"),
    ("bej", "Beja"),
    ("bel", "Belarusian"),
    ("bem", "Bemba"),
    ("ben", "Bengali"),
    ("ber", "Berber (Other)"),
    ("bho", "Bhojpuri"),
    ("bih", "Bihari"),
    ("bik", "Bikol"),
    ("bin", "Bini"),
    ("bis", "Bislama"),
    ("bla", "Siksika"),
    ("bnt", "Bantu (Other)"),
    ("bod", "Tibetan"),
    ("bos", "Bosnian"),
    ("bra", "Braj"),
    ("bre", "Breton"),
    ("btk", "Batak (Indonesia)"),
    ("bua", "Buriat"),
    ("bug", "Buginese"),
    ("bul", "Bulgarian"),
    ("bur", "Burmese"),
    ("cad", "Caddo"),
    ("cai", "Central American Indian (Other)"),
    ("car", "Carib"),
    ("cat", "Catalan"),
    ("cau", "Caucasian (Other)"),
    ("ceb", "Cebuano"),
    ("cel", "Celtic (Other)"),
    ("ces", "Czech"),
    ("cha", "Chamorro"),
    ("chb", "Chibcha"),
    ("che", "Chechen"),
    ("chg", "Chagatai"),
    ("chi", "Chinese"),
    ("chk", "Chuukese"),
    ("chm", "Mari"),
    ("chn", "Chinook jargon"),
    ("cho", "Choctaw"),
    ("chp", "Chipewyan"),
    ("chr", "Cherokee"),
    ("chu", "Church Slavic"),
    ("chv", "Chuvash"),
    ("chy", "Cheyenne"),
    ("cmc", "Chamic languages"),
    ("cop", "Coptic"),
    ("cor", "Cornish"),
    ("cos", "Corsican"),
    ("cpe", "Creoles and pidgins,"),
    ("cpf", "Creoles and pidgins,"),
    ("cpp", "Creoles and pidgins,"),
    ("cre", "Cree"),
    ("crp", "Creoles and pidgins (Other)"),
    ("cus", "Cushitic (Other)"),
    ("cym", "Welsh"),
    ("cze", "Czech"),
    ("dak", "Dakota"),
    ("dan", "Danish"),
    ("day", "Dayak"),
    ("del", "Delaware"),
    ("den", "Slave (Athapascan)"),
    ("deu", "German"),
    ("dgr", "Dogrib"),
    ("din", "Dinka"),
    ("div", "Divehi"),
    ("doi", "Dogri"),
    ("dra", "Dravidian (Other)"),
    ("dua", "Duala"),
    ("dum", "Dutch, Middle (ca. 1050-1350)"),
    ("dut", "Dutch"),
    ("dyu", "Dyula"),
    ("dzo", "Dzongkha"),
    ("efi", "Efik"),
    ("egy", "Egyptian (Ancient)"),
    ("eka", "Ekajuk"),
    ("ell", "Greek"),
    ("elx", "Elamite"),
    ("eng", "English"),
    ("enm", "English, Middle (1100-1500)"),
    ("epo", "Esperanto"),
    ("est", "Estonian"),
    ("eus", "Basque"),
    ("ewe", "Ewe"),
    ("ewo", "Ewondo"),
    ("fan", "Fang"),
    ("fao", "Faroese"),
    ("fas", "Persian"),
    ("fat", "Fanti"),
    ("fij", "Fijian"),
    ("fin", "Finnish"),
    ("fiu", "Finno-Ugrian (Other)"),
    ("fon", "Fon"),
    ("fra", "French"),
    ("fre", "French"),
    ("frm", "French, Middle (ca.1400-1600)"),
    ("fro", "French, Old (842-ca.1400)"),
    ("fry", "Frisian"),
    ("ful", "Fulah"),
    ("fur", "Friulian"),
    ("gaa", "Ga"),
    ("gay", "Gayo"),
    ("gba", "Gbaya"),
    ("gem", "Germanic (Other)"),
    ("geo", "Georgian"),
    ("ger", "German"),
    ("gez", "Geez"),
    ("gil", "Gilbertese"),
    ("gla", "Gaelic"),
    ("gle", "Irish"),
    ("glg", "Gallegan"),
    ("glv", "Manx"),
    ("gmh", "German, Middle High (ca.1050-1500)"),
    ("goh", "German, Old High (ca.750-1050)"),
    ("gon", "Gondi"),
    ("gor", "Gorontalo"),
    ("got", "Gothic"),
    ("grb", "Grebo"),
    ("grc", "Greek, Ancient (to 1453)"),
    ("gre", "Greek"),
    ("grn", "Guarani"),
    ("guj", "Gujarati"),
    ("gwi", "Gwich´in"),
    ("hai", "Haida"),
    ("hau", "Hausa"),
    ("haw", "Hawaiian"),
    ("heb", "Hebrew"),
    ("her", "Herero"),
    ("hil", "Hiligaynon"),
    ("him", "Himachali"),
    ("hin", "Hindi"),
    ("hit", "Hittite"),
    ("hmn", "Hmong"),
    ("hmo", "Hiri Motu"),
    ("hrv", "Croatian"),
    ("hun", "Hungarian"),
    ("hup", "Hupa"),
    ("hye", "Armenian"),
    ("iba", "Iban"),
    ("ibo", "Igbo"),
    ("ice", "Icelandic"),
    ("ijo", "Ijo"),
    ("iku", "Inuktitut"),
    ("ile", "Interlingue"),
    ("ilo", "Iloko"),
    ("ina", "Interlingua (International"),
    ("inc", "Indic (Other)"),
    ("ind", "Indonesian"),
    ("ine", "Indo-European (Other)"),
    ("ipk", "Inupiaq"),
    ("ira", "Iranian (Other)"),
    ("iro", "Iroquoian languages"),
    ("isl", "Icelandic"),
    ("ita", "Italian"),
    ("jav", "Javanese"),
    ("jpn", "Japanese"),
    ("jpr", "Judeo-Persian"),
    ("jrb", "Judeo-Arabic"),
    ("kaa", "Kara-Kalpak"),
    ("kab", "Kabyle"),
    ("kac", "Kachin"),
    ("kal", "Kalaallisut"),
    ("kam", "Kamba"),
    ("kan", "Kannada"),
    ("kar", "Karen"),
    ("kas", "Kashmiri"),
    ("kat", "Georgian"),
    ("kau", "Kanuri"),
    ("kaw", "Kawi"),
    ("kaz", "Kazakh"),
    ("kha", "Khasi"),
    ("khi", "Khoisan (Other)"),
    ("khm", "Khmer"),
    ("kho", "Khotanese"),
    ("kik", "Kikuyu"),
    ("kin", "Kinyarwanda"),
    ("kir", "Kirghiz"),
    ("kmb", "Kimbundu"),
    ("kok", "Konkani"),
    ("kom", "Komi"),
    ("kon", "Kongo"),
    ("kor", "Korean"),
    ("kos", "Kosraean"),
    ("kpe", "Kpelle"),
    ("kro", "Kru"),
    ("kru", "Kurukh"),
    ("kua", "Kuanyama"),
    ("kum", "Kumyk"),
    ("kur", "Kurdish"),
    ("kut", "Kutenai"),
    ("lad", "Ladino"),
    ("lah", "Lahnda"),
    ("lam", "Lamba"),
    ("lao", "Lao"),
    ("lat", "Latin"),
    ("lav", "Latvian"),
    ("lez", "Lezghian"),
    ("lin", "Lingala"),
    ("lit", "Lithuanian"),
    ("lol", "Mongo"),
    ("loz", "Lozi"),
    ("ltz", "Letzeburgesch"),
    ("lua", "Luba-Lulua"),
    ("lub", "Luba-Katanga"),
    ("lug", "Ganda"),
    ("lui", "Luiseno"),
    ("lun", "Lunda"),
    ("luo", "Luo (Kenya and Tanzania)"),
    ("lus", "Lushai"),
    ("mac", "Macedonian"),
    ("mad", "Madurese"),
    ("mag", "Magahi"),
    ("mah", "Marshall"),
    ("mai", "Maithili"),
    ("mak", "Makasar"),
    ("mal", "Malayalam"),
    ("man", "Mandingo"),
    ("mao", "Maori"),
    ("map", "Austronesian (Other)"),
    ("mar", "Marathi"),
    ("mas", "Masai"),
    ("may", "Malay"),
    ("mdr", "Mandar"),
    ("men", "Mende"),
    ("mga", "Irish, Middle (900-1200)"),
    ("mic", "Micmac"),
    ("min", "Minangkabau"),
    ("mis", "Miscellaneous languages"),
    ("mkd", "Macedonian"),
    ("mkh", "Mon-Khmer (Other)"),
    ("mlg", "Malagasy"),
    ("mlt", "Maltese"),
    ("mnc", "Manchu"),
    ("mni", "Manipuri"),
    ("mno", "Manobo languages"),
    ("moh", "Mohawk"),
    ("mol", "Moldavian"),
    ("mon", "Mongolian"),
    ("mos", "Mossi"),
    ("mri", "Maori"),
    ("msa", "Malay"),
    ("mul", "Multiple languages"),
    ("mun", "Munda languages"),
    ("mus", "Creek"),
    ("mwr", "Marwari"),
    ("mya", "Burmese"),
    ("myn", "Mayan languages"),
    ("nah", "Nahuatl"),
    ("nai", "North American Indian (Other)"),
    ("nau", "Nauru"),
    ("nav", "Navajo"),
    ("nbl", "Ndebele, South"),
    ("nde", "Ndebele, North"),
    ("ndo", "Ndonga"),
    ("nds", "Saxon"),
    ("nep", "Nepali"),
    ("new", "Newari"),
    ("nia", "Nias"),
    ("nic", "Niger-Kordofanian (Other)"),
    ("niu", "Niuean"),
    ("nld", "Dutch"),
    ("nno", "Norwegian Nynorsk"),
    ("nob", "Norwegian Bokmål"),
    ("non", "Norse, Old"),
    ("nor", "Norwegian"),
    ("nso", "Sotho, Northern"),
    ("nub", "Nubian languages"),
    ("nya", "Nyanja"),
    ("nym", "Nyamwezi"),
    ("nyn", "Nyankole"),
    ("nyo", "Nyoro"),
    ("nzi", "Nzima"),
    ("oci", "Occitan"),
    ("oji", "Ojibwa"),
    ("ori", "Oriya"),
    ("orm", "Oromo"),
    ("osa", "Osage"),
    ("oss", "Ossetian"),
    ("ota", "Turkish, Ottoman (1500-1928)"),
    ("oto", "Otomian languages"),
    ("paa", "Papuan (Other)"),
    ("pag", "Pangasinan"),
    ("pal", "Pahlavi"),
    ("pam", "Pampanga"),
    ("pan", "Panjabi"),
    ("pap", "Papiamento"),
    ("pau", "Palauan"),
    ("peo", "Persian, Old (ca.600-400 B.C.)"),
    ("per", "Persian"),
    ("phi", "Philippine (Other)"),
    ("phn", "Phoenician"),
    ("pli", "Pali"),
    ("pol", "Polish"),
    ("pon", "Pohnpeian"),
    ("por", "Portuguese"),
    ("pra", "Prakrit languages"),
    ("pro", "Provençal"),
    ("pus", "Pushto"),
    ("que", "Quechua"),
    ("raj", "Rajasthani"),
    ("rap", "Rapanui"),
    ("rar", "Rarotongan"),
    ("roa", "Romance (Other)"),
    ("roh", "Raeto-Romance"),
    ("rom", "Romany"),
    ("ron", "Romanian"),
    ("rum", "Romanian"),
    ("run", "Rundi"),
    ("rus", "Russian"),
    ("sad", "Sandawe"),
    ("sag", "Sango"),
    ("sah", "Yakut"),
    ("sai", "South American Indian (Other)"),
    ("sal", "Salishan languages"),
    ("sam", "Samaritan Aramaic"),
    ("san", "Sanskrit"),
    ("sas", "Sasak"),
    ("sat", "Santali"),
    ("scc", "Serbian"),
    ("sco", "Scots"),
    ("scr", "Croatian"),
    ("sel", "Selkup"),
    ("sem", "Semitic (Other)"),
    ("sga", "Irish, Old (to 900)"),
    ("sgn", "Sign languages"),
    ("shn", "Shan"),
    ("sid", "Sidamo"),
    ("sin", "Sinhalese"),
    ("sio", "Siouan languages"),
    ("sit", "Sino-Tibetan (Other)"),
    ("sla", "Slavic (Other)"),
    ("slk", "Slovak"),
    ("slo", "Slovak"),
    ("slv", "Slovenian"),
    ("sme", "Northern Sami"),
    ("smi", "Sami languages (Other)"),
    ("smo", "Samoan"),
    ("sna", "Shona"),
    ("snd", "Sindhi"),
    ("snk", "Soninke"),
    ("sog", "Sogdian"),
    ("som", "Somali"),
    ("son", "Songhai"),
    ("sot", "Sotho, Southern"),
    ("spa", "Spanish"),
    ("sqi", "Albanian"),
    ("srd", "Sardinian"),
    ("srp", "Serbian"),
    ("srr", "Serer"),
    ("ssa", "Nilo-Saharan (Other)"),
    ("ssw", "Swati"),
    ("suk", "Sukuma"),
    ("sun", "Sundanese"),
    ("sus", "Susu"),
    ("sux", "Sumerian"),
    ("swa", "Swahili"),
    ("swe", "Swedish"),
    ("syr", "Syriac"),
    ("tah", "Tahitian"),
    ("tai", "Tai (Other)"),
    ("tam", "Tamil"),
    ("tat", "Tatar"),
    ("tel", "Telugu"),
    ("tem", "Timne"),
    ("ter", "Tereno"),
    ("tet", "Tetum"),
    ("tgk", "Tajik"),
    ("tgl", "Tagalog"),
    ("tha", "Thai"),
    ("tib", "Tibetan"),
    ("tig", "Tigre"),
    ("tir", "Tigrinya"),
    ("tiv", "Tiv"),
    ("tkl", "Tokelau"),
    ("tli", "Tlingit"),
    ("tmh", "Tamashek"),
    ("tog", "Tonga (Nyasa)"),
    ("ton", "Tonga (Tonga Islands)"),
    ("tpi", "Tok Pisin"),
    ("tsi", "Tsimshian"),
    ("tsn", "Tswana"),
    ("tso", "Tsonga"),
    ("tuk", "Turkmen"),
    ("tum", "Tumbuka"),
    ("tur", "Turkish"),
    ("tut", "Altaic (Other)"),
    ("tvl", "Tuvalu"),
    ("twi", "Twi"),
    ("tyv", "Tuvinian"),
    ("uga", "Ugaritic"),
    ("uig", "Uighur"),
    ("ukr", "Ukrainian"),
    ("umb", "Umbundu"),
    ("und", "Undetermined"),
    ("urd", "Urdu"),
    ("uzb", "Uzbek"),
    ("vai", "Vai"),
    ("ven", "Venda"),
    ("vie", "Vietnamese"),
    ("vol", "Volapük"),
    ("vot", "Votic"),
    ("wak", "Wakashan languages"),
    ("wal", "Walamo"),
    ("war", "Waray"),
    ("was", "Washo"),
    ("wel", "Welsh"),
    ("wen", "Sorbian languages"),
    ("wol", "Wolof"),
    ("xho", "Xhosa"),
    ("yao", "Yao"),
    ("yap", "Yapese"),
    ("yid", "Yiddish"),
    ("yor", "Yoruba"),
    ("ypk", "Yupik languages"),
    ("zap", "Zapotec"),
    ("zen", "Zenaga"),
    ("zha", "Zhuang"),
    ("zho", "Chinese"),
    ("znd", "Zande"),
    ("zul", "Zulu"),
    ("zun", "Zuni"),
];

/// Returns the English name for an ISO-639 language `code`, or `code` itself when
/// it is not in the table.
///
/// The match is exact and case-sensitive; anything unrecognized falls back to
/// the identity mapping, so the caller always gets a printable value.
#[must_use]
pub fn get_name(code: &str) -> String {
    LANGUAGE_CODES
        .iter()
        .find(|&&(candidate, _)| candidate == code)
        .map_or_else(|| code.to_owned(), |&(_, name)| name.to_owned())
}

#[cfg(test)]
mod tests {
    use proptest::prelude::{prop_assert_eq, proptest};

    use super::{LANGUAGE_CODES, get_name};

    #[test]
    fn known_codes_map_to_their_names() {
        assert_eq!(get_name("eng"), "English");
        assert_eq!(get_name("jpn"), "Japanese");
        assert_eq!(get_name("fra"), "French");
        assert_eq!(get_name("aar"), "Afar"); // first by code
        assert_eq!(get_name("zun"), "Zuni"); // last by code
    }

    #[test]
    fn iso_639_b_and_t_aliases_share_a_name() {
        // Both ISO-639-2 variants resolve to the same English name.
        assert_eq!(get_name("ger"), "German");
        assert_eq!(get_name("deu"), "German");
        assert_eq!(get_name("alb"), "Albanian");
        assert_eq!(get_name("sqi"), "Albanian");
    }

    #[test]
    fn non_ascii_names_are_preserved_verbatim() {
        // The report emits these exact UTF-8 bytes; keep them byte-for-byte.
        assert_eq!(get_name("gwi"), "Gwich\u{00B4}in");
        assert_eq!(get_name("nob"), "Norwegian Bokm\u{00E5}l");
        assert_eq!(get_name("pro"), "Proven\u{00E7}al");
        assert_eq!(get_name("vol"), "Volap\u{00FC}k");
    }

    #[test]
    fn unknown_code_returns_itself() {
        // The identity fallback: an unrecognized code maps to itself.
        assert_eq!(get_name("xyz"), "xyz");
        assert_eq!(get_name(""), "");
    }

    #[test]
    fn lookup_is_case_sensitive() {
        // The table matches the lowercase code exactly; uppercase falls
        // through to the identity fallback.
        assert_eq!(get_name("ENG"), "ENG");
        assert_eq!(get_name("Eng"), "Eng");
    }

    #[test]
    fn table_is_sorted_by_code_without_duplicates() {
        // Strictly ascending => sorted (the doc claim) and no duplicate codes.
        assert!(LANGUAGE_CODES.is_sorted_by(|a, b| a.0 < b.0));
    }

    #[test]
    fn every_table_entry_round_trips() {
        // Every code resolves to its own name, exercising the scan at all
        // positions (first, last, and everything between).
        for &(code, name) in LANGUAGE_CODES {
            assert_eq!(get_name(code), name);
        }
    }

    proptest! {
        #[test]
        fn uppercase_codes_are_never_found(code in "[A-Z]{3}") {
            // The table holds only lowercase codes, so any uppercase triple hits
            // the identity fallback.
            prop_assert_eq!(get_name(&code), code);
        }
    }
}