Changeset 71 for lang/elisp/pdicv-mode/trunk/nt-bocu.el
- Timestamp:
- 01/30/09 23:52:02 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/pdicv-mode/trunk/nt-bocu.el
r67 r71 1 1 ;;; nt-bocu.el --- decode/encode BOCU-1 string (via utf-8, so requires Mule-UCS) 2 2 ;; 3 ;; Copyright (C) 2005 Naoya TOZUKA. All Rights Reserved.3 ;; Copyright (C) 2005-2009 naoya_t. All Rights Reserved. 4 4 ;; 5 ;; Author: Naoya TOZUKA <pdicviewer@gmail.com> 6 ;; Maintainer: Naoya TOZUKA <pdicviewer@gmail.com> 7 ;; Primary distribution site: http://pdicviewer.naochan.com/el/ 5 ;; Author: naoya_t <naoya.t@aqua.plala.or.jp> 6 ;; Maintainer: naoya_t <naoya.t@aqua.plala.or.jp> 7 ;; Primary distribution site: 8 ;; http://lambdarepos.svnrepository.com/svn/share/lang/elisp/pdicv-mode/trunk 8 9 ;; 9 10 ;; Created: 12 Feb 2005 … … 38 39 ((>= tr #x10) (- tr 10)) ;10 ... 19 >> 06 ... 0F 39 40 (t (1- tr)) ;01 ... 06 >> 00 ... 05 40 ) ; cond41 ) 41 )) 42 42 43 (defsubst nt:bocu-encode-trail-char (c) 43 44 "[BOCU] encode trail char" … … 47 48 ((>= c #x06) (+ c 10)) ;06 ... 0F >> 10 ... 19 48 49 (t (1+ c)) ;00 ... 05 >> 01 ... 06 49 ); cond 50 ) 50 )) 51 51 52 52 (defun nt:bocustr-to-rawcode-list (s) … … 67 67 ; trail 1 68 68 (setq tr (nt:bocu-decode-trail-char (aref s i)) i (1+ i)) 69 (setq diff (+ diff tr)) 70 ) 69 (setq diff (+ diff tr)) ) 71 70 ((< lead #x25) ;22-24 (L T T) 72 71 (setq diff (+ -10513 (* (- lead #x25) 243 243))) … … 76 75 ; trail 1 77 76 (setq tr (nt:bocu-decode-trail-char (aref s i)) i (1+ i)) 78 (setq diff (+ diff tr)) 79 ) 77 (setq diff (+ diff tr)) ) 80 78 ((< lead #x50) ;25-4f (L T) 81 79 (setq diff (+ -64 (* (- lead #x50) 243))) 82 80 ; trail 1 83 81 (setq tr (nt:bocu-decode-trail-char (aref s i)) i (1+ i)) 84 (setq diff (+ diff tr)) 85 ) 82 (setq diff (+ diff tr)) ) 86 83 ((< lead #xd0) ;50-cf (L) 87 (setq diff (- lead #x90)) 88 ) 84 (setq diff (- lead #x90)) ) 89 85 ((< lead #xfb) ;d0-fa (L T) 90 86 (setq diff (+ 64 (* (- lead #xd0) 243))) 91 87 ; trail 1 92 88 (setq tr (nt:bocu-decode-trail-char (aref s i)) i (1+ i)) 93 (setq diff (+ diff tr)) 94 ) 89 (setq diff (+ diff tr)) ) 95 90 ((< lead #xfe) ;fb-fd (L T T) 96 91 (setq diff (+ 10513 (* (- lead #xfb) 243 243))) … … 100 95 ; trail 1 101 96 (setq tr (nt:bocu-decode-trail-char (aref s i)) i (1+ i)) 102 (setq diff (+ diff tr)) 103 ) 97 (setq diff (+ diff tr)) ) 104 98 ((= lead #xfe) ;fe (L T T T) 105 99 (setq diff 187660) … … 112 106 ; trail 1 113 107 (setq tr (nt:bocu-decode-trail-char (aref s i)) i (1+ i)) 114 (setq diff (+ diff tr)) 115 ) 116 ((= lead #xff) ; reset 117 ) 118 ); end of cond. 108 (setq diff (+ diff tr)) ) 109 ((= lead #xff) )) ; reset 119 110 120 111 (cond … … 122 113 (push lead l) 123 114 ; (setq r (concat r (string lead))) 124 (if (< lead #x20) (setq pc #x40)) ;#x20�ʤ餽�Τޤ� ) 125 ((< lead #xff) 115 (if (< lead #x20) (setq pc #x40)) ) ;#x20�ʤ餽�Τޤ� ((< lead #xff) 126 116 (progn 127 117 (setq code (+ pc diff)) 128 118 (if (< code 0) (setq code 0));; error recovery 129 130 119 (push code l) 131 120 ; (setq r (concat r (if (> code 0) (code-to-utf8 code) "?"))) … … 140 129 )); pc 141 130 )) 142 (t (setq pc #x40)); #xFF: reset 143 ) 144 ); wend 145 (nreverse l) 146 ); let 147 ) 131 (t (setq pc #x40)) )); #xFF: reset 132 (nreverse l) )) 148 133 149 134 (defun nt:diff-to-bocustr (diff) … … 160 145 (setq t1 (% diff 243)) (setq diff (/ diff 243)) 161 146 ;(setq t0 diff) 162 (string #x21 (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2) (nt:bocu-encode-trail-char t3)) 163 ) 164 ) 147 (string #x21 (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2) (nt:bocu-encode-trail-char t3)) )) 165 148 ((< diff -10513) ; [-187660,-10513) : 22-24 166 149 (progn … … 169 152 (setq t1 (% diff 243)) (setq diff (/ diff 243)) 170 153 (setq t0 diff) 171 (string (+ #x22 t0) (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2)) 172 ) 173 ) 154 (string (+ #x22 t0) (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2)) )) 174 155 ((< diff -64) ; [-10513,-64) : 25-4F 175 156 (progn … … 177 158 (setq t1 (% diff 243)) (setq diff (/ diff 243)) 178 159 (setq t0 diff) 179 (string (+ #x25 t0) (nt:bocu-encode-trail-char t1)) 180 ) 181 ) 160 (string (+ #x25 t0) (nt:bocu-encode-trail-char t1)) )) 182 161 ((< diff 64) ; [-64,63) : 50-CF 183 162 (progn 184 163 (setq diff (- diff -64)) 185 164 (setq t0 diff) 186 (string (+ #x50 t0)) 187 ) 188 ) 165 (string (+ #x50 t0)) )) 189 166 ((< diff 10513) ; [64,10513) : D0-FA 190 167 (progn … … 192 169 (setq t1 (% diff 243)) (setq diff (/ diff 243)) 193 170 (setq t0 diff) 194 (string (+ #xD0 t0) (nt:bocu-encode-trail-char t1)) 195 ) 196 ) 171 (string (+ #xD0 t0) (nt:bocu-encode-trail-char t1)) )) 197 172 ((< diff 187660) ; [10513,187660) : FB-FD 198 173 (progn … … 201 176 (setq t1 (% diff 243)) (setq diff (/ diff 243)) 202 177 (setq t0 diff) 203 (string (+ #xFB t0) (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2)) 204 ) 205 ) 178 (string (+ #xFB t0) (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2)) )) 206 179 ((< diff 14536567) ; [187660,14536567) : FE 207 180 (progn … … 211 184 (setq t1 (% diff 243)) (setq diff (/ diff 243)) 212 185 ;(setq t0 diff) 213 (string #xFE (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2) (nt:bocu-encode-trail-char t3)) 214 ) 215 ) 216 (t (throw 'bocu-encode-diff 'overflow-exception)) 217 ); cond 218 ); let 219 ); caught 220 ) 186 (string #xFE (nt:bocu-encode-trail-char t1) (nt:bocu-encode-trail-char t2) (nt:bocu-encode-trail-char t3)) )) 187 (t (throw 'bocu-encode-diff 'overflow-exception)) )))) 221 188 222 189 (defun nt:rawcode-list-to-bocustr (l) ; not tested much … … 234 201 ((and (<= #x4E00 code) (<= code #x9FA5)) #x7711) 235 202 ((and (<= #xAC00 code) (<= code #xD7A3)) #xC1D1) 236 (t (+ (logand code #xffff80) #x40)))) 237 ); let* 238 ); wend 239 s 240 ); let* 241 ) 203 (t (+ (logand code #xffff80) #x40)))) )) 204 s)) 242 205 243 206 (defsubst nt:bocu-decode (s) … … 245 208 (let* ((rawcode-list (nt:bocustr-to-rawcode-list s)) 246 209 (utf8str (nt:rawcode-list-to-utf8str rawcode-list))) 247 (decode-coding-string utf8str 'utf-8) 248 ) 249 ) 210 (decode-coding-string utf8str 'utf-8) )) 250 211 251 212 (defsubst nt:bocu-encode (s) … … 253 214 (let* ((utf8str (encode-coding-string s 'utf-8)) 254 215 (rawcode-list (nt:utf8str-to-rawcode-list utf8str)) 255 (bocustr (nt:rawcode-list-to-bocustr rawcode-list)) 256 ) 257 bocustr 258 ) 259 ) 216 (bocustr (nt:rawcode-list-to-bocustr rawcode-list))) 217 bocustr)) 260 218 261 219 ;;; nt-bocu.el ends here