From 79d2daaaeb4e9c8e274752cba02fe73f177bd393 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 27 Jun 2015 13:22:30 -0700 Subject: [PATCH] correct handling of `valid-char?` for 6.0 --- txexpr/core-predicates.rkt | 19 +++++++++++++++++-- txexpr/tests.rkt | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/txexpr/core-predicates.rkt b/txexpr/core-predicates.rkt index 0a077b3..270fbaf 100644 --- a/txexpr/core-predicates.rkt +++ b/txexpr/core-predicates.rkt @@ -1,6 +1,21 @@ #lang racket/base -(require sugar/define xml racket/match) -(provide (all-defined-out) valid-char? cdata? cdata xexpr->string xexpr?) +(require sugar/define (prefix-in xml: xml) racket/match) +(provide (all-defined-out) cdata? cdata xexpr->string xexpr?) + +; Section 2.2 of XML 1.1 +; (XML 1.0 is slightly different and more restrictive) +(define (valid-char? i) + (and (exact-nonnegative-integer? i) + (or (<= #x1 i #xD7FF) + (<= #xE000 i #xFFFD) + (<= #x10000 i #x10FFFF)))) + +(define (xexpr? x) + (or (txexpr? x) (xml:xexpr? x) (valid-char? x))) + +(define cdata xml:cdata) +(define cdata? xml:cdata?) +(define xexpr->string xml:xexpr->string) (define (txexpr-short? x) (match x diff --git a/txexpr/tests.rkt b/txexpr/tests.rkt index 3b74fa4..8d28317 100644 --- a/txexpr/tests.rkt +++ b/txexpr/tests.rkt @@ -68,6 +68,8 @@ (check-false (txexpr-elements? '("foo" "bar" ((key "value"))))) ; malformed (check-true (txexpr? '(p))) + (check-true (txexpr? '(div 2))) + (check-true (txexpr? '(div (div ((foo "bar")) 2)))) (check-true (txexpr? '(p "foo" "bar"))) (check-true (txexpr? '(p ((key "value")) "foo" "bar"))) (check-true (txexpr? '(p 123))) ; content is a number