Skip to content

Commit

Permalink
Addressing some PR comments
Browse files Browse the repository at this point in the history
- Moved inner function for multi-check into property impl. This also now checks for additional properties. The only remaining thing here is the special case for DESCRIPTION on VJOURNAL
- Iterating over properties instead of splitting into two vec
  • Loading branch information
daveterra committed Nov 16, 2023
1 parent 06c4769 commit 550b649
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ pub trait Component {
write_crlf!(out, "UID:{}", Uuid::new_v4())?;
}

for properties in self.multi_properties().values() {
for property in properties {
property.fmt_write(out)?;
}
for property in self.multi_properties().values().flatten() {
property.fmt_write(out)?;
}

for component in self.components() {
Expand Down
22 changes: 11 additions & 11 deletions src/parser/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,22 @@ impl From<Component<'_>> for Other {

impl From<Component<'_>> for InnerComponent {
fn from(component: Component) -> Self {
fn is_multi(property: &Property) -> bool {
property.name.to_string() == "ATTENDEE"
}

let (multi, single): (Vec<_>, Vec<_>) =
component.properties.into_iter().partition(is_multi);

let mut from_component = Self {
properties: single
.into_iter()
.map(|p| (p.name.clone().into_owned().into(), p.into()))
properties: component
.properties
.iter()
.filter(|p| !p.is_multi_property())
.map(|p| (p.name.clone().into_owned().into(), p.to_owned().into()))
.collect(),
components: component.components.into_iter().map(Other::from).collect(),
multi_properties: Default::default(),
};

for p in multi.into_iter() {
for p in component
.properties
.into_iter()
.filter(|p| p.is_multi_property())
{
from_component.insert_multi(p);
}

Expand Down Expand Up @@ -487,6 +486,7 @@ fn test_multi_properties() {
.into(),
],
);

assert_parser!(
inner_component,
r#"
Expand Down
22 changes: 22 additions & 0 deletions src/parser/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ impl Property<'_> {
write_crlf!(out, "{}", fold_line(&line))?;
Ok(())
}

pub(crate) fn is_multi_property(&self) -> bool {
// [RFC-5545](https://datatracker.ietf.org/doc/html/rfc5545) states that the following
// "MAY occur more than once" in a VEVENT, VTODO, VJOURNAL, and VFREEBUSY.
// Note: A VJOURNAL can also contain multiple DECRIPTION but this is not covered here.
[
"ATTACH",
"ATTENDEE",
"CATEGORIES",
"COMMENT",
"CONTACT",
"EXDATE",
"FREEBUSY",
"IANA-PROP",
"RDATE",
"RELATED",
"RESOURCES",
"RSTATUS",
"X-PROP",
]
.contains(&self.name.as_str())
}
}

impl fmt::Display for Property<'_> {
Expand Down

0 comments on commit 550b649

Please sign in to comment.