'testing with QB64 X 64 version 1.2 20180228/86 from git b301f92
'Overload test eval.bas B+ 2018-08-25 started
' modify Split for special case of spaces to be used as delimiter for overloaded p$ = parameter string
' note: for ease of coding ~ is used for subtraction sign and normal - is reserved to indicate a negative number.
test$(1) = "seven=7 eval>seven*10~7" ' < this is 7*10-7
test$(2) = "A=2 b=3 C=5 x=10 eval>a*X^2+B*x+c"
test$(3) = "eval>able*x^2+baker*x+charlie able=2 baker=2.99 charlie=5 x=10 eval>able*x^2+baker*x+charlie"
evalOverload test$(i)
PRINT ", evalOverload returned: "; test$
(i
)
' p$ comes in as parameters list, goes out as like a function's return value (but in string form of course).
' so save p$ before calling and using here if need it again!
Split p, " ", pList$()
this$
= rightOf$
(pList$
(i
), "EVAL>"): found
= 1:
EXIT FOR b$ = ""
FOR i
= 1 TO LEN(this$
) 'do substitutions wd$ = ""
hit = 0
hit = 1
wd$
= wd$
+ MID$(this$
, i
, 1) i = i + 1
found2 = 0
IF leftOf$
(pList$
(j
), "=") = wd$
THEN b$
= b$
+ rightOf$
(pList$
(j
), "="): found2
= 1:
EXIT FOR PRINT "Did not find word, "; wd$;
", in paramters list.": p
= "":
EXIT SUB b$
= b$
+ MID$(this$
, i
, 1)
op$
= MID$("%^/*~+", j
, 1) 'notice the starnge sign for minus, to distinguish a neg number from subtraction op L = place - 1: R = place + 1: lb$ = "": rb$ = ""
lb$
= MID$(b$
, L
, 1) + lb$
L = L - 1
R = place + 1
rb$
= rb$
+ MID$(b$
, R
, 1) R = R + 1
head$
= MID$(b$
, 1, L
): tail$
= MID$(b$
, R
) b$ = head$ + M$ + tail$
'return p string as result
p = b$
posOf
= INSTR(source$
, of$
) IF posOf
> 0 THEN leftOf$
= MID$(source$
, 1, posOf
- 1)
posOf
= INSTR(source$
, of$
)
'notes: REDIM the array(0) to be loaded before calling Split '<<<<<<<<<<<<<<<<<<<<<<< IMPORTANT!!!!
' bplus modifications of Galleon fix of Bulrush Split reply #13
' http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=1612.0
' this sub further developed and tested here: \test\Strings\Split test.bas
copy = mystr 'make copy since we are messing with mystr
'special case if delim is space, probably want to remove all excess space
copy
= MID$(copy
, 1, p
- 1) + MID$(copy
, p
+ 1) curpos = 1
arrpos = 0
dpos
= INSTR(curpos
, copy
, delim
) arr
(arrpos
) = MID$(copy
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos
= dpos
+ LEN(delim
) dpos
= INSTR(curpos
, copy
, delim
) arr
(arrpos
) = MID$(copy
, curpos
)