Docs and tests for io.encodings.iana

db4
Daniel Ehrenberg 2008-04-30 22:06:13 -05:00
parent 82679024ce
commit 0bde52d63b
5 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1 @@
Daniel Ehrenberg

View File

@ -0,0 +1,12 @@
USING: help.syntax help.markup ;
IN: io.encodings.iana
HELP: name>encoding
{ $values { "string" "an encoding name" } { "encoding" "an encoding descriptor" } }
{ "Given an IANA-registered encoding name, find the encoding descriptor that represents it, or " { $code f } " if it is not found (either not implemented in Factor or not registered)." } ;
HELP: encoding>name
{ $values { "encoding" "an encoding descriptor" } { "name" "an encoding name" } }
{ "Given an encoding descriptor, return the preferred IANA name." } ;
{ name>encoding encoding>name } related-words

View File

@ -0,0 +1,5 @@
USING: io.encodings.iana io.encodings.ascii tools.test ;
[ ascii ] [ "US-ASCII" name>encoding ] unit-test
[ ascii ] [ "ASCII" name>encoding ] unit-test
[ "US-ASCII" ] [ ascii encoding>name ] unit-test

View File

@ -1,8 +1,11 @@
! Copyright (C) 2008 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: kernel strings unicode.syntax.backend io.files assocs
splitting sequences io namespaces sets
io.encodings.ascii io.encodings.utf8 io.encodings.utf16 io.encodings.8-bit ;
IN: io.encodings.iana
<PRIVATE
VALUE: n>e-table
: e>n-table H{
@ -22,6 +25,7 @@ VALUE: n>e-table
{ latin5 "ISO-8859-9" }
{ latin6 "ISO-8859-10" }
} ;
PRIVATE>
: name>encoding ( string -- encoding )
n>e-table at ;
@ -29,6 +33,7 @@ VALUE: n>e-table
: encoding>name ( encoding -- string )
e>n-table at ;
<PRIVATE
: parse-iana ( stream -- synonym-set )
lines { "" } split [
[ " " split ] map
@ -44,6 +49,7 @@ VALUE: n>e-table
[ drop ] if*
] with each
] each ] H{ } make-assoc ;
PRIVATE>
"resource:extra/io/encodings/iana/character-sets"
ascii <file-reader> make-n>e \ n>e-table set-value

View File

@ -0,0 +1 @@
Tables for IANA encoding names