From 2afa1d1925cb9672c0300febe8c4db0937db3164 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 25 Jul 2025 07:55:48 -0700 Subject: [PATCH] work on datum --- rust/pspp/src/format/parse.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/rust/pspp/src/format/parse.rs b/rust/pspp/src/format/parse.rs index b3fb59a64d..5bff50c528 100644 --- a/rust/pspp/src/format/parse.rs +++ b/rust/pspp/src/format/parse.rs @@ -16,7 +16,7 @@ use crate::{ calendar::{calendar_gregorian_to_offset, DateError}, - data::{Datum, EncodedStr, EncodedString, RawString}, + data::{Datum, EncodedStr, EncodedString, OwnedDatum, RawString}, endian::{Endian, Parse}, format::{DateTemplate, Decimals, Settings, TemplateItem, Type}, settings::{EndianSettings, Settings as PsppSettings}, @@ -190,7 +190,7 @@ impl<'a> ParseValue<'a> { /// input into UTF-8, but this will screw up parsing of binary formats, /// because recoding bytes from (e.g.) windows-1252 into UTF-8, and then /// interpreting them as a binary number yields nonsense. - pub fn parse<'b, T>(&self, input: T) -> Result, ParseError> + pub fn parse<'b, T>(&self, input: T) -> Result where T: Into>, { @@ -239,7 +239,7 @@ impl<'a> ParseValue<'a> { }) } - fn parse_number(&self, input: &str, type_: Type) -> Result, ParseErrorKind> { + fn parse_number(&self, input: &str, type_: Type) -> Result { let style = self.settings.number_style(type_); let input = input.trim(); @@ -312,14 +312,14 @@ impl<'a> ParseValue<'a> { } } - fn parse_n(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_n(&self, input: &str) -> Result { match input.chars().find(|c| !c.is_ascii_digit()) { None => Ok(Datum::Number(Some(input.parse().unwrap()))), Some(nondigit) => Err(ParseErrorKind::Nondigit(nondigit)), } } - fn parse_z(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_z(&self, input: &str) -> Result { let input = input.trim(); if input.is_empty() || input == "." { return Ok(Datum::sysmis()); @@ -396,12 +396,12 @@ impl<'a> ParseValue<'a> { } } - fn parse_pk(&self, input: &[u8]) -> Result, ParseErrorKind> { + fn parse_pk(&self, input: &[u8]) -> Result { let number = Self::parse_bcd(input)?; Ok(Datum::Number(Some(self.apply_decimals(number as f64)))) } - fn parse_p(&self, input: &[u8]) -> Result, ParseErrorKind> { + fn parse_p(&self, input: &[u8]) -> Result { if input.is_empty() { return Ok(Datum::Number(None)); }; @@ -423,7 +423,7 @@ impl<'a> ParseValue<'a> { } } - fn parse_ib(&self, input: &[u8]) -> Result, ParseErrorKind> { + fn parse_ib(&self, input: &[u8]) -> Result { let number = self.parse_binary(input); let sign_bit = 1 << (input.len() * 8 - 1); let number = if (number & sign_bit) == 0 { @@ -434,12 +434,12 @@ impl<'a> ParseValue<'a> { Ok(Datum::Number(Some(self.apply_decimals(number as f64)))) } - fn parse_pib(&self, input: &[u8]) -> Result, ParseErrorKind> { + fn parse_pib(&self, input: &[u8]) -> Result { let number = self.parse_binary(input); Ok(Datum::Number(Some(self.apply_decimals(number as f64)))) } - fn parse_rb(&self, input: &[u8]) -> Result, ParseErrorKind> { + fn parse_rb(&self, input: &[u8]) -> Result { let mut bytes = [0; 8]; let len = input.len().min(8); bytes[..len].copy_from_slice(&input[..len]); @@ -453,7 +453,7 @@ impl<'a> ParseValue<'a> { Ok(Datum::Number(number)) } - fn parse_ahex(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_ahex(&self, input: &str) -> Result { let mut result = Vec::with_capacity(input.len() / 2); let mut iter = input.chars(); while let Some(hi) = iter.next() { @@ -483,17 +483,17 @@ impl<'a> ParseValue<'a> { } } - fn parse_pibhex(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_pibhex(&self, input: &str) -> Result { self.parse_hex(input) .map(|value| Datum::Number(value.map(|number| number as f64))) } - fn parse_rbhex(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_rbhex(&self, input: &str) -> Result { self.parse_hex(input) .map(|value| Datum::Number(value.map(f64::from_bits))) } - fn parse_date(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_date(&self, input: &str) -> Result { let mut p = StrParser(input.trim()); if p.0.is_empty() || p.0 == "." { return Ok(Datum::sysmis()); @@ -609,7 +609,7 @@ impl<'a> ParseValue<'a> { Ok(time + seconds) } - fn parse_wkday(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_wkday(&self, input: &str) -> Result { let mut p = StrParser(input.trim()); if p.0.is_empty() || p.0 == "." { Ok(Datum::sysmis()) @@ -620,7 +620,7 @@ impl<'a> ParseValue<'a> { } } - fn parse_month(&self, input: &str) -> Result, ParseErrorKind> { + fn parse_month(&self, input: &str) -> Result { let mut p = StrParser(input.trim()); if p.0.is_empty() || p.0 == "." { Ok(Datum::sysmis()) -- 2.30.2