From: Ben Pfaff Date: Sat, 3 Jan 2026 18:17:59 +0000 (-0800) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=131cca3a1277b12e2ee53f4bb98ec6ade73e6be0;p=pspp cleanup --- diff --git a/rust/pspp/src/data.rs b/rust/pspp/src/data.rs index 433a013cda..799d4ebf6f 100644 --- a/rust/pspp/src/data.rs +++ b/rust/pspp/src/data.rs @@ -90,6 +90,10 @@ pub trait RawString: Debug + PartialEq + Eq + PartialOrd + Ord + Hash { self.raw_string_bytes().is_empty() } + fn is_spaces(&self) -> bool { + self.without_trailing_spaces().is_empty() + } + fn len(&self) -> usize { self.raw_string_bytes().len() } @@ -710,6 +714,10 @@ where } } + pub fn is_spaces(&self) -> bool { + self.is_string_and(|s| s.is_spaces()) + } + pub fn as_raw(&self) -> Datum<&ByteStr> { self.as_ref().map_string(|s| s.as_ref()) } diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index ebb53f3d37..59331d3a76 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -852,26 +852,27 @@ impl SourceVariable { series: &mut BTreeMap<&'a str, Series>, ) -> bool { let label_series = if let Some(label_variable) = &self.label_variable { - let Some(label_series) = series.get(label_variable.references.as_str()) else { + if let Some(label_series) = series.get(label_variable.references.as_str()) { + Some(label_series) + } else { return false; - }; - Some(label_series) + } } else { None }; - let data = if let Some(source) = data.get(&self.source) + let mut data = if let Some(source) = data.get(&self.source) && let Some(values) = source.get(&self.variable) { - values.as_slice() + values.clone() } else { - &[] + Vec::new() }; let mut map = Map::new(); let format = map.remap_formats(&self.format, &self.string_format); - let mut data = Vec::from(data); if !map.0.is_empty() { map.apply(&mut data); + map = Map::new(); } else if let Some(label_series) = label_series { map.insert_labels(&data, label_series, format); } @@ -2187,15 +2188,12 @@ fn decode_dimension<'a>( for end in 1..=cats.len() { let dv1 = &variable.values[cats[start].index]; if end >= cats.len() || &variable.values[cats[end].index].value != &dv1.value { - let name = variable.map.lookup(dv1); - if name.is_number_or(|s| !s.is_empty()) { + if !variable.map.lookup(dv1).is_spaces() { let name = variable.new_name(dv1, footnotes); - let mut group = Group::new(name); - for i in start..end { - group.push(cats[i].category.clone()); - } let next_cat = CatBuilder { - category: Category::from(group), + category: Group::new(name) + .with_multiple(cats[start..end].iter().map(|c| c.category.clone())) + .into(), index: cats[start].index, leaves: cats[start].leaves.start..cats[end - 1].leaves.end, location: cats[start].location.parent(), @@ -2204,7 +2202,6 @@ fn decode_dimension<'a>( .insert(dv1.category().unwrap() /*XXX?*/, next_cat.location); next_cats.push(next_cat); } else { - // XXX coordinate_to_index? for cat in &cats[start..end] { next_cats.push(cat.clone()); }