work
[pspp] / rust / src / raw.rs
index ead9da8341f33eb0dcd032bafa128b663017da06..b5968e67b94a24780bab517702b5dbe6dfbba710 100644 (file)
@@ -135,17 +135,17 @@ pub enum Record {
     Document(DocumentRecord),
     IntegerInfo(IntegerInfoRecord),
     FloatInfo(FloatInfoRecord),
-    VariableSets(UnencodedString),
+    VariableSets(TextRecord),
     VarDisplay(VarDisplayRecord),
     MultipleResponse(MultipleResponseRecord),
     LongStringValueLabels(LongStringValueLabelRecord),
     Encoding(EncodingRecord),
     NumberOfCases(NumberOfCasesRecord),
-    ProductInfo(UnencodedString),
-    LongNames(UnencodedString),
-    LongStrings(UnencodedString),
-    FileAttributes(UnencodedString),
-    VariableAttributes(UnencodedString),
+    ProductInfo(TextRecord),
+    LongNames(TextRecord),
+    LongStrings(TextRecord),
+    FileAttributes(TextRecord),
+    VariableAttributes(TextRecord),
     OtherExtension(Extension),
     EndOfHeaders(u32),
     ZHeader(ZHeader),
@@ -337,7 +337,7 @@ impl TryFrom<[u8; 4]> for Magic {
     }
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, Hash)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub enum VarType {
     Numeric,
     String,
@@ -1455,6 +1455,21 @@ impl ExtensionRecord for NumberOfCasesRecord {
     }
 }
 
+#[derive(Clone, Debug)]
+pub struct TextRecord {
+    /// Offset from the start of the file to the start of the record.
+    pub offset: u64,
+
+    /// The text content of the record.
+    pub text: UnencodedString,
+}
+
+impl From<Extension> for TextRecord {
+    fn from(source: Extension) -> Self {
+        TextRecord { offset: source.offset, text: source.data.into() }
+    }
+}
+
 #[derive(Clone, Debug)]
 pub struct Extension {
     /// Offset from the start of the file to the start of the record.
@@ -1552,12 +1567,12 @@ impl Extension {
                 endian,
                 |_| (),
             )?)),
-            5 => Ok(Record::VariableSets(UnencodedString(extension.data))),
-            10 => Ok(Record::ProductInfo(UnencodedString(extension.data))),
-            13 => Ok(Record::LongNames(UnencodedString(extension.data))),
-            14 => Ok(Record::LongStrings(UnencodedString(extension.data))),
-            17 => Ok(Record::FileAttributes(UnencodedString(extension.data))),
-            18 => Ok(Record::VariableAttributes(UnencodedString(extension.data))),
+            5 => Ok(Record::VariableSets(extension.into())),
+            10 => Ok(Record::ProductInfo(extension.into())),
+            13 => Ok(Record::LongNames(extension.into())),
+            14 => Ok(Record::LongStrings(extension.into())),
+            17 => Ok(Record::FileAttributes(extension.into())),
+            18 => Ok(Record::VariableAttributes(extension.into())),
             _ => Ok(Record::OtherExtension(extension)),
         }
     }