io.encodings.chinese and io.encodings.japanese: use [1234]byte-array words instead of B{ } new-sequence and [1234]array >byte-array
parent
f8d80faed3
commit
489019acd0
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2009 Daniel Ehrenberg
|
! Copyright (C) 2009 Daniel Ehrenberg
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: xml xml.data kernel io io.encodings interval-maps splitting fry
|
USING: xml xml.data kernel io io.encodings interval-maps splitting fry
|
||||||
math.parser sequences combinators assocs locals accessors math
|
math.parser sequences combinators assocs locals accessors math arrays
|
||||||
arrays values io.encodings.ascii ascii io.files biassocs math.order
|
byte-arrays values io.encodings.ascii ascii io.files biassocs
|
||||||
combinators.short-circuit io.binary io.encodings.iana ;
|
math.order combinators.short-circuit io.binary io.encodings.iana ;
|
||||||
IN: io.encodings.chinese
|
IN: io.encodings.chinese
|
||||||
|
|
||||||
SINGLETON: gb18030
|
SINGLETON: gb18030
|
||||||
|
@ -65,7 +65,7 @@ TUPLE: range ufirst ulast bfirst blast ;
|
||||||
126 /mod HEX: 81 + swap
|
126 /mod HEX: 81 + swap
|
||||||
10 /mod HEX: 30 + swap
|
10 /mod HEX: 30 + swap
|
||||||
HEX: 81 +
|
HEX: 81 +
|
||||||
B{ } 4sequence dup reverse-here ;
|
4byte-array dup reverse-here ;
|
||||||
|
|
||||||
: >interval-map-by ( start-quot end-quot value-quot seq -- interval-map )
|
: >interval-map-by ( start-quot end-quot value-quot seq -- interval-map )
|
||||||
'[ _ [ @ 2array ] _ tri ] { } map>assoc <interval-map> ; inline
|
'[ _ [ @ 2array ] _ tri ] { } map>assoc <interval-map> ; inline
|
||||||
|
@ -115,13 +115,13 @@ M: gb18030 encode-char ( char stream encoding -- )
|
||||||
|
|
||||||
: four-byte ( stream byte1 byte2 -- char )
|
: four-byte ( stream byte1 byte2 -- char )
|
||||||
rot 2 swap stream-read dup last-bytes?
|
rot 2 swap stream-read dup last-bytes?
|
||||||
[ first2 B{ } 4sequence decode-quad ]
|
[ first2 4byte-array decode-quad ]
|
||||||
[ 3drop replacement-char ] if ;
|
[ 3drop replacement-char ] if ;
|
||||||
|
|
||||||
: two-byte ( stream byte -- char )
|
: two-byte ( stream byte -- char )
|
||||||
over stream-read1 {
|
over stream-read1 {
|
||||||
{ [ dup not ] [ 3drop replacement-char ] }
|
{ [ dup not ] [ 3drop replacement-char ] }
|
||||||
{ [ dup second-byte? ] [ B{ } 2sequence mapping value-at nip ] }
|
{ [ dup second-byte? ] [ 2byte-array mapping value-at nip ] }
|
||||||
{ [ dup quad-2/4? ] [ four-byte ] }
|
{ [ dup quad-2/4? ] [ four-byte ] }
|
||||||
[ 3drop replacement-char ]
|
[ 3drop replacement-char ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
@ -129,7 +129,7 @@ M: gb18030 encode-char ( char stream encoding -- )
|
||||||
M: gb18030 decode-char ( stream encoding -- char )
|
M: gb18030 decode-char ( stream encoding -- char )
|
||||||
drop dup stream-read1 {
|
drop dup stream-read1 {
|
||||||
{ [ dup not ] [ 2drop f ] }
|
{ [ dup not ] [ 2drop f ] }
|
||||||
{ [ dup ascii? ] [ nip 1array B{ } like mapping value-at ] }
|
{ [ dup ascii? ] [ nip 1byte-array mapping value-at ] }
|
||||||
{ [ dup quad-1/3? ] [ two-byte ] }
|
{ [ dup quad-1/3? ] [ two-byte ] }
|
||||||
[ 2drop replacement-char ]
|
[ 2drop replacement-char ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2009 Daniel Ehrenberg
|
! Copyright (C) 2009 Daniel Ehrenberg
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: sequences kernel io io.files combinators.short-circuit
|
USING: sequences kernel io io.files combinators.short-circuit
|
||||||
math.order values assocs io.encodings io.binary fry strings
|
math.order values assocs io.encodings io.binary fry strings math
|
||||||
math io.encodings.ascii arrays accessors splitting math.parser
|
io.encodings.ascii arrays byte-arrays accessors splitting
|
||||||
biassocs io.encodings.iana ;
|
math.parser biassocs io.encodings.iana ;
|
||||||
IN: io.encodings.japanese
|
IN: io.encodings.japanese
|
||||||
|
|
||||||
SINGLETON: shift-jis
|
SINGLETON: shift-jis
|
||||||
|
@ -55,7 +55,7 @@ make-jis to: shift-jis-table
|
||||||
{ [ 0 HEX: 7F between? ] [ HEX: A1 HEX: DF between? ] } 1|| ;
|
{ [ 0 HEX: 7F between? ] [ HEX: A1 HEX: DF between? ] } 1|| ;
|
||||||
|
|
||||||
: write-halfword ( stream halfword -- )
|
: write-halfword ( stream halfword -- )
|
||||||
h>b/b swap B{ } 2sequence swap stream-write ;
|
h>b/b swap 2byte-array swap stream-write ;
|
||||||
|
|
||||||
M: jis encode-char
|
M: jis encode-char
|
||||||
swapd ch>jis
|
swapd ch>jis
|
||||||
|
|
Loading…
Reference in New Issue