xml.traversal: adding deep-children>string.

John Benediktsson 2012-12-17 11:58:30 -08:00
parent 589af77192
commit 07194b7a13
2 changed files with 8 additions and 1 deletions

View File

@ -9,6 +9,8 @@ IN: xml.traversal.tests
[ "" ] [ "<foo/>" string>xml children>string ] unit-test
[ "bar qux" ] [ "<foo>bar <baz>qux</baz></foo>" string>xml deep-children>string ] unit-test
[ "blah" ] [ "<foo attr='blah'/>" string>xml-chunk "foo" deep-tag-named "attr" attr ] unit-test
[ { "blah" } ] [ "<foo attr='blah'/>" string>xml-chunk "foo" deep-tags-named [ "attr" attr ] map ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel namespaces sequences words io assocs
quotations strings parser lexer arrays xml.data
quotations strings parser lexer arrays xml.data make
splitting vectors sequences.deep combinators fry memoize ;
IN: xml.traversal
@ -15,6 +15,11 @@ IN: xml.traversal
[ concat ]
} cond ;
: deep-children>string ( tag -- string )
children>> [
[ dup tag? [ deep-children>string ] when % ] each
] "" make ;
: children-tags ( tag -- sequence )
children>> [ tag? ] filter ;