]> gitweb.factorcode.org Git - factor.git/commitdiff
base85: fix handling of pad characters.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Apr 2013 18:43:17 +0000 (11:43 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Apr 2013 18:43:17 +0000 (11:43 -0700)
extra/base85/base85-tests.factor
extra/base85/base85.factor

index 57cc34fe86f05ec96914d90dd9cc217c1143e2dd..2b3171fd7b366c60a2dd6f5ec10936761c60ca1b 100644 (file)
@@ -2,3 +2,6 @@ USING: kernel strings tools.test ;
 IN: base85
 
 { t } [ "Hello, world" dup >base85 base85> >string = ] unit-test
+
+{ "NM!&3" } [ "He" >base85 >string ] unit-test
+{ t } [ "He" dup >base85 base85> >string = ] unit-test
index f32248b3538f53433255b29e76379303c35ce85a..51c3a0338d20529a229579de7e4a00a8a846eb40 100644 (file)
@@ -29,15 +29,11 @@ ERROR: malformed-base85 ;
         reverse! nip [ _ write1-lines ] each
     ] change ; inline
 
-: encode-pad ( seq n -- )
-    [ 4 0 pad-tail binary [ encode4 ] with-byte-writer ]
-    [ 1 + ] bi* head-slice 5 CHAR: = pad-tail write-lines ; inline
-
 : (encode-base85) ( stream -- )
     4 over stream-read dup length {
         { 0 [ 2drop ] }
         { 4 [ encode4 (encode-base85) ] }
-        [ encode-pad (encode-base85) ]
+        [ drop 4 0 pad-tail encode4 (encode-base85) ]
     } case ;
 
 PRIVATE>
@@ -51,9 +47,9 @@ PRIVATE>
 <PRIVATE
 
 : decode5 ( seq -- )
-    [ 0 [ [ 85 * ] [ base85>ch ] bi* + ] reduce 4 >be ]
-    [ [ CHAR: = = ] count ] bi head-slice*
-    output-stream get '[ _ stream-write1 ] each ; inline
+    0 [ [ 85 * ] [ base85>ch ] bi* + ] reduce 4 >be
+    [ zero? ] trim-tail-slice output-stream get
+    '[ _ stream-write1 ] each ; inline
 
 : (decode-base85) ( stream -- )
     5 "\n\r" pick read-ignoring dup length {