! 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 alien.accessors byte-arrays io io.binary
+io.encodings kernel math math.private sequences
+sequences.private strings strings.private ;
IN: io.encodings.utf16
SINGLETON: utf16be
drop char>utf16le ;
: ascii-char>utf16-byte-array ( off n byte-array string -- )
- [ over ] dip string-nth-fast -rot
+ overd string-nth-fast -rot
[ 2 fixnum*fast rot fixnum+fast ] dip
set-nth-unsafe ; inline
: ascii-string>utf16-byte-array ( off string -- byte-array )
- [ length >fixnum [ iota ] [ 2 fixnum*fast <byte-array> ] bi ] keep
- [ [ ascii-char>utf16-byte-array ] 2curry with each ] 2keep drop ; inline
+ [ length >fixnum [ <iota> ] [ 2 fixnum*fast <byte-array> ] bi ] keep
+ [ [ ascii-char>utf16-byte-array ] 2curry with each ] keepd ; inline
: ascii-string>utf16le ( string stream -- )
[ 0 swap ascii-string>utf16-byte-array ] dip stream-write ; inline
M: utf16 <encoder> ( stream utf16 -- encoder )
drop bom-le over stream-write utf16le <encoder> ;
+: le? ( -- ? ) B{ 1 0 0 0 } 0 alien-unsigned-4 1 = ; foldable
+
PRIVATE>
+
+: utf16n ( -- value ) le? utf16le utf16be ? ;