1 ! Copyright (C) 2009 Daniel Ehrenberg, Jonghyouk Yun.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs biassocs byte-arrays classes.parser
4 classes.singleton combinators endian generic io io.encodings
5 kernel math.bitwise math.order parser sequences simple-flat-file
9 TUPLE: euc { table biassoc read-only } ;
17 swapd table>> value-at [
19 [ swap stream-write1 ] [
20 h>b/b swap 2byte-array
23 ] [ encode-error ] if* ;
25 : euc-multibyte? ( ch -- ? )
28 :: decode-multibyte ( ch stream encoding -- char )
30 [ ch swap 2byte-array be> encoding table>> at ]
31 [ replacement-char ] if* ;
33 M:: euc decode-char ( stream encoding -- char/f )
36 { [ dup not ] [ drop f ] }
37 { [ dup euc-multibyte? ] [ stream encoding decode-multibyte ] }
38 [ encoding table>> at ]
41 : define-method ( class word definition -- )
42 [ create-method ] dip define ;
46 : setup-euc ( word file-name -- singleton-class biassoc )
47 [ dup define-singleton-class ]
48 [ load-codetable-file ] bi* ;
50 :: define-recursive-methods ( class data words -- )
52 class word [ drop data word execute ] define-method
55 : euc-methods ( singleton-class biassoc -- )
56 [ euc-table set-word-prop ] [
58 { <encoder> <decoder> }
59 define-recursive-methods
62 : define-euc ( word file-name -- )
63 setup-euc euc-methods ;
68 ! EUC: euc-kr "vocab:io/encodings/korean/cp949.txt"
69 scan-new-class scan-object define-euc ;