2008-04-30 23:06:13 -04:00
|
|
|
! Copyright (C) 2008 Daniel Ehrenberg
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-05-06 21:59:37 -04:00
|
|
|
USING: kernel strings values io.files assocs
|
|
|
|
splitting sequences io namespaces sets io.encodings.8-bit
|
|
|
|
io.encodings.ascii io.encodings.utf8 io.encodings.utf16 ;
|
2008-04-30 22:04:57 -04:00
|
|
|
IN: io.encodings.iana
|
2008-04-30 20:45:12 -04:00
|
|
|
|
2008-04-30 23:06:13 -04:00
|
|
|
<PRIVATE
|
2008-04-30 20:45:12 -04:00
|
|
|
VALUE: n>e-table
|
2008-04-30 22:04:57 -04:00
|
|
|
|
|
|
|
: e>n-table H{
|
|
|
|
{ ascii "US-ASCII" }
|
|
|
|
{ utf8 "UTF-8" }
|
|
|
|
{ utf16 "UTF-16" }
|
|
|
|
{ utf16be "UTF-16BE" }
|
|
|
|
{ utf16le "UTF-16LE" }
|
|
|
|
{ latin1 "ISO-8859-1" }
|
|
|
|
{ latin2 "ISO-8859-2" }
|
|
|
|
{ latin3 "ISO-8859-3" }
|
|
|
|
{ latin4 "ISO-8859-4" }
|
|
|
|
{ latin/cyrillic "ISO-8859-5" }
|
|
|
|
{ latin/arabic "ISO-8859-6" }
|
|
|
|
{ latin/greek "ISO-8859-7" }
|
|
|
|
{ latin/hebrew "ISO-8859-8" }
|
|
|
|
{ latin5 "ISO-8859-9" }
|
|
|
|
{ latin6 "ISO-8859-10" }
|
|
|
|
} ;
|
2008-04-30 23:06:13 -04:00
|
|
|
PRIVATE>
|
2008-04-30 20:45:12 -04:00
|
|
|
|
2008-05-01 21:02:34 -04:00
|
|
|
: name>encoding ( name -- encoding )
|
2008-04-30 20:45:12 -04:00
|
|
|
n>e-table at ;
|
|
|
|
|
2008-05-01 21:02:34 -04:00
|
|
|
: encoding>name ( encoding -- name )
|
2008-04-30 20:45:12 -04:00
|
|
|
e>n-table at ;
|
|
|
|
|
2008-04-30 23:06:13 -04:00
|
|
|
<PRIVATE
|
2008-04-30 22:04:57 -04:00
|
|
|
: parse-iana ( stream -- synonym-set )
|
|
|
|
lines { "" } split [
|
|
|
|
[ " " split ] map
|
|
|
|
[ first { "Name:" "Alias:" } member? ] filter
|
|
|
|
[ second ] map { "None" } diff
|
|
|
|
] map ;
|
|
|
|
|
2008-06-12 04:50:20 -04:00
|
|
|
: more-aliases ( -- assoc )
|
|
|
|
H{
|
|
|
|
{ "UTF8" utf8 }
|
|
|
|
{ "utf8" utf8 }
|
|
|
|
{ "utf-8" utf8 }
|
|
|
|
} ;
|
|
|
|
|
2008-04-30 22:09:27 -04:00
|
|
|
: make-n>e ( stream -- n>e )
|
2008-04-30 22:04:57 -04:00
|
|
|
parse-iana [ [
|
|
|
|
dup [
|
|
|
|
e>n-table value-at
|
|
|
|
[ swap [ set ] with each ]
|
|
|
|
[ drop ] if*
|
|
|
|
] with each
|
2008-06-12 04:50:20 -04:00
|
|
|
] each ] H{ } make-assoc more-aliases assoc-union ;
|
2008-04-30 23:06:13 -04:00
|
|
|
PRIVATE>
|
2008-04-30 20:45:12 -04:00
|
|
|
|
2008-07-28 23:03:13 -04:00
|
|
|
"resource:basis/io/encodings/iana/character-sets"
|
2008-09-28 01:40:41 -04:00
|
|
|
ascii <file-reader> make-n>e to: n>e-table
|