]> gitweb.factorcode.org Git - factor.git/blobdiff - core/io/encodings/utf16/utf16.factor
endian: replaces io.binary and io.binary.fast.
[factor.git] / core / io / encodings / utf16 / utf16.factor
index 254f668c903d648360a8d19be9d680d9244c84f0..d8896529094fb686cb6939dd7fabf46e164a55b4 100644 (file)
@@ -1,9 +1,8 @@
 ! 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
@@ -80,12 +79,15 @@ M: utf16le decode-char
     [ 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 ;
@@ -95,7 +97,7 @@ M: utf16be encode-char
         [ 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 ;