Paste number 6063: CLX translate function that seems to work in the presence of non-ASCII characters

Paste number 6063: CLX translate function that seems to work in the presence of non-ASCII characters
Pasted by: beach
When:20 years, 2 weeks ago
Share:Tweet this! | http://paste.lisp.org/+4OF
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
;;; remove this file whenever CLX is fixed and McCLIM removes its private
;;; implementation of translate.

(in-package :clim-clx)

(defun translate (src src-start src-end afont dst dst-start)
  (let ((min-char-index (xlib:font-min-char afont))
        (max-char-index (xlib:font-max-char afont)))
    (if (stringp src)
        (loop for i from src-start below src-end
              for j from dst-start
              for index = (char-code (aref src i))
              while (<= min-char-index index max-char-index)
              do (setf (aref dst j) index)
              finally (return i))
        (loop for i from src-start below src-end
              for j from dst-start
              for index = (if (characterp (aref src i)) (char-code (aref src i)) (aref src i))
              while (<= min-char-index index max-char-index)
              do (setf (aref dst j) index)
              finally (return i)))))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.