@@ -61,6 +61,22 @@ from de.setf.xml suffice."))
61
61
:initarg :documentation :initform nil
62
62
:accessor content-encoding-documentation)))
63
63
64
+ (define-condition simple-encoding-error (simple-type-error )
65
+ ()
66
+ (:default-initargs
67
+ :format-control " The character ~S (code x~ 2,'0 x ) cannot be encoded as ~a ." ))
68
+ (defun simple-encoding-error (&key datum expected-type encoding)
69
+ (error ' simple-encoding-error :datum datum :expected-type expected-type
70
+ :format-arguments (list datum (char-code datum) encoding)))
71
+
72
+ (define-condition simple-decoding-error (simple-type-error )
73
+ ()
74
+ (:default-initargs
75
+ :format-control " The code x~ 2,'0 x cannot be decoded as ~a ." ))
76
+ (defun simple-decoding-error (&key datum expected-type encoding)
77
+ (error ' simple-encoding-error :datum datum :expected-type expected-type
78
+ :format-arguments (list datum encoding)))
79
+
64
80
(def-class-constructor content-encoding
65
81
(:method ((name string ) &rest initargs)
66
82
(declare (dynamic-extent initargs))
@@ -142,7 +158,7 @@ from de.setf.xml suffice."))
142
158
(ash (logand #x3f (read-byte-code)) 6 )
143
159
(logand (read-byte-code) #x3f )))
144
160
(t
145
- (error " Illegal UTF-8 data: x ~ 2,'0 x . " byte1 ))))))
161
+ (simple-decoding- error :datum byte1 :encoding :utf-8 ))))))
146
162
(utf8-code-point-size (char )
147
163
(let ((code (char-code char )))
148
164
(declare (type (mod #x110000 ) code))
@@ -159,8 +175,11 @@ from de.setf.xml suffice."))
159
175
160
176
(flet ((iso-8859-1-encode (char put-byte destination)
161
177
(let ((code (char-code char )))
162
- (declare (type (mod #x100 ) code))
163
- (assert (< code #x100 ) () " Cannot be encoded as iso-8859-1: ~s " char )
178
+ (declare ; (type (mod #x100) code)
179
+ ; ; permit assertion to run
180
+ (optimize (speed 3 ) (safety 0 )))
181
+ (unless (< code #x100 )
182
+ (simple-encoding-error :datum char :encoding :iso-8859-1 ))
164
183
(funcall put-byte destination code)))
165
184
(iso-8859-1-decode (get-byte source)
166
185
(code-char (or (funcall get-byte source)
0 commit comments