File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -208,7 +208,7 @@ static REBCNT EncodedU32_Size(u32 value) {
208
208
// /write "Write data into output buffer"
209
209
// data [binary! block!] "Data dialect"
210
210
// /read "Read data from the input buffer"
211
- // code [word! block! integer!] "Input encoding"
211
+ // code [word! block! integer! binary! ] "Input encoding"
212
212
// /into "Put READ results in out block, instead of creating a new block"
213
213
// out [block!] "Target block for results, when /into is used"
214
214
// /with "Additional input argument"
@@ -1589,6 +1589,19 @@ static REBCNT EncodedU32_Size(u32 value) {
1589
1589
//puts("-- found set-word?");
1590
1590
DS_PUSH (value );
1591
1591
continue ;
1592
+ case REB_BINARY :
1593
+ // do binary comparison, return TRUE and skip if data matches
1594
+ // or return FALSE and keep position where it is
1595
+ VAL_SET (temp , REB_LOGIC );
1596
+ n = Val_Series_Len (value );
1597
+ if ((cp + n ) > ep || NZ (memcmp (cp , VAL_BIN_DATA (value ), n ))) {
1598
+ VAL_LOGIC (temp ) = FALSE;
1599
+ n = 0 ; // no advance
1600
+ }
1601
+ else {
1602
+ VAL_LOGIC (temp ) = TRUE;
1603
+ }
1604
+ break ;
1592
1605
}
1593
1606
// Set prior set-words:
1594
1607
while (DSP > ssp ) {
Original file line number Diff line number Diff line change @@ -440,6 +440,18 @@ is-protected-error?: func[code][
440
440
;- used for fixed size octal numbers (used for example in TAR files)
441
441
--assert 8 = binary/read/with #{ 3130 } 'OCTAL-BYTES 2
442
442
443
+ --test-- "BinCode - match binary!"
444
+ b: binary #{ 0badCafe }
445
+ --assert binary/read b #{ 0bad }
446
+ --assert binary/read b #{ Cafe }
447
+ --assert tail? b/buffer
448
+ --assert [#[true] #[false] #[true]] = binary/read b [
449
+ ATz 0 ; reset position to head
450
+ #{ 0bad } ; true and advance
451
+ #{ F00D } ; false, no advance
452
+ #{ Cafe } ; true and advance
453
+ ]
454
+ --assert [#[true] #{ CAFE } ] = binary/read b [ATz 0 #{ 0bad } bytes 2 ]
443
455
444
456
===end-group===
445
457
You can’t perform that action at this time.
0 commit comments