diff --git a/src/components.rs b/src/components.rs index e81deb2..8e61e76 100644 --- a/src/components.rs +++ b/src/components.rs @@ -433,9 +433,10 @@ mod tests { let event = Event::new().url(url).done(); let serialized = event.to_string(); - let reparsed = - dbg!(Other::try_from(crate::parser::Component::<'_>::try_from(serialized.as_str()).unwrap()) - .unwrap()); + let reparsed = dbg!(Other::try_from( + crate::parser::Component::<'_>::try_from(serialized.as_str()).unwrap() + ) + .unwrap()); assert_eq!(event.get_url(), Some(url)); assert_eq!(reparsed.get_url(), Some(url)); diff --git a/src/parser/utils.rs b/src/parser/utils.rs index c019fbf..3975c67 100644 --- a/src/parser/utils.rs +++ b/src/parser/utils.rs @@ -12,6 +12,99 @@ use pretty_assertions::assert_eq; use super::parsed_string::ParseString; +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +enum ValueType { + /// [RFC 5545 3.3.1](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.1) + Binary, + /// [RFC 5545 3.3.2](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.2) + Boolean, + /// [RFC 5545 3.3.3](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.3) + CalAddress, + /// [RFC 5545 3.3.4](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.4) + Date, + /// [RFC 5545 3.3.5](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.5) + DateTime, + /// [RFC 5545 3.3.6](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.6) + Duration, + /// [RFC 5545 3.3.7](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.7) + Float, + /// [RFC 5545 3.3.8](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.8) + Integer, + /// [RFC 5545 3.3.9](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.9) + Period, + /// [RFC 5545 3.3.10](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.10) + Recur, + /// [RFC 5545 3.3.11](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.11) + Text, + /// [RFC 5545 3.3.12](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.12) + Time, + /// [RFC 5545 3.3.13](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.13) + Uri, + /// [RFC 5545 3.3.14](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.14) + UtcOffset, + Invalid +} + +/// returns the proper value type for a given property according to RFC 5545 +fn value_type(property_name: &str) -> ValueType { + use ValueType::*; + if property_name.chars().any(|c| c.is_lowercase()) { + panic!("property_name must be uppercase"); + } + match property_name { + "CALSCALE" => Text, + "METHOD" => Text, + "PRODID" => Text, + "VERSION" => Text, + "ATTACH" => Uri, // or BINARY + "CATEGORIES" => Text, + "CLASS" => Text, + "COMMENT" => Text, + "DESCRIPTION" => Text, + "GEO" => Float, + "LOCATION" => Text, + "PERCENT-COMPLETE" => Integer, + "PRIORITY" => Integer, + "RESOURCES" => Text, + "STATUS" => Text, // 3.8.1.11 + "SUMMARY" => Text, // 3.8.8.1.12 + "COMPLETED" => DateTime, // 3.8.2.1 + "DTEND" => DateTime, // or DATE // 3.8.2.2 + "DUE" => DateTime, // or DATE // 3.8.2.3 + "DTSTART" => DateTime, // or DATE 3.8.2.4 + "DURATION" => Duration, // 3.8.2.5 + "FREEBUSY" => Period, // 3.8.2.6 + "TRANSP" => Text, // 3.8.2.7 + "TZID" => Text, // 3.8.3.1 + "TZNAME" => Text, // 3.8.3.2 + "TZOFFSETFROM" => UtcOffset, // + "TZOFFSETTO" => UtcOffset, // + "TZURL" => Uri, // + "ATTENDEE" => CalAddress, // 3.8.4.1 + "CONTACT" => Text, // 3.8.4.2 + "ORGANIZER" => CalAddress, // 3.8.4.3 + "RECURRENCE-ID" => DateTime, // 3.8.4.4 + "RELATED-TO" => Text, // + "URL" => Uri, // + "UID" => Text, // + "EXDATE" => DateTime, // or DATE-TIME // + "RDATE" => DateTime, // or PERIOD // or DATE-TIME // or DATE // + "RRULE" => Recur, // + "ACTION" => Text, // + "REPEAT" => Integer, // + "TRIGGER" => Duration, // or DATE-TIME (must be UTC) // 3.8.6.3 + "CREATED" => DateTime, // 3.8.7.1 + "DTSTAMP" => DateTime, // 3.8.7.2 + "LAST-MODIFIED" => DateTime, // 3.8.7.3 + "SEQUENCE" => Integer, // 3.8.7.4 + // 3.8.8.1 + // "An IANA-registered property name" => Any parameter can be specified on this property. + "X-"/* ... */ => Text, // any type 3.8.8.2 + "REQUEST-STATUS" => Text, // 3.8.8.3 + _ => Invalid, + } +} + // TODO: how do I express <> pub fn property_key<'a, E: ParseError<&'a str> + ContextError<&'a str>>( input: &'a str, diff --git a/src/properties.rs b/src/properties.rs index 757eb62..1da596b 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -141,6 +141,8 @@ impl Property { } /// + /// TODO: this should not be used for properties but TEXT + #[allow(dead_code)] fn escape_text(input: &str) -> String { input .replace('\\', r#"\\"#)