work
[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 use thiserror::Error as ThisError;
10 #[derive(ThisError, Debug)]
11 pub enum Error {
12     #[error("This system file does not indicate its own character encoding.  Using default encoding {0}.  For best results, specify an encoding explicitly.  Use SYSFILE INFO with ENCODING=\"DETECT\" to analyze the possible encodings.")]
13     NoEncoding(String),
14     
15 }
16
17 /// Returns the character set used by the locale configured in the operating
18 /// system.  This should implement roughly the same behavior as the function
19 /// with the same name in Gnulib.  Until then, we'll just use a default.
20 pub fn locale_charset() -> &'static str {
21     "UTF-8"
22 }
23
24 /*
25 pub fn encoding_from_hints(encoding: Option<&str>, codepage: Option<u32>) -> Result<&str, ()> {
26     let label = if encoding.is_some() {
27         encoding
28     } else if let Some(codepage) = codepage {
29         match codepage {
30             1 => Some("EBCDIC-US"),
31             2 | 3 => {
32                 // These ostensibly mean "7-bit ASCII" and "8-bit ASCII"[sic]
33                 // respectively.  However, many files have character code 2 but
34                 // data which are clearly not ASCII.  Therefore, ignore these
35                 // values.
36                 None
37             },
38             4 => Some("MS_KANJI"),
39             _ => CODEPAGE_NUMBER_TO_NAME.get(&codepage).copied()
40         }
41     } else {
42         None
43     };
44 }
45 */