Changeset 5331


Ignore:
Timestamp:
Oct 9, 2006, 3:31:28 PM (18 years ago)
Author:
Gary Byers
Message:

:stream-encode/decode functions always write/read something, even if it's
a replacement character of some sort.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-unicode.lisp

    r5321 r5331  
    3939  (max-units-per-char 1)                ;usually 1-4
    4040
    41   ;; Returns NIL if the character can't be encoded, else writes it
    42   ;; to the stream and returns the number of units written.
     41  ;; Writes CHAR (or a replacement character if CHAR can't be encoded)
     42  ;; to STREAM and returns the number of code-units written.
    4343  stream-encode-function                ;(CHAR WRITE-FUNCTION STREAM)
    4444 
    45   ;; Returns a charcter or NIL, possibly calling a function to
    46   ;; obtain the next unit from a stream-like argument
     45  ;; Returns a charcter (possibly #\Replacement_Character) or :EOF.
    4746  stream-decode-function                ;(1ST-UNIT NEXT-UNIT STREAM)
    4847
     
    144143     (let* ((code (char-code char)))
    145144       (declare (type (mod #x110000) code))
    146        (when (< code 256)
    147          (funcall write-function stream code)
    148          1))))
     145       (if (>= code 256)
     146         (setq code (char-code #\Sub)))
     147       (funcall write-function stream code)
     148       1)))
    149149  :stream-decode-function
    150150  (nfunction
     
    236236
    237237  :aliases '(:csASCII :cp637 :IBM637 :us :ISO646-US :ascii :ISO-ir-6)
    238 
    239238  :stream-encode-function
    240239  (nfunction
     
    243242     (let* ((code (char-code char)))
    244243       (declare (type (mod #x110000) code))
    245        (when (< code 128)
    246          (funcall write-function stream code)
    247          1))))
     244       (when (>= code 128)
     245         (setq code (char-code #\Sub)))
     246       (funcall write-function stream code)
     247       1)))
    248248  :stream-decode-function
    249249  (nfunction
     
    253253              (type (unsigned-byte 8) 1st-unit))
    254254     (if (< 1st-unit 128)
    255        (code-char 1st-unit))))
     255       (code-char 1st-unit)
     256       #\Replacement_Character)))
    256257  :vector-encode-function
    257258  (nfunction
     
    434435                     
    435436       (declare (type (mod #x110000) code))
    436        (when c2
    437          (funcall write-function stream code)
    438          1))))
     437       (funcall write-function stream (or c2 (char-code #\Sub)))
     438       1)))
    439439  :stream-decode-function
    440440  (nfunction
     
    637637                       (svref *unicode-2d8-2e0-to-iso8859-3*
    638638                              (the fixnum (- code #x2d8)))))))
    639                      
    640639       (declare (type (mod #x110000) code))
    641        (when c2
    642          (funcall write-function stream code)
    643          1))))
     640       (funcall write-function stream (or c2 (char-code #\Sub)))
     641       1)))
    644642  :stream-decode-function
    645643  (nfunction
     
    852850                     
    853851       (declare (type (mod #x110000) code))
    854        (when c2
    855          (funcall write-function stream code)
    856          1))))
     852       (funcall write-function stream (or c2 (char-code #\Sub)))
     853       1)))
    857854  :stream-decode-function
    858855  (nfunction
     
    10311028                      (logior
    10321029                       (the fixnum (ash (the fixnum (logand #x1f 1st-unit)) 6))
    1033                        (the fixnum (logxor s1 #x80)))))
    1034                    (let* ((s2 (funcall next-unit-function stream)))                 
     1030                       (the fixnum (logxor s1 #x80))))
     1031                     #\Replacement_Character)
     1032                   (let* ((s2 (funcall next-unit-function stream)))
    10351033                     (if (eq s2 :eof)
    10361034                       s2
     
    10511049                                                       (ash (the fixnum (logand s1 #x3f))
    10521050                                                            6))
    1053                                                      (the fixnum (logand s2 #x3f))))))))
     1051                                                     (the fixnum (logand s2 #x3f)))))))
     1052                             #\Replacement_Character)
    10541053                           (if (< 1st-unit #xf8)
    10551054                             (let* ((s3 (funcall next-unit-function stream)))
     
    10751074                                          (the fixnum
    10761075                                            (ash (the fixnum (logxor s2 #x80)) 6))
    1077                                           (the fixnum (logxor s3 #x80)))))))))))))))))))))))
     1076                                          (the fixnum (logxor s3 #x80))))))
     1077                                     #\Replacement_Character))))
     1078                             #\Replacement_Character)))))))))))))
    10781079    :vector-encode-function
    10791080    (nfunction
     
    13821383                                                           (- 1st-unit #xd800))
    13831384                                                         10))
    1384                             (the (unsigned-byte 10) (- 2nd-unit #xdc00))))))))))))
     1385                            (the (unsigned-byte 10) (- 2nd-unit #xdc00)))))
     1386              #\Replacement_Character)))))))
    13851387
    13861388
     
    19751977  (let* ((code (char-code char)))
    19761978    (declare (type (mod #x110000) code))
    1977     (if (< code #x10000)
    1978       (progn
    1979         (funcall write-function stream code)
    1980         1))))
     1979    (if (>= code #x10000)
     1980      (setq code (char-code #\Replacement_Character)))
     1981    (funcall write-function stream code)
     1982    1))
    19811983
    19821984(defun ucs-2-stream-decode (1st-unit next-unit-function stream)
     
    19841986           (ignore next-unit-function stream))
    19851987  ;; CODE-CHAR returns NIL on either half of a surrogate pair.
    1986   (code-char 1st-unit))
     1988  (or (code-char 1st-unit)
     1989      #\Replacement_Character))
    19871990
    19881991
Note: See TracChangeset for help on using the changeset viewer.