From: Ben Pfaff Date: Sat, 21 Dec 2024 21:37:30 +0000 (-0800) Subject: Cleanup. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee168914d8d7660c7913ec70de4de65c59bf148a;p=pspp Cleanup. --- diff --git a/rust/pspp/src/cooked.rs b/rust/pspp/src/cooked.rs index f5cd59af93..b2ae515f8b 100644 --- a/rust/pspp/src/cooked.rs +++ b/rust/pspp/src/cooked.rs @@ -18,7 +18,6 @@ use crate::{ use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use encoding_rs::Encoding; use indexmap::set::MutableValues; -use num::Integer; use thiserror::Error as ThisError; pub use crate::raw::{CategoryLabels, Compression}; @@ -448,9 +447,14 @@ pub fn decode( n_generated_names: 0, }; - let mut header_vars = headers.variable.iter().enumerate(); let mut var_index_map = HashMap::new(); - while let Some((value_index, input)) = header_vars.next() { + let mut value_index = 0; + for (index, input) in headers + .variable + .iter() + .enumerate() + .filter(|(_index, record)| record.width != -1) + { let name = trim_end_spaces(input.name.to_string()); let name = match Identifier::from_encoding(&name, encoding) { Ok(name) => { @@ -506,21 +510,22 @@ pub fn decode( }, ); - // Skip long string continuation records. - if input.width > 0 { - #[allow(unstable_name_collisions)] - for _ in 1..input.width.div_ceil(&8) { - if let Some((_, continuation)) = header_vars.next() { - if continuation.width == -1 { - continue; - } - } - return Err(Error::TBD); + // Check for long string continuation records. + let n_values = input.n_values().unwrap(); + for offset in 1..n_values { + if headers + .variable + .get(index + offset) + .is_none_or(|record| record.width != -1) + { + warn(Error::TBD); + break; } } let dict_index = dictionary.add_var(variable).unwrap(); assert_eq!(var_index_map.insert(value_index, dict_index), None); + value_index += n_values; } if let Some(weight_index) = headers.header.weight_index { diff --git a/rust/pspp/src/raw.rs b/rust/pspp/src/raw.rs index b8fc79e7cf..776677e563 100644 --- a/rust/pspp/src/raw.rs +++ b/rust/pspp/src/raw.rs @@ -1267,6 +1267,20 @@ where pub label: Option, } +impl VariableRecord +where + S: Debug, + V: Debug, +{ + pub fn n_values(&self) -> Option { + match self.width { + 0 => Some(1), + 1..=255 => Some((self.width as usize).div_ceil(8)), + _ => None, + } + } +} + impl Debug for VariableRecord where S: Debug,