io.encodings.latin1: adding a memory efficient latin1 encoding.

windows-high-dpi
John Benediktsson 2018-02-28 08:54:50 -08:00
parent 7dd32181dd
commit 093e6411be
3 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,5 @@
USING: help.markup help.syntax io.encodings.latin1 ;
HELP: latin1
{ $var-description "This is the ISO-8859-1 encoding, also called Latin-1: Western European. It is an 8-bit superset of ASCII which is the default for a mimetype starting with 'text' and provides the characters necessary for most western European languages." }
{ $see-also "encodings-introduction" } ;

View File

@ -0,0 +1,14 @@
USING: arrays io.encodings.latin1 io.encodings.string strings
tools.test ;
{ B{ CHAR: f CHAR: o CHAR: o } } [ "foo" latin1 encode ] unit-test
[ { 256 } >string latin1 encode ] must-fail
{ B{ 255 } } [ { 255 } >string latin1 encode ] unit-test
{ "bar" } [ "bar" latin1 decode ] unit-test
{ { CHAR: b 233 CHAR: r } } [
B{ CHAR: b 233 CHAR: r } latin1 decode >array
] unit-test

View File

@ -0,0 +1,15 @@
USING: io io.encodings io.encodings.iana kernel math ;
IN: io.encodings.latin1
SINGLETON: latin1
M: latin1 encode-char
drop over 256 < [ stream-write1 ] [ encode-error ] if ;
M: latin1 decode-char
drop stream-read1 [
dup 256 < [ drop replacement-char ] unless
] [ f ] if* ;
latin1 "ISO_8859-1:1987" register-encoding