File tree 3 files changed +48
-5
lines changed
3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -1023,6 +1023,36 @@ static int Do_Ordinal(REBVAL *ds, REBINT n)
1023
1023
}
1024
1024
1025
1025
1026
+ /***********************************************************************
1027
+ **
1028
+ */ REBNATIVE (truncate )
1029
+ /*
1030
+ // truncate: native [
1031
+ // "Removes all bytes/values from series' head to its current index position"
1032
+ // series [series!] "Series to be truncated"
1033
+ // /part "Also shorten resulted series to a length or end position"
1034
+ // range [number! series!]
1035
+ // ]
1036
+ ***********************************************************************/
1037
+ {
1038
+ REBVAL * arg = D_ARG (1 );
1039
+ REBINT index = VAL_INDEX (arg );
1040
+ REBINT len = -1 ;
1041
+
1042
+ if (D_REF (2 )) {
1043
+ len = Partial (arg , 0 , D_ARG (3 ), 0 );
1044
+ }
1045
+ if (index > 0 ) {
1046
+ Remove_Series (VAL_SERIES (arg ), 0 , index );
1047
+ VAL_INDEX (arg ) = 0 ;
1048
+ }
1049
+ if (len >= 0 ) {
1050
+ VAL_TAIL (arg ) = len ;
1051
+ }
1052
+ return R_ARG1 ;
1053
+ }
1054
+
1055
+
1026
1056
#ifdef not_fast_enough
1027
1057
/***********************************************************************
1028
1058
**
Original file line number Diff line number Diff line change @@ -736,6 +736,8 @@ sys/make-scheme [
736
736
len: data/2 & 127
737
737
data: skip data 2
738
738
;? final? ? opcode ? len
739
+
740
+ ;@@ Not removing bytes until we make sure, that there is enough data!
739
741
case [
740
742
len = 126 [
741
743
if 2 >= length? data [break]
@@ -749,8 +751,7 @@ sys/make-scheme [
749
751
]
750
752
]
751
753
if (4 + length? data) < len [break]
752
- remove/part head data data
753
- data: head data
754
+ data: truncate data ;; removes already processed bytes from the head
754
755
either mask? [
755
756
request-data: make binary! len
756
757
masks: take/part data 4
@@ -761,9 +762,8 @@ sys/make-scheme [
761
762
][
762
763
request-data: take/part data len
763
764
]
764
- ready?: true
765
- clear skip request-data len
766
- ctx/inp/content: request-data
765
+ ready?: true
766
+ ctx/inp/content: truncate/part request-data len
767
767
if opcode = 8 [
768
768
sys/log/more 'HTTPD "WS Connection Close Frame!"
769
769
code: 0
Original file line number Diff line number Diff line change @@ -392,6 +392,19 @@ Rebol [
392
392
===end-group===
393
393
394
394
395
+ ===start-group=== "TRUNCATE"
396
+ --test-- "TRUNCATE"
397
+ --assert "23" = truncate next "123"
398
+ --assert [2 3 ] = truncate next [1 2 3 ]
399
+ --assert "2" = truncate/part next "123" 1
400
+ --assert [2 ] = truncate/part next [1 2 3 ] 1
401
+ --assert "23" = head truncate next "123"
402
+ --assert [2 3 ] = head truncate next [1 2 3 ]
403
+ --assert "2" = head truncate/part next "123" 1
404
+ --assert [2 ] = head truncate/part next [1 2 3 ] 1
405
+ ===end-group===
406
+
407
+
395
408
396
409
===start-group=== "REPLACE string!"
397
410
;@@ https://github.com/Oldes/Rebol-issues/issues/54
You can’t perform that action at this time.
0 commit comments