Skip to content
Snippets Groups Projects
Commit 6692aa7e authored by rtoy's avatar rtoy
Browse files

Pull out the range tests for CJK Ideographs and Hangul Syllables and

put the tests into their own functions so that the limits are on one
place.
parent d2b9eace
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
;;; This code was written by Paul Foley and has been placed in the public ;;; This code was written by Paul Foley and has been placed in the public
;;; domain. ;;; domain.
;;; ;;;
(ext:file-comment "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unidata.lisp,v 1.9 2010/09/15 21:06:38 rtoy Exp $") (ext:file-comment "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unidata.lisp,v 1.10 2010/09/15 23:32:06 rtoy Exp $")
;;; ;;;
;;; ********************************************************************** ;;; **********************************************************************
;;; ;;;
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
(defconstant +unidata-path+ #p"ext-formats:unidata.bin") (defconstant +unidata-path+ #p"ext-formats:unidata.bin")
(defvar *unidata-version* "$Revision: 1.9 $") (defvar *unidata-version* "$Revision: 1.10 $")
(defstruct unidata (defstruct unidata
range range
...@@ -635,6 +635,20 @@ ...@@ -635,6 +635,20 @@
(defvar *reverse-hangul-jungseong*) (defvar *reverse-hangul-jungseong*)
(defvar *reverse-hangul-jongseong*) (defvar *reverse-hangul-jongseong*)
(declaim (inline cjk-ideograph-p hangul-syllable-p))
(defun cjk-ideograph-p (code)
;; Search src/i18n/UnicodeData.txt for "CJK Ideograph" to find the
;; values here.
(or (<= #x3400 code #x4DB5) ; CJK Ideograph Extension A
(<= #x4E00 code #x9FCB) ; CJK Ideograph
(<= #x20000 code #x2A6D6) ; CJK Ideograph Extension B
(<= #X2A700 code #X2B734))) ; CJK Ideograph Extension C
(defun hangul-syllable-p (code)
;; Search src/i18n/UnicodeData.txt for "Hangule Syllable" to find
;; the values here.
(<= #xAC00 code #xD7A3))
(defun unicode-name-to-codepoint (name) (defun unicode-name-to-codepoint (name)
(declare (type string name)) (declare (type string name))
(cond ((and (> (length name) 22) (cond ((and (> (length name) 22)
...@@ -645,11 +659,7 @@ ...@@ -645,11 +659,7 @@
:start (+ x 9)))) :start (+ x 9))))
(code (and n (values (parse-integer name :start n :radix 16))))) (code (and n (values (parse-integer name :start n :radix 16)))))
(when (and code (when (and code (cjk-ideograph-p code))
(or (<= #x3400 code #x4DB5) ; CJK Ideograph Extension A
(<= #x4E00 code #x9FCB) ; CJK Ideograph
(<= #x20000 code #x2A6D6) ; CJK Ideograph Extension B
(<= #X2A700 code #X2B734))) ; CJK Ideograph Extension C
code))) code)))
((and (> (length name) 15) ((and (> (length name) 15)
(or (string= name "HANGUL SYLLABLE" :end1 15) (or (string= name "HANGUL SYLLABLE" :end1 15)
...@@ -743,12 +753,9 @@ ...@@ -743,12 +753,9 @@
s)))) s))))
(defun unicode-name (code) (defun unicode-name (code)
(cond ((or (<= #x3400 code #x4DB5) ; CJK Ideograph Extension A (cond ((cjk-ideograph-p code)
(<= #x4E00 code #x9FCB) ; CJK Ideograph
(<= #x20000 code #x2A6D6) ; CJK Ideograph Extension B
(<= #X2A700 code #X2B734)) ; CJK Ideograph Extension C
(format nil "CJK UNIFIED IDEOGRAPH-~4,'0X" code)) (format nil "CJK UNIFIED IDEOGRAPH-~4,'0X" code))
((<= #xAC00 code #xD7A3) ; Hangul Syllable ((hangul-syllable-p code) ; Hangul Syllable
(apply #'concatenate 'string "HANGUL SYLLABLE " (apply #'concatenate 'string "HANGUL SYLLABLE "
(loop for ch across (unicode-decomp code) (loop for ch across (unicode-decomp code)
as code = (char-code ch) as code = (char-code ch)
...@@ -856,7 +863,7 @@ ...@@ -856,7 +863,7 @@
(defun unicode-decomp (code &optional (compatibility t)) (defun unicode-decomp (code &optional (compatibility t))
(declare (optimize (speed 3) (space 0) (safety 0)) (declare (optimize (speed 3) (space 0) (safety 0))
(type codepoint code)) (type codepoint code))
(if (<= #xAC00 code #xD7A3) (if (hangule-syllable-p code)
;; Hangul syllables. (See ;; Hangul syllables. (See
;; http://www.unicode.org/reports/tr15/#Hangul for the ;; http://www.unicode.org/reports/tr15/#Hangul for the
;; algorithm.) ;; algorithm.)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment