work
[pspp] / rust / src / raw.rs
index 986bb92a52bb389726c8875582130305aa3772d2..65b0f9474cf8326c98af843c7f4b95e894633749 100644 (file)
@@ -11,7 +11,7 @@ use std::{
     borrow::Cow,
     cell::RefCell,
     cmp::Ordering,
-    collections::VecDeque,
+    collections::{VecDeque, HashMap},
     fmt::{Debug, Display, Formatter, Result as FmtResult},
     io::{Error as IoError, Read, Seek, SeekFrom},
     iter::repeat,
@@ -246,6 +246,8 @@ impl Record {
             }),
         }
     }
+
+    
 }
 
 // If `s` is valid UTF-8, returns it decoded as UTF-8, otherwise returns it
@@ -2093,7 +2095,7 @@ impl TextRecord {
             text: extension.data.into(),
         }
     }
-    fn decode<'a>(&self, decoder: &Decoder) -> Result<Option<Record>, Error> {
+    pub fn decode<'a>(&self, decoder: &Decoder) -> Result<Option<Record>, Error> {
         match self.rec_type {
             TextRecordType::VariableSets => Ok(Some(Record::VariableSets(
                 VariableSetRecord::decode(self, decoder),
@@ -2194,7 +2196,7 @@ impl Attribute {
 }
 
 #[derive(Clone, Debug)]
-pub struct AttributeSet(pub Vec<Attribute>);
+pub struct AttributeSet(pub HashMap<Identifier, Vec<String>>);
 
 impl AttributeSet {
     fn parse<'a>(
@@ -2202,14 +2204,15 @@ impl AttributeSet {
         mut input: &'a str,
         sentinel: Option<char>,
     ) -> Result<(AttributeSet, &'a str), Error> {
-        let mut attributes = Vec::new();
+        let mut attributes = HashMap::new();
         let rest = loop {
             match input.chars().next() {
                 None => break input,
                 c if c == sentinel => break &input[1..],
                 _ => {
                     let (attribute, rest) = Attribute::parse(decoder, input)?;
-                    attributes.push(attribute);
+                    // XXX report duplicate name
+                    attributes.insert(attribute.name, attribute.values);
                     input = rest;
                 }
             }