1 include!(concat!(env!("OUT_DIR"), "/encodings.rs"));
3 pub fn codepage_from_encoding(encoding: &str) -> Option<u32> {
4 CODEPAGE_NAME_TO_NUMBER
5 .get(encoding.to_ascii_lowercase().as_str())
9 use thiserror::Error as ThisError;
10 #[derive(ThisError, Debug)]
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.")]
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 {
25 pub fn encoding_from_hints(encoding: Option<&str>, codepage: Option<u32>) -> Result<&str, ()> {
26 let label = if encoding.is_some() {
28 } else if let Some(codepage) = codepage {
30 1 => Some("EBCDIC-US"),
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
38 4 => Some("MS_KANJI"),
39 _ => CODEPAGE_NUMBER_TO_NAME.get(&codepage).copied()