io.encodings.blackhole initial

db4
Yun, Jonghyouk 2009-03-01 01:16:13 +09:00
parent a583af44d9
commit 5d70cdfd27
4 changed files with 51 additions and 0 deletions

View File

View File

@ -0,0 +1,22 @@
! Copyright (C) 2009 Yun, Jonghyouk.
! See http://factorcode.org/license.txt for BSD license.
USING: help.syntax help.markup ;
IN: io.encodings.blackhole
ARTICLE: "io.encodings.blackhole" "yet another /dev/null in Factor encodings"
"The " { $vocab-link "io.encodings.blackhole" } " vocab is yet another port of Un*x /dev/null special device file."
{ $subsection blackhole }
{
$see-also
"encodings-introduction"
"encode" "decode"
"file-reader" "file-writer"
"ascii" "binary"
}
;
ABOUT: "io.encodings.blackhole"
HELP: blackhole
{ $class-description "blackhole encoding class specified to input/output encoding, it consume everything and produce nothing." }
;

View File

@ -0,0 +1,7 @@
! Copyright (C) 2009 Yun, Jonghyouk.
! See http://factorcode.org/license.txt for BSD license.
USING: io.encodings.blackhole io.encodings.string kernel tools.test ;
IN: io.encodings.blackhole.tests
[ t ] [ "foobar" blackhole encode B{ } = ] unit-test
[ t ] [ "foobar" blackhole decode f = ] unit-test

View File

@ -0,0 +1,22 @@
! Copyright (C) 2009 Yun, Jonghyouk.
! See http://factorcode.org/license.txt for BSD license.
USING: byte-arrays combinators io io.encodings kernel multiline ;
IN: io.encodings.blackhole
SINGLETON: blackhole
<PRIVATE
M: blackhole encode-char ( char stream encoding -- )
drop swap drop { } >byte-array swap stream-write ;
M: blackhole decode-char ( stream encoding -- char/f )
drop stream-read1
{
{ [ dup not ] [ drop f ] }
[ drop replacement-char ]
} cond ;
PRIVATE>