]> gitweb.factorcode.org Git - factor.git/commitdiff
io.encodings.korean modified
authorYun, Jonghyouk <ageldama@gmail.com>
Fri, 27 Feb 2009 16:34:04 +0000 (01:34 +0900)
committerYun, Jonghyouk <ageldama@gmail.com>
Fri, 27 Feb 2009 16:34:04 +0000 (01:34 +0900)
basis/io/encodings/korean/korean.factor

index a021cfce33c84b9967bd2b6b818a2a6f96567852..07ceb956b38292491929110c491fbff2389bdb32 100644 (file)
@@ -2,11 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: assocs byte-arrays combinators io io.encodings
 io.encodings.ascii io.encodings.iana io.files kernel locals math
-math.order math.parser memoize multiline sequences splitting
-values hashtables io.binary ;
+math.order math.parser values multiline sequences splitting
+values hashtables io.binary io.encodings.asian ;
 IN: io.encodings.korean
 
-! TODO: migrate to common code-table parser (by Dan).
 
 SINGLETON: cp949
 
@@ -14,44 +13,16 @@ cp949 "EUC-KR" register-encoding
 
 <PRIVATE
 
-! parse cp949.txt > table
+VALUE: cp949-table
 
-: cp949.txt-lines ( -- seq )
-    ! "cp949.txt" from ...
-    ! <http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP949.TXT>
-    "vocab:io/encodings/korean/data/cp949.txt"
-    ascii file-lines ;
-
-: drop-comments ( seq -- newseq )
-    [ "#" split1 drop ] map harvest ;
-
-: split-column ( line -- columns )
-    "\t" split 2 head ;
-
-: parse-hex ( s -- n )
-    2 short tail hex> ;
-
-: parse-line ( line -- code-unicode )
-    split-column [ parse-hex ] map ;
-
-: process-codetable-lines ( lines -- assoc )
-    drop-comments [ parse-line ] map ; 
-
-! convert cp949 <> unicode
-
-MEMO: cp949>unicode-table ( -- hashtable )
-    cp949.txt-lines process-codetable-lines >hashtable ;
-
-MEMO: unicode>cp949-table ( -- hashtable )
-    cp949>unicode-table [ swap ] assoc-map ;
-
-unicode>cp949-table drop
+"vocab:io/encodings/korean/data/cp949.txt" <code-table>*
+    to: cp949-table
 
 : cp949>unicode ( b -- u )
-    cp949>unicode-table at ;
+    cp949-table n>u ;
 
 : unicode>cp949 ( u -- b )
-    unicode>cp949-table at ;
+    cp949-table u>n ;
 
 : cp949-1st? ( n -- ? )
     dup [ HEX: 81 HEX: fe between? ] when ;