Extracting Structure from HTML using Adam's dom.d
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 22 08:33:28 PST 2015
On Thursday, 22 January 2015 at 09:27:17 UTC, Per Nordlöw wrote:
> BTW: Would you be interested in receiving a PR for dom.d where
> I replace array allocations with calls to lazy ranges?
Maybe. It was on my todo list to do that for getElementsByTagName
at least, which is supposed to be a live list rather than a copy
of references.
querySelectorAll, however, is supposed to be a copy, so don't
want that to be a range. (this is to match the W3C standard and
what javascript does)
There are lazy range functions in there btw: element.tree is a
lazy range. If you combine it with stuff like
std.algorithm.filter and map, etc., it'd be easy to do a bunch of
them.
getElementsByTagName for example is filter!((e) => e.tagName ==
want)(element.tree). So the lazy implementations could just be in
those terms.
(actually though, that's not hard to write on the spot, so maybe
it should just be explained instead of adding/changing methods.
It is nice that they are plain methods instead of templates now
because they can be so easily wrapped in things like script code)
More information about the Digitalmars-d-learn
mailing list