From 93be0d1d4f4601fb88f9755de26f03a20e826b23 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Tue, 4 Jun 2013 09:04:00 -0400 Subject: [PATCH] comment helper function --- dom.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dom.d b/dom.d index c893897..f261266 100644 --- a/dom.d +++ b/dom.d @@ -434,6 +434,24 @@ mixin template DomConvenienceFunctions() { } } +/// finds comments that match the given txt. Case insensitive, strips whitespace. +Element[] findComments(Document document, string txt) { + return findComments(document.root, txt); +} + +/// ditto +Element[] findComments(Element element, string txt) { + txt = txt.strip().toLower(); + Element[] ret; + + foreach(comment; element.getElementsByTagName("#comment")) { + string t = comment.nodeValue().strip().toLower(); + if(t == txt) + ret ~= comment; + } + + return ret; +} // I'm just dicking around with this struct ElementCollection {