]> gitweb.factorcode.org Git - factor.git/blob - basis/simple-flat-file/simple-flat-file.factor
403fc4d14b82e0a4b8056d0d5120184e867c3dbf
[factor.git] / basis / simple-flat-file / simple-flat-file.factor
1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: sequences splitting kernel math.parser io.files io.encodings.ascii biassocs ;
4 IN: simple-flat-file
5
6 : drop-comments ( seq -- newseq )
7     [ "#" split1 drop ] map harvest ;
8
9 : split-column ( line -- columns )
10     " \t" split harvest 2 short head 2 f pad-tail ;
11
12 : parse-hex ( s -- n )
13     dup [
14         "0x" ?head [ "U+" ?head [ "Missing 0x or U+" throw ] unless ] unless
15         hex>
16     ] when ;
17
18 : parse-line ( line -- code-unicode )
19     split-column [ parse-hex ] map ;
20
21 : process-codetable-lines ( lines -- assoc )
22     drop-comments [ parse-line ] map ; 
23
24 : flat-file>biassoc ( filename -- biassoc )
25     ascii file-lines process-codetable-lines >biassoc ;
26