+++ /dev/null
-Maxim Savchenko
-Slava Pestov
+++ /dev/null
-! Copyright (C) 2009 Maxim Savchenko, Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-IN: byte-arrays.hex
-USING: byte-arrays help.markup help.syntax ;
-
-HELP: HEX{
-{ $syntax "HEX{ 0123 45 67 89abcdef }" }
-{ $description "Constructs a " { $link byte-array } " from data specified in hexadecimal format. Whitespace between the curly braces is ignored. There must be an even number of hex digits or an error is thrown." } ;
+++ /dev/null
-! Copyright (C) 2011 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: byte-arrays.hex eval tools.test ;
-
-{ B{ 16 0 8 0 } } [ HEX{ 10 00 08 00 } ] unit-test
-{ B{ 255 255 15 255 255 255 } } [ HEX{ ffff 0fff ffff } ] unit-test
-
-[ "HEX{ ffff fff ffff }" parse-string ] must-fail
-[ "HEX{ 10 00 08 0 }" parse-string ] must-fail
-[ "HEX{ 1 00 00 80 }" parse-string ] must-fail
+++ /dev/null
-! Copyright (C) 2009,2011 Maxim Savchenko, Slava Pestov, Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: ascii grouping kernel math.parser sequences
-strings.parser lexer math ;
-IN: byte-arrays.hex
-
-ERROR: odd-length-hex-string string ;
-
-SYNTAX: HEX{
- "}" parse-tokens concat
- [ blank? ] reject
- dup length even? [ odd-length-hex-string ] unless
- 2 <groups> [ hex> ] B{ } map-as
- suffix! ;
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays.hex crypto.aes crypto.aes.private
-crypto.aes.utils grouping kernel sequences tools.test ;
+USING: accessors crypto.aes crypto.aes.private crypto.aes.utils
+grouping kernel sequences tools.test ;
IN: crypto.aes.tests
! fips-197 test vectors
-CONSTANT: plaintext HEX{ 32 43 f6 a8 88 5a 30 8d 31 31 98 a2 e0 37 07 34 }
-CONSTANT: key HEX{ 2b 7e 15 16 28 ae d2 a6 ab f7 15 88 09 cf 4f 3c }
+CONSTANT: plaintext B{ 0x32 0x43 0xf6 0xa8 0x88 0x5a 0x30 0x8d 0x31 0x31 0x98 0xa2 0xe0 0x37 0x07 0x34 }
+CONSTANT: key B{ 0x2b 0x7e 0x15 0x16 0x28 0xae 0xd2 0xa6 0xab 0xf7 0x15 0x88 0x09 0xcf 0x4f 0x3c }
{ {
0x00 0x01 0x02 0x04 0x08 0x10
2893506291 435870753 684796225 1465647214 3491035560 3387827593
3779005640 3059944614 }
} [
- HEX{ 2b 7e 15 16 28 ae d2 a6 ab f7 15 88 09 cf 4f 3c } ! AES-128 key expansion test vector from FIPS-197 (appendix)
+ B{ 0x2b 0x7e 0x15 0x16 0x28 0xae 0xd2 0xa6 0xab 0xf7 0x15 0x88 0x09 0xcf 0x4f 0x3c } ! AES-128 key expansion test vector from FIPS-197 (appendix)
10 (expand-enc-key)
] unit-test
! (c)2010 Joe Groff bsd license
-USING: byte-arrays byte-arrays.hex io.encodings.8-bit.koi8-r
+USING: byte-arrays io.encodings.8-bit.koi8-r
io.encodings.8-bit.latin1 io.encodings.binary
io.encodings.detect io.encodings.utf16 io.encodings.utf32
io.encodings.utf8 namespaces tools.test ;
IN: io.encodings.detect.tests
! UTF encodings with BOMs
-{ utf16be } [ HEX{ FEFF 0031 0032 0033 } detect-byte-array ] unit-test
-{ utf16le } [ HEX{ FFFE 3100 3200 3300 } detect-byte-array ] unit-test
-{ utf32be } [ HEX{ 0000FEFF 00000031 00000032 00000033 } detect-byte-array ] unit-test
-{ utf32le } [ HEX{ FFFE0000 31000000 32000000 33000000 } detect-byte-array ] unit-test
-{ utf8 } [ HEX{ EF BB BF 31 32 33 } detect-byte-array ] unit-test
+{ utf16be } [ B{ 0xFE 0xFF 0x00 0x31 0x00 0x32 0x00 0x33 } detect-byte-array ] unit-test
+{ utf16le } [ B{ 0xFF 0xFE 0x31 0x00 0x32 0x00 0x33 0x00 } detect-byte-array ] unit-test
+{ utf32be } [ B{ 0x00 0x00 0xFE 0xFF 0x00 0x00 0x00 0x31 0x00 0x00 0x00 0x32 0x00 0x00 0x00 0x33 } detect-byte-array ] unit-test
+{ utf32le } [ B{ 0xFF 0xFE 0x00 0x00 0x31 0x00 0x00 0x00 0x32 0x00 0x00 0x00 0x33 0x00 0x00 0x00 } detect-byte-array ] unit-test
+{ utf8 } [ B{ 0xEF 0xBB 0xBF 0x31 0x32 0x33 } detect-byte-array ] unit-test
! XML prolog
{ utf8 }
unit-test
! Default to utf8 if decoding succeeds and there are no nulls
-{ utf8 } [ HEX{ } detect-byte-array ] unit-test
-{ utf8 } [ HEX{ 31 32 33 } detect-byte-array ] unit-test
-{ utf8 } [ HEX{ 31 32 C2 A0 33 } detect-byte-array ] unit-test
-{ latin1 } [ HEX{ 31 32 A0 33 } detect-byte-array ] unit-test
+{ utf8 } [ B{ } detect-byte-array ] unit-test
+{ utf8 } [ B{ 0x31 0x32 0x33 } detect-byte-array ] unit-test
+{ utf8 } [ B{ 0x31 0x32 0xC2 0xA0 0x33 } detect-byte-array ] unit-test
+{ latin1 } [ B{ 0x31 0x32 0xA0 0x33 } detect-byte-array ] unit-test
{ koi8-r } [
koi8-r default-8bit-encoding [
- HEX{ 31 32 A0 33 } detect-byte-array
+ B{ 0x31 0x32 0xA0 0x33 } detect-byte-array
] with-variable
] unit-test
-{ binary } [ HEX{ 31 32 33 C2 A0 00 } detect-byte-array ] unit-test
-{ binary } [ HEX{ 31 32 33 C2 A0 00 30 } detect-byte-array ] unit-test
+{ binary } [ B{ 0x31 0x32 0x33 0xC2 0xA0 0x00 } detect-byte-array ] unit-test
+{ binary } [ B{ 0x31 0x32 0x33 0xC2 0xA0 0x00 0x30 } detect-byte-array ] unit-test
! (c)2010 Joe Groff bsd license
-USING: accessors byte-arrays byte-arrays.hex combinators
-continuations fry io io.encodings io.encodings.8-bit.latin1
-io.encodings.ascii io.encodings.binary io.encodings.iana
-io.encodings.string io.encodings.utf16 io.encodings.utf32
-io.encodings.utf8 io.files io.streams.string kernel literals
-math namespaces sequences strings ;
+USING: accessors byte-arrays combinators continuations fry io
+io.encodings io.encodings.8-bit.latin1 io.encodings.ascii
+io.encodings.binary io.encodings.iana io.encodings.string
+io.encodings.utf16 io.encodings.utf32 io.encodings.utf8
+io.files io.streams.string kernel literals math namespaces
+sequences strings ;
IN: io.encodings.detect
SYMBOL: default-8bit-encoding
: detect-byte-array ( bytes -- encoding )
{
- { [ dup HEX{ 0000FEFF } head? ] [ drop utf32be ] }
- { [ dup HEX{ FFFE0000 } head? ] [ drop utf32le ] }
- { [ dup HEX{ FEFF } head? ] [ drop utf16be ] }
- { [ dup HEX{ FFFE } head? ] [ drop utf16le ] }
- { [ dup HEX{ EF BB BF } head? ] [ drop utf8 ] }
+ { [ dup B{ 0x00 0x00 0xFE 0xFF } head? ] [ drop utf32be ] }
+ { [ dup B{ 0xFF 0xFE 0x00 0x00 } head? ] [ drop utf32le ] }
+ { [ dup B{ 0xFE 0xFF } head? ] [ drop utf16be ] }
+ { [ dup B{ 0xFF 0xFE } head? ] [ drop utf16le ] }
+ { [ dup B{ 0xEF 0xBB 0xBF } head? ] [ drop utf8 ] }
{ [ dup $[ "<?xml" >byte-array ] head? ] [ detect-xml-prolog ] }
{ [ 0 over member? ] [ drop binary ] }
{ [ dup empty? ] [ drop utf8 ] }
-USING: byte-arrays.hex io.encodings.binary io.streams.byte-array midi
+USING: io.encodings.binary io.streams.byte-array midi
midi.private sequences tools.test ;
IN: midi.tests
}
} [
{
- HEX{ 00 }
- HEX{ 40 }
- HEX{ 7f }
- HEX{ 81 00 }
- HEX{ C0 00 }
- HEX{ ff 7f }
- HEX{ 81 80 00 }
- HEX{ C0 80 00 }
- HEX{ ff ff 7f }
- HEX{ 81 80 80 00 }
- HEX{ C0 80 80 00 }
- HEX{ ff ff ff 7f }
+ B{ 0x00 }
+ B{ 0x40 }
+ B{ 0x7f }
+ B{ 0x81 0x00 }
+ B{ 0xC0 0x00 }
+ B{ 0xff 0x7f }
+ B{ 0x81 0x80 0x00 }
+ B{ 0xC0 0x80 0x00 }
+ B{ 0xff 0xff 0x7f }
+ B{ 0x81 0x80 0x80 0x00 }
+ B{ 0xC0 0x80 0x80 0x00 }
+ B{ 0xff 0xff 0xff 0x7f }
} [ binary [ read-number ] with-byte-reader ] map
] unit-test
{
{
- HEX{ 00 }
- HEX{ 40 }
- HEX{ 7f }
- HEX{ 81 00 }
- HEX{ C0 00 }
- HEX{ ff 7f }
- HEX{ 81 80 00 }
- HEX{ C0 80 00 }
- HEX{ ff ff 7f }
- HEX{ 81 80 80 00 }
- HEX{ C0 80 80 00 }
- HEX{ ff ff ff 7f }
+ B{ 0x00 }
+ B{ 0x40 }
+ B{ 0x7f }
+ B{ 0x81 0x00 }
+ B{ 0xC0 0x00 }
+ B{ 0xff 0x7f }
+ B{ 0x81 0x80 0x00 }
+ B{ 0xC0 0x80 0x00 }
+ B{ 0xff 0xff 0x7f }
+ B{ 0x81 0x80 0x80 0x00 }
+ B{ 0xC0 0x80 0x80 0x00 }
+ B{ 0xff 0xff 0xff 0x7f }
}
} [
{
}
}
} [
- HEX{
- 4D 54 68 64
- 00 00 00 06
- 00 00
- 00 01
- 00 60
+ B{
+ 0x4D 0x54 0x68 0x64
+ 0x00 0x00 0x00 0x06
+ 0x00 0x00
+ 0x00 0x01
+ 0x00 0x60
- 4D 54 72 6B
- 00 00 00 3B
- 00 FF 58 04 04 02 18 08
- 00 FF 51 03 07 A1 20
- 00 C0 05
- 00 C1 2E
- 00 C2 46
- 00 92 30 60
- 00 3C 60
- 60 91 43 40
- 60 90 4C 20
- 81 40 82 30 40
- 00 3C 40
- 00 81 43 40
- 00 80 4C 40
- 00 FF 2F 00
+ 0x4D 0x54 0x72 0x6B
+ 0x00 0x00 0x00 0x3B
+ 0x00 0xFF 0x58 0x04 0x04 0x02 0x18 0x08
+ 0x00 0xFF 0x51 0x03 0x07 0xA1 0x20
+ 0x00 0xC0 0x05
+ 0x00 0xC1 0x2E
+ 0x00 0xC2 0x46
+ 0x00 0x92 0x30 0x60
+ 0x00 0x3C 0x60
+ 0x60 0x91 0x43 0x40
+ 0x60 0x90 0x4C 0x20
+ 0x81 0x40 0x82 0x30 0x40
+ 0x00 0x3C 0x40
+ 0x00 0x81 0x43 0x40
+ 0x00 0x80 0x4C 0x40
+ 0x00 0xFF 0x2F 0x00
} >midi
] unit-test
}
}
} [
- HEX{
- 4D 54 68 64
- 00 00 00 06
- 00 01
- 00 04
- 00 60
+ B{
+ 0x4D 0x54 0x68 0x64
+ 0x00 0x00 0x00 0x06
+ 0x00 0x01
+ 0x00 0x04
+ 0x00 0x60
- 4D 54 72 6B
- 00 00 00 14
- 00 FF 58 04 04 02 18 08
- 00 FF 51 03 07 A1 20
- 83 00 FF 2F 00
+ 0x4D 0x54 0x72 0x6B
+ 0x00 0x00 0x00 0x14
+ 0x00 0xFF 0x58 0x04 0x04 0x02 0x18 0x08
+ 0x00 0xFF 0x51 0x03 0x07 0xA1 0x20
+ 0x83 0x00 0xFF 0x2F 0x00
- 4D 54 72 6B
- 00 00 00 10
- 00 C0 05
- 81 40 90 4C 20
- 81 40 4C 00
- 00 FF 2F 00
+ 0x4D 0x54 0x72 0x6B
+ 0x00 0x00 0x00 0x10
+ 0x00 0xC0 0x05
+ 0x81 0x40 0x90 0x4C 0x20
+ 0x81 0x40 0x4C 0x00
+ 0x00 0xFF 0x2F 0x00
- 4D 54 72 6B
- 00 00 00 0F
- 00 C1 2E
- 60 91 43 40
- 82 20 43 00
- 00 FF 2F 00
+ 0x4D 0x54 0x72 0x6B
+ 0x00 0x00 0x00 0x0F
+ 0x00 0xC1 0x2E
+ 0x60 0x91 0x43 0x40
+ 0x82 0x20 0x43 0x00
+ 0x00 0xFF 0x2F 0x00
- 4D 54 72 6B
- 00 00 00 15
- 00 C2 46
- 00 92 30 60
- 00 3C 60
- 83 00 30 00
- 00 3C 00
- 00 FF 2F 00
+ 0x4D 0x54 0x72 0x6B
+ 0x00 0x00 0x00 0x15
+ 0x00 0xC2 0x46
+ 0x00 0x92 0x30 0x60
+ 0x00 0x3C 0x60
+ 0x83 0x00 0x30 0x00
+ 0x00 0x3C 0x00
+ 0x00 0xFF 0x2F 0x00
} >midi
] unit-test
-USING: accessors alien.c-types alien.syntax byte-arrays.hex
+USING: accessors alien.c-types alien.syntax
classes.struct colors.constants colors.hex kernel literals logging
math ;
IN: strange
flags{ 10 20 } drop
-! TODO: Highlight contents too.
-HEX{ ab cd ef } drop
-
! ! Alien functions
STRUCT: timeval
{ sec long }