#| -*-Scheme-*-
-$Id: xml-output.scm,v 1.31 2004/02/24 20:48:32 cph Exp $
+$Id: xml-output.scm,v 1.32 2004/02/25 21:00:49 cph Exp $
Copyright 2001,2002,2003,2004 Massachusetts Institute of Technology
(write-xml-1 xml port options))))
(define (set-coding xml port)
- (port/set-coding port
- (or (normalize-coding port
- (and (xml-document? xml)
- (xml-document-declaration xml)))
- 'UTF-8))
- (port/set-line-ending port 'TEXT))
+ (let ((coding
+ (or (normalize-coding port
+ (and (xml-document? xml)
+ (xml-document-declaration xml)))
+ 'UTF-8)))
+ (port/set-coding port coding)
+ (port/set-line-ending port 'TEXT)
+ (if (coding-requires-bom? coding)
+ (write-char #\U+FEFF port))))
(define (xml->wide-string xml . options)
(call-with-wide-output-string
#| -*-Scheme-*-
-$Id: xml-parser.scm,v 1.57 2004/02/24 20:36:42 cph Exp $
+$Id: xml-parser.scm,v 1.58 2004/02/25 21:00:52 cph Exp $
Copyright 2001,2002,2003,2004 Massachusetts Institute of Technology
0)))
(lose c0 c1 c2 c3))))
((#\U+3C)
- (values #f '8-BIT #\<))
+ (values #f 'NO-BOM #\<))
(else
(values 'UTF-8 'UTF-8 c0))))))
\f
((UTF-32)
(if (not (eq? declared coding))
(lose)))
- ((8-BIT)
- (if (memq declared
- '(UTF-16 UTF-16BE UTF-16LE UTF-32 UTF-32BE UTF-32LE))
+ ((NO-BOM)
+ (if (coding-requires-bom? declared)
(lose))
(port/set-coding port (or declared 'UTF-8)))
((ANY) unspecific)
(if (and coding (not (port/known-coding? port coding)))
(error:bad-range-argument coding #f))
coding))
+
+(define (coding-requires-bom? coding)
+ (memq coding '(UTF-16 UTF-16BE UTF-16LE UTF-32 UTF-32BE UTF-32LE)))
\f
;;;; Top level
#| -*-Scheme-*-
-$Id: xml.pkg,v 1.38 2004/02/24 20:36:23 cph Exp $
+$Id: xml.pkg,v 1.39 2004/02/25 21:00:45 cph Exp $
Copyright 2001,2002,2003,2004 Massachusetts Institute of Technology
(export (runtime xml)
alphabet:name-initial
alphabet:name-subsequent
+ coding-requires-bom?
normalize-coding))
(define-package (runtime xml output)