Changeset 5327


Ignore:
Timestamp:
Oct 9, 2006, 2:18:35 PM (18 years ago)
Author:
Gary Byers
Message:

Use a hashtable to map characters to their names. (Maybe a sparse vector ?).

Define #\Sub and #\Replacement_Character.

File:
1 edited

Legend:

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

    r5318 r5327  
    2626;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    2727
    28 ;;; Maps character codes to character names, for (some of the) first 2K codes.
    29 (defvar *character-names* #2048(nil))
    30 
    3128;;; Maps character names to characters
    3229(defvar *name->char* (make-hash-table :test #'equalp))
     30;;; Maps characters to (canonical) character names.
     31(defvar *char->name* (make-hash-table :test #'eql))
    3332
    3433;;; This isn't thread-safe.  If the user really wants to register character
    3534;;; names from multiple threads, they should do their own locking.
    3635(defun register-character-name (name char)
    37   (let* ((code (char-code char)))
    38     (when (>= code (length *character-names*))
    39       (setq *character-names* (%extend-vector 0 *character-names* (+ code 1024))))
    40     (setf (gethash name *name->char*) char)   
    41     (unless (svref *character-names* code)
    42       (setf (svref *character-names* code) name))))
     36  (setf (gethash name *name->char*) char)   
     37  (unless (gethash char *char->name*)
     38    (setf (gethash char *char->name*) name)))
    4339
    4440(dolist (pair '(
     
    4844                ("Rubout" . #\177) ("Page" . #\014) ("Tab" . #\011)
    4945                ("Backspace" . #\010) ("Return" . #\015) ("Linefeed" . #\012)
    50                 ;; Other character names.  (When available, standard names
    51                 ;; should be used for printing in preference to any non-standard
    52                 ;; names.)
     46                ;; Other character names.  (When available, standard
     47                ;; names should be used for printing in preference to
     48                ;; any non-standard names.)
    5349                ("Null" . #\000) ("Nul" . #\000)
    5450                ("Bell"  . #\007)       ; ^G , used by Franz (and others with bells.)
     
    5854                ("PageDown" . #\014)("Formfeed" . #\014) ("FF" . #\014)
    5955                ("CR" . #\015)
     56                ("Sub" . #\032)
    6057                ("ESC" .  #\033) ("Escape" . #\033) ("Clear" .  #\033)
    6158                ("Altmode" .  #\033) ("ALT" .  #\033)
     
    18131810                ("Line_Separator" . #\u+2028)
    18141811                ("Paragraph_Separator" . #\u+2029)
     1812                ("Replacement_Character" . #\u+fffd)
    18151813                ))
    18161814  (destructuring-bind (name . char) pair
Note: See TracChangeset for help on using the changeset viewer.