From 4be970ba51e2527f3c2da82ef699b9104bf179f3 Mon Sep 17 00:00:00 2001 Message-Id: <4be970ba51e2527f3c2da82ef699b9104bf179f3.1715113391.git.mdw@distorted.org.uk> From: Mark Wooding Date: Wed, 6 Sep 2006 09:45:26 +0000 Subject: [PATCH] ENCODE-UTF8-STRING now works with zero length string Organization: Straylight/Edgeware From: espen --- gffi/basic-types.lisp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gffi/basic-types.lisp b/gffi/basic-types.lisp index d1da957..b2b0a89 100644 --- a/gffi/basic-types.lisp +++ b/gffi/basic-types.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: basic-types.lisp,v 1.2 2006-06-08 13:24:25 espen Exp $ +;; $Id: basic-types.lisp,v 1.3 2006-09-06 09:45:26 espen Exp $ (in-package "GFFI") @@ -580,7 +580,8 @@ (defun utf8-length (string) ((< char-code #x1FFFFF) 4))))) (defun encode-utf8-string (string &optional location) - (let ((location (or location (allocate-memory (utf8-length string))))) + (let* ((len (utf8-length string)) + (location (or location (allocate-memory len)))) (loop for char across string for i from 0 @@ -599,8 +600,8 @@ (defun encode-utf8-string (string &optional location) ((< char-code #x80) (setf (ref-byte location i) char-code)) ((< char-code #x800) (encode 11)) ((< char-code #x10000) (encode 16)) - ((< char-code #x200000) (encode 21)))) - finally (setf (ref-byte location (1+ i)) 0)) + ((< char-code #x200000) (encode 21))))) + (setf (ref-byte location len) 0) location)) (defun decode-utf8-string (c-string) -- [mdw]