296e4e65a8e4f32a61e4e415318610e3180513f7
[pspp] / rust / src / encoding.rs
1 include!(concat!(env!("OUT_DIR"), "/encodings.rs"));
2
3 pub fn codepage_from_encoding(encoding: &str) -> Option<u32> {
4     CODEPAGE_NAME_TO_NUMBER
5         .get(encoding.to_ascii_lowercase().as_str())
6         .copied()
7 }
8
9 pub fn encoding_from_hints(encoding: Option<&str>, codepage: Option<u32>) -> Option<&str> {
10     if encoding.is_some() {
11         encoding
12     } else if let Some(codepage) = codepage {
13         match codepage {
14             1 => Some("EBCDIC-US"),
15             2 | 3 => {
16                 // These ostensibly mean "7-bit ASCII" and "8-bit ASCII"[sic]
17                 // respectively.  However, many files have character code 2 but
18                 // data which are clearly not ASCII.  Therefore, ignore these
19                 // values.
20                 None
21             },
22             4 => Some("MS_KANJI"),
23             _ => CODEPAGE_NUMBER_TO_NAME.get(&codepage).copied()
24         }
25     } else {
26         None
27     }
28 }