io.encodings: a bit faster and make ascii support slices.
parent
0988df1e5a
commit
6d417f4f71
|
@ -14,9 +14,12 @@ M: ascii encode-char
|
|||
|
||||
GENERIC: ascii> ( string -- byte-array )
|
||||
|
||||
M: object ascii>
|
||||
[ dup 127 <= [ encode-error ] unless ] B{ } map-as ; inline
|
||||
|
||||
M: string ascii>
|
||||
dup aux>>
|
||||
[ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
|
||||
[ call-next-method ]
|
||||
[ string>byte-array-fast ] if ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
|
|
@ -114,17 +114,29 @@ M: utf16le encode-char ( char stream encoding -- )
|
|||
: ascii-string>utf16be ( string stream -- )
|
||||
[ 1 swap ascii-string>utf16-byte-array ] dip stream-write ; inline
|
||||
|
||||
M: utf16le encode-string
|
||||
drop
|
||||
over dup string? [ aux>> ] [ drop t ] if
|
||||
[ [ char>utf16le ] curry each ]
|
||||
[ ascii-string>utf16le ] if ;
|
||||
GENERIC# encode-string-utf16le 1 ( string stream -- )
|
||||
|
||||
M: utf16be encode-string
|
||||
drop
|
||||
over dup string? [ aux>> ] [ drop t ] if
|
||||
[ [ char>utf16be ] curry each ]
|
||||
[ ascii-string>utf16be ] if ;
|
||||
M: object encode-string-utf16le
|
||||
[ char>utf16le ] curry each ; inline
|
||||
|
||||
M: string encode-string-utf16le
|
||||
over aux>>
|
||||
[ call-next-method ]
|
||||
[ ascii-string>utf16le ] if ; inline
|
||||
|
||||
M: utf16le encode-string drop encode-string-utf16le ;
|
||||
|
||||
GENERIC# encode-string-utf16be 1 ( string stream -- )
|
||||
|
||||
M: object encode-string-utf16be
|
||||
[ char>utf16be ] curry each ; inline
|
||||
|
||||
M: string encode-string-utf16be
|
||||
over aux>>
|
||||
[ call-next-method ]
|
||||
[ ascii-string>utf16be ] if ; inline
|
||||
|
||||
M: utf16be encode-string drop encode-string-utf16be ;
|
||||
|
||||
M: utf16le guess-encoded-length drop 2 * ; inline
|
||||
M: utf16le guess-decoded-length drop 2 /i ; inline
|
||||
|
|
|
@ -84,11 +84,17 @@ M: utf8 decode-until (decode-until) ;
|
|||
M: utf8 encode-char
|
||||
drop char>utf8 ;
|
||||
|
||||
M: utf8 encode-string
|
||||
drop
|
||||
over dup string? [ aux>> ] [ drop t ] if
|
||||
[ [ char>utf8 ] curry each ]
|
||||
[ [ string>byte-array-fast ] dip stream-write ] if ;
|
||||
GENERIC# encode-string-utf8 1 ( string stream -- )
|
||||
|
||||
M: object encode-string-utf8
|
||||
[ char>utf8 ] curry each ; inline
|
||||
|
||||
M: string encode-string-utf8
|
||||
over aux>>
|
||||
[ call-next-method ]
|
||||
[ [ string>byte-array-fast ] dip stream-write ] if ; inline
|
||||
|
||||
M: utf8 encode-string drop encode-string-utf8 ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
|
|
Loading…
Reference in New Issue