Output encoding support, using Babel
authorDavid Lichteblau <david@lichteblau.com>
Sun, 13 Apr 2008 18:57:00 +0000 (13 20:57 +0200)
committerDavid Lichteblau <david@radon.(none)>
Sun, 13 Apr 2008 18:57:00 +0000 (13 20:57 +0200)
src/parse/unparse.lisp

index 4f93ad3..b0cc805 100644 (file)
 (defmethod hax:characters ((sink sink) data)
   (let ((y (sink-ystream sink)))
     (if (find (caar (stack sink)) '("script" "style") :test 'equalp)
-       (write-rod data (sink-ystream sink))
+       (ystream-write-escapable-rod data (sink-ystream sink))
        (loop for c across data do (unparse-datachar-readable c y)))))
 
 (defmethod hax:unescaped ((sink sink) data)
        do
         (cond ((rune= c #/&)
                (if (and (< i (length str)) (rune= (rune str i) #/{))
-                   (write-rune c y)
-                   (write-rod '#.(string-rod "&amp;") y)))
-              ((rune= c #/\") (write-rod '#.(string-rod "&quot;") y))
-              ((rune= c #/U+000A) (write-rod '#.(string-rod "&#10;") y))
-              ((rune= c #/U+000D) (write-rod '#.(string-rod "&#13;") y))
+                   (ystream-write-rune c y)
+                   (ystream-write-rod '#.(string-rod "&amp;") y)))
+              ((rune= c #/\") (ystream-write-rod '#.(string-rod "&quot;") y))
+              ((rune= c #/U+000A) (ystream-write-rod '#.(string-rod "&#10;") y))
+              ((rune= c #/U+000D) (ystream-write-rod '#.(string-rod "&#13;") y))
               (t
-               (write-rune c y))))))
+               (ystream-write-escapable-rune c y))))))
 
 (defun unparse-datachar (c ystream)
-  (cond ((rune= c #/&) (write-rod '#.(string-rod "&amp;") ystream))
-        ((rune= c #/<) (write-rod '#.(string-rod "&lt;") ystream))
-        ((rune= c #/>) (write-rod '#.(string-rod "&gt;") ystream))
-        ((rune= c #/\") (write-rod '#.(string-rod "&quot;") ystream))
-        ((rune= c #/U+0009) (write-rod '#.(string-rod "&#9;") ystream))
-        ((rune= c #/U+000A) (write-rod '#.(string-rod "&#10;") ystream))
-        ((rune= c #/U+000D) (write-rod '#.(string-rod "&#13;") ystream))
+  (cond ((rune= c #/&) (ystream-write-rod '#.(string-rod "&amp;") ystream))
+        ((rune= c #/<) (ystream-write-rod '#.(string-rod "&lt;") ystream))
+        ((rune= c #/>) (ystream-write-rod '#.(string-rod "&gt;") ystream))
+        ((rune= c #/\") (ystream-write-rod '#.(string-rod "&quot;") ystream))
+        ((rune= c #/U+0009) (ystream-write-rod '#.(string-rod "&#9;") ystream))
+        ((rune= c #/U+000A) (ystream-write-rod '#.(string-rod "&#10;") ystream))
+        ((rune= c #/U+000D) (ystream-write-rod '#.(string-rod "&#13;") ystream))
         (t
-         (write-rune c ystream))))
+         (ystream-write-escapable-rune c ystream))))
 
 (defun unparse-datachar-readable (c ystream)
-  (cond ((rune= c #/&) (write-rod '#.(string-rod "&amp;") ystream))
-        ((rune= c #/<) (write-rod '#.(string-rod "&lt;") ystream))
-        ((rune= c #/>) (write-rod '#.(string-rod "&gt;") ystream))
-        ((rune= c #/\") (write-rod '#.(string-rod "&quot;") ystream))
-        ((rune= c #/U+000D) (write-rod '#.(string-rod "&#13;") ystream))
+  (cond ((rune= c #/&) (ystream-write-rod '#.(string-rod "&amp;") ystream))
+        ((rune= c #/<) (ystream-write-rod '#.(string-rod "&lt;") ystream))
+        ((rune= c #/>) (ystream-write-rod '#.(string-rod "&gt;") ystream))
+        ((rune= c #/\") (ystream-write-rod '#.(string-rod "&quot;") ystream))
+        ((rune= c #/U+000D) (ystream-write-rod '#.(string-rod "&#13;") ystream))
         (t
-          (write-rune c ystream))))
+          (ystream-write-escapable-rune c ystream))))
 
 (defun unparse-dtd-string (str sink)
   (let ((y (sink-ystream sink)))
     (loop for rune across str do (unparse-dtd-char rune y))))
 
 (defun unparse-dtd-char (c ystream)
-  (cond ((rune= c #/%) (write-rod '#.(string-rod "&#37;") ystream))
-        ((rune= c #/&) (write-rod '#.(string-rod "&amp;") ystream))
-        ((rune= c #/<) (write-rod '#.(string-rod "&lt;") ystream))
-        ((rune= c #/>) (write-rod '#.(string-rod "&gt;") ystream))
-        ((rune= c #/\") (write-rod '#.(string-rod "&quot;") ystream))
-        ((rune= c #/U+0009) (write-rod '#.(string-rod "&#9;") ystream))
-        ((rune= c #/U+000A) (write-rod '#.(string-rod "&#10;") ystream))
-        ((rune= c #/U+000D) (write-rod '#.(string-rod "&#13;") ystream))
+  (cond ((rune= c #/%) (ystream-write-rod '#.(string-rod "&#37;") ystream))
+        ((rune= c #/&) (ystream-write-rod '#.(string-rod "&amp;") ystream))
+        ((rune= c #/<) (ystream-write-rod '#.(string-rod "&lt;") ystream))
+        ((rune= c #/>) (ystream-write-rod '#.(string-rod "&gt;") ystream))
+        ((rune= c #/\") (ystream-write-rod '#.(string-rod "&quot;") ystream))
+        ((rune= c #/U+0009) (ystream-write-rod '#.(string-rod "&#9;") ystream))
+        ((rune= c #/U+000A) (ystream-write-rod '#.(string-rod "&#10;") ystream))
+        ((rune= c #/U+000D) (ystream-write-rod '#.(string-rod "&#13;") ystream))
         (t
-         (write-rune c ystream))))
+         (ystream-write-escapable-rune c ystream))))
 
 (defun %write-rune (c sink)
-  (write-rune c (sink-ystream sink)))
+  (ystream-write-rune c (sink-ystream sink)))
 
 (defun %write-rod (r sink)
-  (write-rod r (sink-ystream sink)))
+  (ystream-write-rod r (sink-ystream sink)))
 
 
 ;;;; convenience functions for PTless HTML serialization