io.encodings.utf7: revert last patch, fixed and faster.
parent
3b1464630c
commit
605dad2406
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2013-2014 Björn Lindqvist
|
! Copyright (C) 2013-2014 Björn Lindqvist
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
USING: accessors ascii assocs base64 fry io io.encodings
|
USING: accessors ascii base64 fry io io.encodings
|
||||||
io.encodings.string io.encodings.utf16 kernel math
|
io.encodings.string io.encodings.utf16 kernel make math
|
||||||
math.functions sequences splitting strings ;
|
math.functions sequences splitting strings ;
|
||||||
IN: io.encodings.utf7
|
IN: io.encodings.utf7
|
||||||
|
|
||||||
|
@ -32,10 +32,18 @@ TUPLE: utf7codec dialect buffer ;
|
||||||
[ swap [ first ] [ concat ] bi replace nip ]
|
[ swap [ first ] [ concat ] bi replace nip ]
|
||||||
[ >raw-base64 -rot [ first2 replace ] [ first2 surround ] bi* ] if ;
|
[ >raw-base64 -rot [ first2 replace ] [ first2 surround ] bi* ] if ;
|
||||||
|
|
||||||
|
: split-chunk ( str -- after before printable? )
|
||||||
|
dup first printable? [
|
||||||
|
dupd '[ printable? _ = not ] find drop
|
||||||
|
[ cut-slice ] [ f ] if* swap
|
||||||
|
] keep ;
|
||||||
|
|
||||||
: encode-utf7-string ( str codec -- bytes )
|
: encode-utf7-string ( str codec -- bytes )
|
||||||
[ [ printable? ] collect-by ] dip dialect>> first2
|
dialect>> first2 rot '[
|
||||||
'[ [ _ _ ] 2dip swap encode-chunk ] { } assoc>map
|
[ dup empty? ] [
|
||||||
B{ } concat-as ;
|
split-chunk '[ 2dup _ _ encode-chunk % ] dip
|
||||||
|
] until
|
||||||
|
] B{ } make 3nip ;
|
||||||
|
|
||||||
M: utf7codec encode-string ( str stream codec -- )
|
M: utf7codec encode-string ( str stream codec -- )
|
||||||
swapd encode-utf7-string swap stream-write ;
|
swapd encode-utf7-string swap stream-write ;
|
||||||
|
|
Loading…
Reference in New Issue