1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays ascii assocs biassocs interval-maps
4 io.encodings.utf8 io.files kernel math.parser sequences sets
8 : drop-comment ( line -- line' )
9 dup [ "#@" member? ] find drop [ head ] when* ;
11 : drop-comments ( seq -- newseq )
12 [ drop-comment ] map harvest ;
14 : split-column ( line -- columns )
15 " \t" split harvest 2 index-or-length head 2 f pad-tail ;
17 : parse-hex ( s -- n )
19 "0x" ?head [ "U+" ?head [ "Missing 0x or U+" throw ] unless ] unless
23 : parse-line ( line -- code-unicode )
24 split-column [ parse-hex ] map! ;
26 : process-codetable-lines ( lines -- assoc )
27 drop-comments [ parse-line ] map! ;
29 : load-codetable-file ( filename -- biassoc )
30 utf8 file-lines process-codetable-lines >biassoc ;
32 : split-; ( line -- array )
33 ";" split [ [ blank? ] trim ] map! ; inline
35 : load-data-file ( filename -- data )
36 utf8 file-lines drop-comments [ split-; ] map! ;
38 : expand-range ( range -- range' )
39 ".." split1 [ hex> ] bi@ [ 2array ] when* ;
41 : expand-ranges ( ranges -- table )
42 [ [ expand-range ] dip ] assoc-map <interval-map> ;
44 : intern ( value values -- value' )
47 : intern-values ( assoc -- assoc' )
48 dup values members [ intern ] curry assoc-map ;
50 : load-interval-file ( filename -- table )
51 load-data-file intern-values expand-ranges ;