Adding string->xexpr from troels

svn: r15233
This commit is contained in:
Jay McCarthy 2009-06-22 19:46:22 +00:00
parent c94c436c18
commit f409c1e36d
3 changed files with 10 additions and 1 deletions

View File

@ -463,7 +463,7 @@ END
(local (local
[(define (test-xml->xexpr str xe) [(define (test-xml->xexpr str xe)
(test-equal? str (xml->xexpr (document-element (read-xml (open-input-string str)))) xe)) (test-equal? str (string->xexpr str) xe))
(define (test-xexpr->string xe str) (define (test-xexpr->string xe str)
(test-equal? (format "~S" xe) (xexpr->string xe) str))] (test-equal? (format "~S" xe) (xexpr->string xe) str))]
(test-suite (test-suite

View File

@ -1,6 +1,7 @@
#lang scheme #lang scheme
(require scheme/pretty (require scheme/pretty
"structures.ss" "structures.ss"
"reader.ss"
"writer.ss") "writer.ss")
;; Xexpr ::= String ;; Xexpr ::= String
@ -232,6 +233,9 @@
(write-xml/content (xexpr->xml xexpr) port) (write-xml/content (xexpr->xml xexpr) port)
(get-output-string port))) (get-output-string port)))
(define (string->xexpr str)
(xml->xexpr (read-xml/element (open-input-string str))))
;; bcompose : (a a -> c) (b -> a) -> (b b -> c) ;; bcompose : (a a -> c) (b -> a) -> (b b -> c)
(define (bcompose f g) (define (bcompose f g)
(lambda (x y) (f (g x) (g y)))) (lambda (x y) (f (g x) (g y))))
@ -241,6 +245,7 @@
[exn:invalid-xexpr-code (exn:invalid-xexpr? . -> . any/c)] [exn:invalid-xexpr-code (exn:invalid-xexpr? . -> . any/c)]
[xexpr/c contract?] [xexpr/c contract?]
[xexpr? (any/c . -> . boolean?)] [xexpr? (any/c . -> . boolean?)]
[string->xexpr (string? . -> . xexpr/c)]
[xexpr->string (xexpr/c . -> . string?)] [xexpr->string (xexpr/c . -> . string?)]
[xml->xexpr (content/c . -> . xexpr/c)] [xml->xexpr (content/c . -> . xexpr/c)]
[xexpr->xml (xexpr/c . -> . content/c)] [xexpr->xml (xexpr/c . -> . content/c)]

View File

@ -265,6 +265,10 @@ Converts an @tech{X-expression} into XML content.}
Converts an @tech{X-expression} into a string containing XML.} Converts an @tech{X-expression} into a string containing XML.}
@defproc[(string->xexpr [str string?]) xexpr/c]{
Converts XML represented with a string into an @tech{X-expression}.}
@defproc[((eliminate-whitespace [tags (listof symbol?)] @defproc[((eliminate-whitespace [tags (listof symbol?)]
[choose (boolean? . -> . boolean?)]) [choose (boolean? . -> . boolean?)])
[elem element?]) [elem element?])