[postmodern-devel] encoding problem

Nicolas Martyanoff khaelin at gmail.com
Tue Feb 15 07:52:02 UTC 2011


Marijn Haverbeke <marijnh at gmail.com> writes:

> Hi Nicolas,
>
> Still no luck reproducing this. Does this simple query fail too?
> (query "select '’'")

All right, I finally figured out the problem. The string came from a
file, which was loaded with:

(defun file-read (filename)
  (with-open-file (stream filename)
    (let ((content (make-string (file-length stream))))
      (read-sequence content stream)
      content)))

This didn't correctly handle multibyte characters, and yielded a string
containg null bytes at the end. This triggered the error.

Using the following works perfectly:

(defun file-read (filename)
  (with-open-file (stream filename :element-type '(unsigned-byte 8))
    (let ((content (make-array (file-length stream)
                               :element-type '(unsigned-byte 8))))
      (read-sequence content stream)
      (babel:octets-to-string content))))

Sorry for the noise, and thank you for trying to help me.

Regards,

-- 
Nicolas Martyanoff
   http://codemore.org
   khaelin at gmail.com




More information about the postmodern-devel mailing list