work
[pspp] / rust / src / encoding.rs
index 296e4e65a8e4f32a61e4e415318610e3180513f7..d22f6927477218f59f564dd6a93a8bfd79d77d3c 100644 (file)
@@ -6,8 +6,24 @@ pub fn codepage_from_encoding(encoding: &str) -> Option<u32> {
         .copied()
 }
 
-pub fn encoding_from_hints(encoding: Option<&str>, codepage: Option<u32>) -> Option<&str> {
-    if encoding.is_some() {
+use thiserror::Error as ThisError;
+#[derive(ThisError, Debug)]
+pub enum Error {
+    #[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.")]
+    NoEncoding(String),
+    
+}
+
+/// Returns the character set used by the locale configured in the operating
+/// system.  This should implement roughly the same behavior as the function
+/// with the same name in Gnulib.  Until then, we'll just use a default.
+pub fn locale_charset() -> &'static str {
+    "UTF-8"
+}
+
+/*
+pub fn encoding_from_hints(encoding: Option<&str>, codepage: Option<u32>) -> Result<&str, ()> {
+    let label = if encoding.is_some() {
         encoding
     } else if let Some(codepage) = codepage {
         match codepage {
@@ -24,5 +40,6 @@ pub fn encoding_from_hints(encoding: Option<&str>, codepage: Option<u32>) -> Opt
         }
     } else {
         None
-    }
+    };
 }
+*/