DELINE/ENLINE (community effort) Part 3

The testing goes on. Focussing on /with and in particular the char case now.

So now we have this code

	deline*: func [
		check?   [logic!]
		_with [integer!]									;-- with is reserved 
		lines [integer!]
			data 	[red-string!]
			buffer	[red-string!]
			val  	[red-value!]
			with-arg [red-value!]							;-- with char! or string! value
			char 	[red-char!]
			s	 	[series!]
			p		[byte-ptr!]
			len  	[integer!]
			unit 	[integer!]
			cp   	[integer!]
			cr   	[integer!]
			lf   	[integer!]
			p4        [int-ptr!]
			blk		[red-block!]
			tail      [byte-ptr!]

		#typecheck [deline _with lines]
		data: as red-string! stack/arguments
		print lines print _with
		lf: 10
		cr: 13
		either positive? lines [
			print "lines refinement found"
			val/header: TYPE_BLOCK

			; To do: return a block of lines using some split functionality
			either positive? _with [
				print "with refinement found"
				val: as red-value! data + 1
				either TYPE_OF(val) = TYPE_CHAR [
					print "char type"
					;print val
					;val/header: TYPE_CHAR
					lf: val/data2
					print lf
				][  print "string type"
					;print val
					val/header: TYPE_STRING
			][print "No refinement used" ]

		s:  GET_BUFFER(data)
		unit: GET_UNIT(s)
		p:	  string/rs-head data
		len:  string/rs-length? data
		tail: as byte-ptr! s/tail
		print val/header print "-" print val/data1 print "-" print val/data2 print "-" print val/data3
		buffer: string/rs-make-at stack/push* ( len ) * unit

		while [p < tail][
			cp: switch unit [
				Latin1 [as-integer p/value]
				UCS-2  [(as-integer p/2) << 8 + p/1]
				UCS-4  [p4: as int-ptr! p p4/value]

			p: p + unit
			either 13 = cp [ ; CR
				string/append-char GET_BUFFER(buffer) lf unit
				p: p + unit
				cp: switch unit [
					Latin1 [as-integer p/value]
					UCS-2  [(as-integer p/2) << 8 + p/1]
					UCS-4  [p4: as int-ptr! p p4/value]
				if 10 = cp [
					p: p + unit            				;-- Next!
				either 10 = cp [
					string/append-char GET_BUFFER(buffer) lf unit
					string/append-char GET_BUFFER(buffer) cp unit
					;string/append-char GET_BUFFER(buffer) 97 unit ;-- "a" for testing 
		stack/set-last as red-value! buffer

Still using a lot of debugging prints and plenty odd variables. But still compiling and also now returning some results.

red>> deline/with {hello
{    all} "b"
-11with refinement foundstring type7-0-3473324-0== "hello^/all"
red>> deline/with {hello
{    all} #"b"
-11with refinement foundchar type9810-15-98-0== "helloball"

Feeling more and more confident, in the next blog some prints can be removed, and experiment with returning a block is still on the list.

To be continued...

This entry was posted in Geen categorie. Bookmark the permalink.

Geef een reactie

Your email address will not be published. Required fields are marked *

Vul dit nog even in: * Time limit is exhausted. Please reload CAPTCHA.