-
Notifications
You must be signed in to change notification settings - Fork 313
/
enc-jpn.lisp
63 lines (51 loc) · 2.02 KB
/
enc-jpn.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(in-package "SB-IMPL")
;;; EUC-JP
(declaim (inline ucs-to-eucjp eucjp-to-ucs
mb-len-as-eucjp eucjp-continuation-byte-p))
(defun ucs-to-eucjp (code)
(declare (optimize speed #.*safety-0*)
(type fixnum code))
(if (<= code #x7F) code
(get-multibyte-mapper +ucs-to-eucjp-table+ code)))
(defun eucjp-to-ucs (code)
(declare (optimize speed #.*safety-0*)
(type fixnum code))
(if (<= code #x7F) code
(get-multibyte-mapper +eucjp-to-ucs-table+ code)))
(defun mb-len-as-eucjp (code)
(declare (optimize speed #.*safety-0*)
(type (unsigned-byte 8) code))
(cond ((< code #x80) 1)
((or (= code #x8E) (<= #xA1 code #xFE)) 2)
((= code #x8F) 3)))
(defun eucjp-continuation-byte-p (code)
(declare (optimize speed #.*safety-0*)
(type (unsigned-byte 8) code))
(<= #xA1 code #xFE))
(declaim (muffle-conditions compiler-note))
(define-multibyte-encoding :euc-jp (:euc-jp :eucjp :|eucJP|)
ucs-to-eucjp eucjp-to-ucs mb-len-as-eucjp eucjp-continuation-byte-p)
;;; Shift_JIS
(declaim (inline ucs-to-sjis sjis-to-ucs
mb-len-as-sjis sjis-continuation-byte-p))
(defun ucs-to-sjis (code)
(declare (optimize speed #.*safety-0*)
(type fixnum code))
(if (<= code #x7F) code
(get-multibyte-mapper +ucs-to-sjis-table+ code)))
(defun sjis-to-ucs (code)
(declare (optimize speed #.*safety-0*)
(type fixnum code))
(if (<= code #x7F) code
(get-multibyte-mapper +sjis-to-ucs-table+ code)))
(defun mb-len-as-sjis (code)
(declare (optimize speed #.*safety-0*)
(type (unsigned-byte 8) code))
(cond ((or (< code #x80) (<= #xA1 code #xDF)) 1)
((or (<= #x81 code #x9F) (<= #xE0 code #xFC)) 2)))
(defun sjis-continuation-byte-p (code)
(declare (optimize speed #.*safety-0*)
(type (unsigned-byte 8) code))
(or (<= #x40 code #x7E) (<= #x80 code #xFC)))
(define-multibyte-encoding :shift_jis (:shift_jis :sjis :|Shift_JIS| :cp932)
ucs-to-sjis sjis-to-ucs mb-len-as-sjis sjis-continuation-byte-p)