]> gitweb.factorcode.org Git - factor.git/blobdiff - core/io/encodings/encodings.factor
core: Add the shuffler words but without primitives.
[factor.git] / core / io / encodings / encodings.factor
index fc1d24375e15c06c3a40dee4a48353c34dbc4ef0..5fef2f1be637e6c2c1bc219255ec3975bf9890d5 100644 (file)
@@ -44,7 +44,7 @@ CONSTANT: replacement-char 0xfffd
     { string } declare ! aux>> must be f
     [ length ] keep over (byte-array) [
         [
-            [ [ string-nth-fast ] 2keep drop ]
+            [ [ string-nth-fast ] keepd ]
             [ set-nth-unsafe ] bi*
         ] 2curry each-integer
     ] keep ; inline
@@ -53,7 +53,7 @@ CONSTANT: replacement-char 0xfffd
     { byte-array } declare
     [ length ] keep over 0 <string> [
         [
-            [ [ nth-unsafe ] 2keep drop ]
+            [ [ nth-unsafe ] keepd ]
             [
                 pick 127 <=
                 [ set-string-nth-fast ]
@@ -119,17 +119,14 @@ M: decoder stream-read1 ( decoder -- ch )
 : (store-read) ( buf stream encoding n c i -- buf stream encoding n )
     [ rot [ set-nth-unsafe ] keep ] 2curry 3dip ; inline
 
-: (finish-read) ( buf stream encoding n i -- i )
-    2nip 2nip ; inline
-
 : (read-next) ( stream encoding n i -- stream encoding n i c )
     [ 2dup decode-char ] 2dip rot ; inline
 
 : (read-rest) ( buf stream encoding n i -- count )
-    2dup = [ (finish-read) ] [
+    2dup = [ 4nip ] [
         (read-next) [
             swap [ (store-read) ] [ 1 + ] bi (read-rest)
-        ] [ (finish-read) ] if*
+        ] [ 4nip ] if*
     ] if ; inline recursive
 
 M: decoder stream-read-unsafe
@@ -167,11 +164,11 @@ M: decoder stream-read-until
             dup CHAR: \n = [
                 2drop stream-read-until
             ] [
-                [ 2drop ] 2dip
+                2nipd
             ] if
         ] [
             first-unsafe CHAR: \n = [ [ rest ] dip ] when
-            [ 2drop ] 2dip
+            2nipd
         ] if-empty
     ] [
         >decoder< decode-until