]> gitweb.factorcode.org Git - factor.git/blob - core/io/encodings/ascii/ascii.factor
change ERROR: words from throw-foo back to foo.
[factor.git] / core / io / encodings / ascii / ascii.factor
1 ! Copyright (C) 2008 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors byte-arrays io io.encodings
4 io.encodings.private kernel math sequences strings ;
5 IN: io.encodings.ascii
6
7 SINGLETON: ascii
8
9 M: ascii encode-char
10     drop
11     over 127 <= [ stream-write1 ] [ encode-error ] if ; inline
12
13 <PRIVATE
14
15 GENERIC: ascii> ( string -- byte-array )
16
17 M: string ascii>
18     dup aux>>
19     [ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
20     [ string>byte-array-fast ] if ; inline
21
22 PRIVATE>
23
24 M: ascii encode-string
25     drop
26     [ ascii> ] dip stream-write ;
27
28 M: ascii decode-char
29     drop
30     stream-read1 dup [
31         dup 127 <= [ >fixnum ] [ drop replacement-char ] if
32     ] when ; inline
33
34 M: ascii decode-until (decode-until) ;