From d19cefe058cf1941640f86e4392047820f4e30be Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 7 Jan 2024 15:33:57 -0800 Subject: [PATCH] work --- rust/src/dictionary.rs | 4 ++-- rust/src/raw.rs | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rust/src/dictionary.rs b/rust/src/dictionary.rs index e9eca118ab..4a8e272116 100644 --- a/rust/src/dictionary.rs +++ b/rust/src/dictionary.rs @@ -26,7 +26,7 @@ pub struct Dictionary { pub file_label: Option, pub documents: Vec, pub vectors: HashSet>, - pub attributes: HashSet>, + pub attributes: HashMap>, pub mrsets: HashSet>, pub variable_sets: HashSet>, pub encoding: &'static Encoding, @@ -43,7 +43,7 @@ impl Dictionary { file_label: None, documents: Vec::new(), vectors: HashSet::new(), - attributes: HashSet::new(), + attributes: HashMap::new(), mrsets: HashSet::new(), variable_sets: HashSet::new(), encoding, diff --git a/rust/src/raw.rs b/rust/src/raw.rs index 986bb92a52..65b0f9474c 100644 --- a/rust/src/raw.rs +++ b/rust/src/raw.rs @@ -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, Error> { + pub fn decode<'a>(&self, decoder: &Decoder) -> Result, 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); +pub struct AttributeSet(pub HashMap>); impl AttributeSet { fn parse<'a>( @@ -2202,14 +2204,15 @@ impl AttributeSet { mut input: &'a str, sentinel: Option, ) -> 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; } } -- 2.30.2