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},
/// 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<Datum<RawString>, ParseError>
+ pub fn parse<'b, T>(&self, input: T) -> Result<OwnedDatum, ParseError>
where
T: Into<EncodedStr<'b>>,
{
})
}
- fn parse_number(&self, input: &str, type_: Type) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_number(&self, input: &str, type_: Type) -> Result<OwnedDatum, ParseErrorKind> {
let style = self.settings.number_style(type_);
let input = input.trim();
}
}
- fn parse_n(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_n(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
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<Datum<RawString>, ParseErrorKind> {
+ fn parse_z(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
let input = input.trim();
if input.is_empty() || input == "." {
return Ok(Datum::sysmis());
}
}
- fn parse_pk(&self, input: &[u8]) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_pk(&self, input: &[u8]) -> Result<OwnedDatum, ParseErrorKind> {
let number = Self::parse_bcd(input)?;
Ok(Datum::Number(Some(self.apply_decimals(number as f64))))
}
- fn parse_p(&self, input: &[u8]) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_p(&self, input: &[u8]) -> Result<OwnedDatum, ParseErrorKind> {
if input.is_empty() {
return Ok(Datum::Number(None));
};
}
}
- fn parse_ib(&self, input: &[u8]) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_ib(&self, input: &[u8]) -> Result<OwnedDatum, ParseErrorKind> {
let number = self.parse_binary(input);
let sign_bit = 1 << (input.len() * 8 - 1);
let number = if (number & sign_bit) == 0 {
Ok(Datum::Number(Some(self.apply_decimals(number as f64))))
}
- fn parse_pib(&self, input: &[u8]) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_pib(&self, input: &[u8]) -> Result<OwnedDatum, ParseErrorKind> {
let number = self.parse_binary(input);
Ok(Datum::Number(Some(self.apply_decimals(number as f64))))
}
- fn parse_rb(&self, input: &[u8]) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_rb(&self, input: &[u8]) -> Result<OwnedDatum, ParseErrorKind> {
let mut bytes = [0; 8];
let len = input.len().min(8);
bytes[..len].copy_from_slice(&input[..len]);
Ok(Datum::Number(number))
}
- fn parse_ahex(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_ahex(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
let mut result = Vec::with_capacity(input.len() / 2);
let mut iter = input.chars();
while let Some(hi) = iter.next() {
}
}
- fn parse_pibhex(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_pibhex(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
self.parse_hex(input)
.map(|value| Datum::Number(value.map(|number| number as f64)))
}
- fn parse_rbhex(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_rbhex(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
self.parse_hex(input)
.map(|value| Datum::Number(value.map(f64::from_bits)))
}
- fn parse_date(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_date(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
let mut p = StrParser(input.trim());
if p.0.is_empty() || p.0 == "." {
return Ok(Datum::sysmis());
Ok(time + seconds)
}
- fn parse_wkday(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_wkday(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
let mut p = StrParser(input.trim());
if p.0.is_empty() || p.0 == "." {
Ok(Datum::sysmis())
}
}
- fn parse_month(&self, input: &str) -> Result<Datum<RawString>, ParseErrorKind> {
+ fn parse_month(&self, input: &str) -> Result<OwnedDatum, ParseErrorKind> {
let mut p = StrParser(input.trim());
if p.0.is_empty() || p.0 == "." {
Ok(Datum::sysmis())