aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-03-10 23:30:27 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-03-10 23:34:28 +0100
commit974405a7ad177965551a9ec5b4bf68b7fe4517aa (patch)
tree60e3587236859d41cfcd43377e1586d1d22b5674
parentAdd parsing for all RRULEs except BYDAY. (diff)
downloadcalp-974405a7ad177965551a9ec5b4bf68b7fe4517aa.tar.gz
calp-974405a7ad177965551a9ec5b4bf68b7fe4517aa.tar.xz
Add filter-children!
-rw-r--r--guile_interface.scm.c21
-rw-r--r--vcalendar.scm2
-rw-r--r--vcalendar/primitive.scm1
3 files changed, 24 insertions, 0 deletions
diff --git a/guile_interface.scm.c b/guile_interface.scm.c
index a5921869..3d0bff1e 100644
--- a/guile_interface.scm.c
+++ b/guile_interface.scm.c
@@ -111,6 +111,27 @@ SCM_DEFINE(vcomponent_children, "%vcomponent-children", 1, 0, 0,
return llist;
}
+SCM_DEFINE(vcomponent_filter_children_x, "%vcomponent-filter-children!",
+ 2, 0, 0,
+ (SCM pred, SCM component),
+ "Remove all children from component who DOESN'T satisfy `pred`")
+{
+ scm_assert_foreign_object_type (vcomponent_type, component);
+ vcomponent* cal = scm_foreign_object_ref (component, 0);
+
+ for (LINK(vcomponent)* l = FIRST(&cal->components);
+ l->after != NULL;
+ l = l->after)
+ {
+ if (scm_is_false(scm_call_1 (pred, scm_from_vcomponent(l->value)))) {
+ FFREE(vcomponent, l->value);
+ UNLINK(LINK(vcomponent))(l);
+ }
+ }
+
+ return SCM_UNSPECIFIED;
+}
+
SCM_DEFINE(vcomponent_push_child_x, "%vcomponent-push-child!", 2, 0, 0,
(SCM component, SCM child),
"")
diff --git a/vcalendar.scm b/vcalendar.scm
index 143d9e79..2ce5a438 100644
--- a/vcalendar.scm
+++ b/vcalendar.scm
@@ -59,6 +59,8 @@
(define-public copy-vcomponent %vcomponent-shallow-copy)
+(define-public filter-children! %vcomponent-filter-children!)
+
(define-public (search cal term)
(cdr (let ((events (filter (lambda (ev) (eq? 'VEVENT (type ev)))
(children cal))))
diff --git a/vcalendar/primitive.scm b/vcalendar/primitive.scm
index e575115c..fdce550c 100644
--- a/vcalendar/primitive.scm
+++ b/vcalendar/primitive.scm
@@ -3,6 +3,7 @@
(define-module (vcalendar primitive)
#:export (%vcomponent-children
%vcomponent-push-child!
+ %vcomponent-filter-children!
%vcomponent-parent