summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vobject/lib.rs25
-rw-r--r--tests/lib.rs11
2 files changed, 31 insertions, 5 deletions
diff --git a/src/vobject/lib.rs b/src/vobject/lib.rs
index bb99551..10076e5 100644
--- a/src/vobject/lib.rs
+++ b/src/vobject/lib.rs
@@ -12,16 +12,24 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
pub struct Property {
params: HashMap<String, String>,
raw_value: String,
+ prop_group: Option<String>
}
impl Property {
- fn new(params: HashMap<String, String>, raw_value: String) -> Property {
+ fn new(params: HashMap<String, String>, raw_value: String, prop_group: Option<String>) -> Property {
Property {
params: params,
- raw_value: raw_value
+ raw_value: raw_value,
+ prop_group: prop_group
}
}
+ #[doc="Get property group. E.g. a contentline like `foo.FN:Markus` would result in the group \
+ being `\"foo\"`."]
+ pub fn get_prop_group(&self) -> &Option<String> {
+ &self.prop_group
+ }
+
#[doc="Get parameters."]
pub fn get_params(&self) -> &HashMap<String, String> {
&self.params
@@ -131,12 +139,18 @@ props -> Vec<(&'input str, Property)>
= ps:prop ++ eols __ { ps }
prop -> (&'input str, Property)
- = k:name p:params ":" v:value {
- (k, Property::new(p, v))
+ = !"BEGIN:" !"END:" g:group? k:name p:params ":" v:value {
+ (k, Property::new(p, v, g))
}
+group -> String
+ = g:group_name "." { g }
+
+group_name -> String
+ = group_char+ { match_str.into_string() }
+
name -> &'input str
- = !"BEGIN" !"END" iana_token+ { match_str }
+ = iana_token+ { match_str }
params -> HashMap<String, String>
= ps:(";" p:param {p})* {
@@ -176,6 +190,7 @@ quoted_content -> &'input str
= qsafe_char* { match_str }
iana_token = ([a-zA-Z0-9] / "-")+
+group_char = ([a-zA-Z0-9] / "-")
safe_char = !";" !":" !"," value_char
qsafe_char = !dquote value_char // FIXME
diff --git a/tests/lib.rs b/tests/lib.rs
index 89ed4e8..72496fe 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -90,3 +90,14 @@ fn test_escaping() {
assert_eq!(&item.name, s!("VCALENDAR"));
assert_eq!(item.single_prop("ORGANIZER").unwrap().get_raw_value(), s!("mailto:joe@joe.com"));
}
+
+#[test]
+fn test_property_groups() {
+ let item = parse_component(s!(
+ "BEGIN:VCARD\n\
+ foo.EMAIL;TYPE=INTERNET:foo@example.com\n\
+ foo.X-ACTUAL-TYPE:CUSTOM\n\
+ END:VCARD\n")).unwrap();
+ assert_eq!(item.single_prop("EMAIL").unwrap().get_prop_group(), &Some("foo".to_owned()));
+
+}