]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - patches/cxml-19d0b.patch
Support textual XTM name variants with qualified original contracts and offline evidence
[topic-maps.git] / patches / cxml-19d0b.patch
1 --- a/xml/xml-parse.lisp
2 +++ b/xml/xml-parse.lisp
3 @@ -2517,22 +2517,41 @@
4 (otherwise
5 (wf-error input "p/markup-decl ~S" (peek-token input))))))
6
7 +(defparameter *topic-maps-encoding-patch* "19d0b-1")
8 +
9 (defun setup-encoding (input xml-header)
10 - (when (xml-header-encoding xml-header)
11 - (let ((enc (find-encoding (xml-header-encoding xml-header)))
12 - (xstream (car (zstream-input-stack input))))
13 - (cond ((eql enc :utf-8)
14 - (let ((old (xstream-encoding xstream)))
15 - (unless (eql old :utf-8)
16 - (with-simple-restart (continue "Stick with ~a" old)
17 - (wf-error input "Header says UTF-8, but BOM says ~a." old)))))
18 - (enc (setf (xstream-encoding xstream) enc))
19 - (t
20 - (warn "There is no such encoding: ~S." (xml-header-encoding xml-header)))))))
21 + (let* ((xstream (car (zstream-input-stack input)))
22 + (initial (getf (xstream-plist xstream) :initial-encoding
23 + (xstream-encoding xstream)))
24 + (detection (getf (xstream-plist xstream) :encoding-detection))
25 + (name (xml-header-encoding xml-header))
26 + (declared (and name (string-upcase name)))
27 + (utf16p (member initial '(:utf-16-big-endian :utf-16-little-endian))))
28 + (cond ((null declared)
29 + (when (eq detection :signature)
30 + (wf-error input "BOM-less UTF-16LE/BE requires an explicit encoding declaration.")))
31 + ((string= declared "UTF-16")
32 + (unless (and utf16p (eq detection :bom))
33 + (wf-error input "UTF-16 requires a matching BOM.")))
34 + ((member declared '("UTF-16LE" "UTF-16BE") :test #'string=)
35 + (unless (and (eq detection :signature)
36 + (eq initial (if (string= declared "UTF-16LE")
37 + :utf-16-little-endian :utf-16-big-endian)))
38 + (wf-error input "UTF-16LE/BE declaration disagrees with the input encoding.")))
39 + (t
40 + (let ((encoding (find-encoding name)))
41 + (unless encoding (wf-error input "Unknown encoding: ~A" name))
42 + (when (or utf16p (and (eq detection :bom) (not (eq encoding :utf-8))))
43 + (wf-error input "Encoding declaration ~A disagrees with the BOM/signature." name))
44 + (setf (xstream-encoding xstream) encoding))))
45 + (setf (getf (xstream-plist xstream) :encoding-declaration-checked) t)))
46
47 (defun set-full-speed (input)
48 (let ((xstream (car (zstream-input-stack input))))
49 (when xstream
50 + (when (and (eq (getf (xstream-plist xstream) :encoding-detection) :signature)
51 + (not (getf (xstream-plist xstream) :encoding-declaration-checked)))
52 + (wf-error input "BOM-less UTF-16LE/BE requires an XML encoding declaration."))
53 (set-to-full-speed xstream))))
54
55 (defun p/ext-subset (input)