incomplete work
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 5 Jun 2024 00:59:52 +0000 (17:59 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 5 Jun 2024 00:59:52 +0000 (17:59 -0700)
rust/src/cooked.rs
rust/src/raw.rs

index 71d65adddd6cfa0ddd50e458d2df9259f7140535..3e97e404dfb0f682242cce51cb1002cdc8bc3c25 100644 (file)
@@ -10,9 +10,9 @@ use crate::{
         self, Cases, DecodedRecord, DocumentRecord, EncodingRecord, Extension, FileAttributeRecord,
         FloatInfoRecord, HeaderRecord, IntegerInfoRecord, LongNamesRecord,
         LongStringMissingValueRecord, LongStringValueLabelRecord, MultipleResponseRecord,
-        NumberOfCasesRecord, ProductInfoRecord, RawStr, ValueLabelRecord, VarDisplayRecord,
-        VariableAttributeRecord, VariableRecord, VariableSetRecord, VeryLongStringsRecord, ZHeader,
-        ZTrailer,
+        NumberOfCasesRecord, ProductInfoRecord, RawStr, ValueLabel, ValueLabelRecord,
+        VarDisplayRecord, VariableAttributeRecord, VariableRecord, VariableSetRecord,
+        VeryLongStringsRecord, ZHeader, ZTrailer,
     },
 };
 use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
@@ -546,6 +546,13 @@ pub fn decode(
                 variables: long_string_variables,
             });
         }
+
+        for dict_index in dict_indexes {
+            let mut variable = &dictionary.variables[dict_index];
+            for ValueLabel { value, label } in record.labels.iter().cloned() {
+                
+            }
+        }
     }
 
     let metadata = Metadata::decode(&headers, warn);
@@ -561,8 +568,7 @@ fn trim_end_spaces(mut s: String) -> String {
 /// replaced by LF.
 ///
 /// (A product that identifies itself as VOXCO INTERVIEWER 4.3 produces system
-/// files that use CR-only line ends in the file label and extra product
-/// info.) */
+/// files that use CR-only line ends in the file label and extra product info.)
 fn fix_line_ends(s: &str) -> String {
     let mut out = String::with_capacity(s.len());
     let mut s = s.chars().peekable();
index f492710378de48c1a7a641b31110559e6353d853..14231b18a695c47590f65c9f9042bc0d4b38cdd3 100644 (file)
@@ -826,7 +826,7 @@ impl RawValue {
         Ok(Some(values))
     }
 
-    fn decode(self, decoder: &Decoder) -> Value<String> {
+    pub fn decode(self, decoder: &Decoder) -> Value<String> {
         match self {
             Self::Number(x) => Value::Number(x),
             Self::String(s) => Value::String(decoder.decode_exact_length(&s.0).into()),
@@ -1302,7 +1302,10 @@ impl VariableRecord<RawString, RawStr<8>> {
         let start_offset = r.stream_position()?;
         let width: i32 = endian.parse(read_bytes(r)?);
         if !(-1..=255).contains(&width) {
-            return Err(Error::BadVariableWidth { start_offset, width });
+            return Err(Error::BadVariableWidth {
+                start_offset,
+                width,
+            });
         }
         let code_offset = r.stream_position()?;
         let has_variable_label: u32 = endian.parse(read_bytes(r)?);
@@ -1540,8 +1543,13 @@ impl ValueLabelRecord<RawStr<8>, RawString> {
                 n,
                 max: Self::MAX_INDEXES,
             });
+        } else if n == 0 {
+            warn(Warning::NoVarIndexes {
+                offset: index_offset,
+            });
+            return Ok(None);
         }
-        
+
         let index_offset = r.stream_position()?;
         let mut dict_indexes = Vec::with_capacity(n as usize);
         let mut invalid_indexes = Vec::new();
@@ -1562,9 +1570,6 @@ impl ValueLabelRecord<RawStr<8>, RawString> {
         }
 
         let Some(&first_index) = dict_indexes.first() else {
-            warn(Warning::NoVarIndexes {
-                offset: index_offset,
-            });
             return Ok(None);
         };
         let var_type = var_types[first_index as usize - 1];