-use std::{borrow::Cow, collections::HashSet};
+use std::{borrow::Cow, collections::{HashSet, HashMap}};
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use encoding_rs::Encoding;
-
+use num::integer::div_ceil;
use crate::{
format::{Spec, UncheckedSpec, Width},
identifier::{Error as IdError, Identifier},
raw::{self, MissingValues},
- {endian::Endian, CategoryLabels, Compression},
+ {endian::Endian, Compression},
};
use thiserror::Error as ThisError;
pub endian: Endian,
pub encoding: &'static Encoding,
pub var_names: HashSet<Identifier>,
+ pub dict_indexes: HashMap<usize, Identifier>,
+ n_dict_indexes: usize,
n_generated_names: usize,
}
assert!(self.n_generated_names < usize::MAX);
}
}
+ fn take_dict_indexes(&mut self, id: &Identifier, width: Width) -> usize {
+ let n = match width {
+ 0 => 1,
+ w => div_ceil(w, 8) as usize,
+ };
+ let dict_index = self.n_dict_indexes;
+ self.dict_indexes.insert(self.n_dict_indexes, id.clone());
+ self.n_dict_indexes += n;
+ dict_index
+
+ }
fn decode_string<'a>(&self, input: &'a [u8], warn: &impl Fn(Error)) -> Cow<'a, str> {
let (output, malformed) = self.encoding.decode_without_bom_handling(input);
if malformed {
.label
.as_ref()
.map(|label| decoder.decode_string(&label.0, &warn).into());
+ decoder.take_dict_indexes(&name, width);
Ok(Some(Variable {
width,
name,
}
}
-#[derive(Clone, Debug)]
-pub enum MultipleResponseType {
- MultipleDichotomy {
- value: String,
- labels: CategoryLabels,
- },
- MultipleCategory,
-}
-#[derive(Clone, Debug)]
-pub struct MultipleResponseSet {
- pub name: String,
- pub label: String,
- pub mr_type: MultipleResponseType,
- pub vars: Vec<String>,
-}
-
-#[derive(Clone, Debug)]
-pub struct MultipleResponseRecord(Vec<MultipleResponseSet>);
-
pub enum Measure {
Nominal,
Ordinal,