Making xml-undo words private; adding bytes>xml word

db4
Daniel Ehrenberg 2009-02-13 15:10:34 -06:00
parent 1682a5512a
commit c6680eee60
4 changed files with 24 additions and 6 deletions

View File

@ -174,6 +174,8 @@ PRIVATE>
: [XML : [XML
"XML]" [ string>chunk ] parse-def ; parsing "XML]" [ string>chunk ] parse-def ; parsing
<PRIVATE
: remove-blanks ( seq -- newseq ) : remove-blanks ( seq -- newseq )
[ { [ string? not ] [ [ blank? ] all? not ] } 1|| ] filter ; [ { [ string? not ] [ [ blank? ] all? not ] } 1|| ] filter ;
@ -241,3 +243,5 @@ M: interpolated [undo-xml]
[undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ; [undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
\ interpolate-xml 1 [ undo-xml ] define-pop-inverse \ interpolate-xml 1 [ undo-xml ] define-pop-inverse
PRIVATE>

View File

@ -3,7 +3,7 @@
IN: xml.tests IN: xml.tests
USING: kernel xml tools.test io namespaces make sequences USING: kernel xml tools.test io namespaces make sequences
xml.errors xml.entities.html parser strings xml.data io.files xml.errors xml.entities.html parser strings xml.data io.files
xml.traversal continuations assocs xml.traversal continuations assocs io.encodings.binary
sequences.deep accessors io.streams.string ; sequences.deep accessors io.streams.string ;
! This is insufficient ! This is insufficient
@ -12,8 +12,14 @@ sequences.deep accessors io.streams.string ;
\ string>xml must-infer \ string>xml must-infer
SYMBOL: xml-file SYMBOL: xml-file
[ ] [ "resource:basis/xml/tests/test.xml" [ ] [
[ file>xml ] with-html-entities xml-file set ] unit-test "resource:basis/xml/tests/test.xml"
[ file>xml ] with-html-entities xml-file set
] unit-test
[ t ] [
"resource:basis/xml/tests/test.xml" binary file-contents
[ bytes>xml ] with-html-entities xml-file get =
] unit-test
[ "1.0" ] [ xml-file get prolog>> version>> ] unit-test [ "1.0" ] [ xml-file get prolog>> version>> ] unit-test
[ f ] [ xml-file get prolog>> standalone>> ] unit-test [ f ] [ xml-file get prolog>> standalone>> ] unit-test
[ "a" ] [ xml-file get space>> ] unit-test [ "a" ] [ xml-file get space>> ] unit-test

View File

@ -1,6 +1,6 @@
! Copyright (C) 2005, 2009 Daniel Ehrenberg ! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax xml.data io strings ; USING: help.markup help.syntax xml.data io strings byte-arrays ;
IN: xml IN: xml
HELP: string>xml HELP: string>xml
@ -16,7 +16,11 @@ HELP: file>xml
{ $values { "filename" string } { "xml" xml } } { $values { "filename" string } { "xml" xml } }
{ $description "Opens the given file, reads it in as XML, closes the file and returns the corresponding XML tree. The encoding is automatically detected." } ; { $description "Opens the given file, reads it in as XML, closes the file and returns the corresponding XML tree. The encoding is automatically detected." } ;
{ string>xml read-xml file>xml } related-words HELP: bytes>xml
{ $values { "byte-array" byte-array } { "xml" xml } }
{ $description "Parses a byte array as an XML document. The encoding is automatically detected." } ;
{ string>xml read-xml file>xml bytes>xml } related-words
HELP: read-xml-chunk HELP: read-xml-chunk
{ $values { "stream" "an input stream" } { "seq" "a sequence of elements" } } { $values { "stream" "an input stream" } { "seq" "a sequence of elements" } }
@ -68,6 +72,7 @@ ARTICLE: { "xml" "reading" } "Reading XML"
{ $subsection read-xml-chunk } { $subsection read-xml-chunk }
{ $subsection string>xml-chunk } { $subsection string>xml-chunk }
{ $subsection file>xml } { $subsection file>xml }
{ $subsection bytes>xml }
"To read a DTD:" "To read a DTD:"
{ $subsection read-dtd } { $subsection read-dtd }
{ $subsection file>dtd } { $subsection file>dtd }

View File

@ -4,7 +4,7 @@ USING: accessors arrays io io.encodings.binary io.files
io.streams.string kernel namespaces sequences strings io.encodings.utf8 io.streams.string kernel namespaces sequences strings io.encodings.utf8
xml.data xml.errors xml.elements ascii xml.entities xml.data xml.errors xml.elements ascii xml.entities
xml.writer xml.state xml.autoencoding assocs xml.tokenize xml.writer xml.state xml.autoencoding assocs xml.tokenize
combinators.short-circuit xml.name splitting ; combinators.short-circuit xml.name splitting io.streams.byte-array ;
IN: xml IN: xml
<PRIVATE <PRIVATE
@ -184,6 +184,9 @@ PRIVATE>
: file>xml ( filename -- xml ) : file>xml ( filename -- xml )
binary <file-reader> read-xml ; binary <file-reader> read-xml ;
: bytes>xml ( byte-array -- xml )
binary <byte-reader> read-xml ;
: read-dtd ( stream -- dtd ) : read-dtd ( stream -- dtd )
[ [
H{ } clone extra-entities set H{ } clone extra-entities set