! Copyright (C) 2006, 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays combinators io io.binary
-io.encodings kernel math math.private namespaces sbufs
-sequences sequences.private splitting strings strings.private
-vectors ;
+USING: accessors byte-arrays combinators io io.encodings kernel
+math math.private namespaces sbufs sequences sequences.private
+splitting strings strings.private vectors ;
IN: io.encodings.utf16
SINGLETON: utf16be
[ B{ } 2sequence ] dip stream-write ; inline
! [ stream-write1 ] curry bi@ ; inline
+: split>b/b ( h -- b1 b2 ) ! duplicate from math.bitwise:h>b/b
+ [ 0xff bitand ] [ -8 shift 0xff bitand ] bi ;
+
: char>utf16be ( char stream -- )
over 0xFFFF > [
[ 0x10000 - ] dip
[ [ encode-first ] dip stream-write2 ]
[ [ encode-second ] dip stream-write2 ] 2bi
- ] [ [ h>b/b swap ] dip stream-write2 ] if ; inline
+ ] [ [ split>b/b swap ] dip stream-write2 ] if ; inline
M: utf16be encode-char
drop char>utf16be ;
[ 0x10000 - ] dip
[ [ encode-first swap ] dip stream-write2 ]
[ [ encode-second swap ] dip stream-write2 ] 2bi
- ] [ [ h>b/b ] dip stream-write2 ] if ; inline
+ ] [ [ split>b/b ] dip stream-write2 ] if ; inline
M: utf16le encode-char
drop char>utf16le ;