[Ecls-list] Invalid octet sequence -> SIMPLE-ERROR

Matthew Mondor mm_lists at pulsar-zone.net
Thu Aug 6 15:54:53 UTC 2009


On Thu, 6 Aug 2009 01:48:41 -0400
Matthew Mondor <mm_lists at pulsar-zone.net> wrote:

> After verification, it appears that condition objects slots can have
> accessor functions which may be called from handler-bind, and that
> indeed a possible choice would be to pass the invalid sequence through

So a modification to custom-read-line which uses the invalid sequence
list provided by the condition (this one actually works better than the
older read-byte one which only would account for the first invalid
character when the condition typically returns three bytes):

(defun custom-read-line (stream)
  (let ((line (make-array 0
                          :element-type 'character
                          :adjustable t
                          :fill-pointer t)))
    (flet ((add-char (c)
             (vector-push-extend c line 1)))
      (loop
         do
           (let ((c #+ecl(handler-case
                             (read-char stream)
                           (simple-error ()
                             #\?))
                    #+sbcl(handler-bind
                              ((sb-int:stream-decoding-error
                                #'(lambda (e)
                                    ;; Treat invalid UTF-8 octets as
                                    ;; ISO-8859 characters.
                                    (mapcar #'(lambda (c)
                                                (when (> c 127)
                                                  (add-char (code-char c))))
                                            (sb-int:character-decoding-error-octets e))
                                    (invoke-restart 'sb-int:attempt-resync))))
                            (read-char stream))))
             (when (char= c #\Newline)
               (return (values line t)))
             (add-char c))))))
-- 
Matt




More information about the ecl-devel mailing list