2009-02-04 06:13:12 -05:00
|
|
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-27 23:14:26 -04:00
|
|
|
USING: accessors alien.accessors ascii grouping kernel
|
|
|
|
|
kernel.private lexer math math.parser parser sequences
|
|
|
|
|
sequences.private ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: byte-arrays
|
|
|
|
|
|
2009-07-27 23:14:26 -04:00
|
|
|
SYNTAX: HEX{
|
|
|
|
|
"}" parse-tokens "" join
|
|
|
|
|
[ blank? not ] filter
|
|
|
|
|
2 group [ hex> ] B{ } map-as
|
|
|
|
|
parsed ;
|
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
M: byte-array clone (clone) ;
|
2008-07-16 17:48:09 -04:00
|
|
|
M: byte-array length length>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
|
|
|
|
|
M: byte-array set-nth-unsafe swap >fixnum set-alien-unsigned-1 ;
|
|
|
|
|
: >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
|
2008-12-05 08:28:52 -05:00
|
|
|
M: byte-array new-sequence drop (byte-array) ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
|
M: byte-array equal?
|
|
|
|
|
over byte-array? [ sequence= ] [ 2drop f ] if ;
|
|
|
|
|
|
2008-01-28 19:15:21 -05:00
|
|
|
M: byte-array resize
|
|
|
|
|
resize-byte-array ;
|
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
INSTANCE: byte-array sequence
|
2008-09-01 19:26:10 -04:00
|
|
|
|
2009-02-04 06:13:12 -05:00
|
|
|
: 1byte-array ( x -- byte-array ) B{ } 1sequence ; inline
|
2008-09-01 19:26:10 -04:00
|
|
|
|
2008-09-05 17:04:23 -04:00
|
|
|
: 2byte-array ( x y -- byte-array ) B{ } 2sequence ; inline
|
2008-09-01 19:26:10 -04:00
|
|
|
|
2008-09-05 17:04:23 -04:00
|
|
|
: 3byte-array ( x y z -- byte-array ) B{ } 3sequence ; inline
|
2008-09-01 19:26:10 -04:00
|
|
|
|
2008-09-05 17:04:23 -04:00
|
|
|
: 4byte-array ( w x y z -- byte-array ) B{ } 4sequence ; inline
|