From 955ea63c046023784bbe6ee5ee62153d40f3adbb Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 13 Apr 2025 11:10:12 -0700 Subject: [PATCH] rawstr -> rawstrarray in plans for rawstr(&[u8]) --- rust/pspp/src/cooked.rs | 4 ++-- rust/pspp/src/raw.rs | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/rust/pspp/src/cooked.rs b/rust/pspp/src/cooked.rs index 7c68d47c8b..cc1194b726 100644 --- a/rust/pspp/src/cooked.rs +++ b/rust/pspp/src/cooked.rs @@ -14,7 +14,7 @@ use crate::{ self, Cases, DecodedRecord, DocumentRecord, EncodingRecord, Extension, FileAttributeRecord, FloatInfoRecord, HeaderRecord, IntegerInfoRecord, LongName, LongNamesRecord, LongStringMissingValueRecord, LongStringValueLabelRecord, MissingValues, - MultipleResponseRecord, NumberOfCasesRecord, ProductInfoRecord, RawStr, RawWidth, + MultipleResponseRecord, NumberOfCasesRecord, ProductInfoRecord, RawStrArray, RawWidth, ValueLabel, ValueLabelRecord, VarDisplayRecord, VariableAttributeRecord, VariableRecord, VariableSetRecord, VeryLongStringsRecord, ZHeader, ZTrailer, }, @@ -175,7 +175,7 @@ pub enum Error { pub struct Headers { pub header: HeaderRecord, pub variable: Vec>, - pub value_label: Vec, String>>, + pub value_label: Vec, String>>, pub document: Vec>, pub integer_info: Option, pub float_info: Option, diff --git a/rust/pspp/src/raw.rs b/rust/pspp/src/raw.rs index 5144b6286e..62ba39f0e0 100644 --- a/rust/pspp/src/raw.rs +++ b/rust/pspp/src/raw.rs @@ -221,7 +221,7 @@ impl From for Warning { pub enum Record { Header(HeaderRecord), Variable(VariableRecord), - ValueLabel(ValueLabelRecord, RawString>), + ValueLabel(ValueLabelRecord, RawString>), Document(DocumentRecord), IntegerInfo(IntegerInfoRecord), FloatInfo(FloatInfoRecord), @@ -243,7 +243,7 @@ pub enum Record { pub enum DecodedRecord { Header(HeaderRecord), Variable(VariableRecord), - ValueLabel(ValueLabelRecord, String>), + ValueLabel(ValueLabelRecord, String>), Document(DocumentRecord), IntegerInfo(IntegerInfoRecord), FloatInfo(FloatInfoRecord), @@ -657,12 +657,12 @@ impl TryFrom for VarWidth { } } -type RawValue = Value>; +type RawValue = Value>; impl RawValue { pub fn from_raw(raw: &UntypedValue, var_type: VarType, endian: Endian) -> Self { match var_type { - VarType::String => Value::String(RawStr(raw.0)), + VarType::String => Value::String(RawStrArray(raw.0)), VarType::Numeric => Value::Number(endian.parse(raw.0)), } } @@ -723,7 +723,7 @@ impl RawValue { 1..=251 => match var_type { VarType::Numeric => break Self::Number(Some(code as f64 - bias)), VarType::String => { - break Self::String(RawStr(endian.to_bytes(code as f64 - bias))) + break Self::String(RawStrArray(endian.to_bytes(code as f64 - bias))) } }, 252 => { @@ -741,7 +741,7 @@ impl RawValue { break Self::from_raw(&UntypedValue(read_bytes(reader)?), var_type, endian) } 254 => match var_type { - VarType::String => break Self::String(RawStr(*b" ")), // XXX EBCDIC + VarType::String => break Self::String(RawStrArray(*b" ")), // XXX EBCDIC VarType::Numeric => { return Err(Error::CompressedStringExpected { offset: case_start, @@ -1404,15 +1404,15 @@ impl Debug for RawString { } #[derive(Copy, Clone)] -pub struct RawStr(pub [u8; N]); +pub struct RawStrArray(pub [u8; N]); -impl From<[u8; N]> for RawStr { +impl From<[u8; N]> for RawStrArray { fn from(source: [u8; N]) -> Self { Self(source) } } -impl Debug for RawStr { +impl Debug for RawStrArray { fn fmt(&self, f: &mut Formatter) -> FmtResult { write!(f, "{:?}", default_decode(&self.0)) } @@ -1477,7 +1477,7 @@ where pub const MAX_INDEXES: u32 = u32::MAX / 8; } -impl ValueLabelRecord, RawString> { +impl ValueLabelRecord, RawString> { fn read( r: &mut R, endian: Endian, @@ -1586,7 +1586,7 @@ impl ValueLabelRecord, RawString> { }))) } - fn decode(self, decoder: &Decoder) -> ValueLabelRecord, String> { + fn decode(self, decoder: &Decoder) -> ValueLabelRecord, String> { let labels = self .labels .iter() @@ -1616,7 +1616,7 @@ where pub lines: Vec, } -pub type RawDocumentLine = RawStr; +pub type RawDocumentLine = RawStrArray; /// Length of a line in a document. Document lines are fixed-length and /// padded on the right with spaces. @@ -1640,7 +1640,7 @@ impl DocumentRecord { } else { let mut lines = Vec::with_capacity(n); for _ in 0..n { - lines.push(RawStr(read_bytes(r)?)); + lines.push(RawStrArray(read_bytes(r)?)); } let end_offset = r.stream_position()?; Ok(Record::Document(DocumentRecord { @@ -2036,7 +2036,7 @@ where pub var_name: N, /// Missing values. - pub missing_values: Vec>, + pub missing_values: Vec>, } impl LongStringMissingValues { @@ -2088,7 +2088,7 @@ impl ExtensionRecord for LongStringMissingValueRecord { } else { value }; - missing_values.push(RawStr(value)); + missing_values.push(RawStrArray(value)); } missing_value_set.push(LongStringMissingValues { var_name, -- 2.30.2