changestr(needle, haystack, newneedle [,start [,length]]
and
countstr(needle, haystack [,start [,length]]
adding the optional parms of [,start [,length]] will allow backward compatability with existing code.
using these parameters will focus the BIF onto a subset of the 'haystack' and thereby achieve some performance gain; especially with large haystacks; while the haystack maintains its integrity.
'start' has a default integer value of 1 and can overide this so the search for needle will start further into the haystack.
'length' has a default integer value of length(haystack) - start + 1 and can overide this so the search for needle is limited before the end of the haystack.
This has been posted on Regina Feature request on the advice of Mark Hessling to keep ooRexx code compatible with Regina Rexx
test suites follow ....
/ ===================== CHANGESTR ============================= /
call notify 'changestr'
if ver > 4 Then
do
Call ch changestr('a','fred','c') , 'fred'
Call ch changestr('','','x') , ''
Call ch changestr('a','abcdef','x') , 'xbcdef'
Call ch changestr('0','0','1') , '1'
Call ch changestr('a','def','xyz') , 'def'
Call ch changestr('a','','x') , ''
Call ch changestr('','def','xyz') , 'def'
Call ch changestr('abc','abcdef','xyz') , 'xyzdef'
Call ch changestr('abcdefg','abcdef','xyz') , 'abcdef'
Call ch changestr('abc','abcdefabccdabcd','z') , 'zdefzcdzd'
/* for enhanced changestr(needle, haystack, newneedle [,start [,length]] */ Call ch changestr('AB','ABCABCABC','xx', 4) , 'ABCxxCxxC' Call ch changestr('AB','ABCABCABC','xx',, 3) , 'xxCABCABC' Call ch changestr('AB','ABCABCABC','xx', 4, 3) , 'ABCxxCABC' Call ch changestr('AB','ABCABCABC','xx', 2, 1) , 'ABCABCABC' Call ch changestr('AB','ABCABCABC','xx', 8, 3) , 'ABCABCABC'
end
/ ===================== COUNTSTR ============================== /
call notify 'countstr'
if ver > 4 Then
do
Call ch countstr('','') , 0
Call ch countstr('a','abcdef') , 1
Call ch countstr(0,0) , 1
Call ch countstr('a','def') , 0
Call ch countstr('a','') , 0
Call ch countstr('','def') , 0
Call ch countstr('abc','abcdef') , 1
Call ch countstr('abcdefg','abcdef') , 0
Call ch countstr('abc','abcdefabccdabcd') , 3
/* for enhanced countstr(needle, haystack [,start [,length]] */ Call ch countstr('AB','ABCABCABC', 4) , 2 Call ch countstr('AB','ABCABCABC',, 3) , 1 Call ch countstr('AB','ABCABCABC', 4, 3) , 1 Call ch countstr('AB','ABCABCABC', 2, 1) , 0 Call ch countstr('AB','ABCABCABC', 8, 3) , 0
end
Anonymous
Felix,
ooRexx's changeStr() already has a fourth arg 'count'
Thanks for the feedback. I'll pass it on to Mark.
Cheers - Felix
On 10/08/2017 4:13 am, "Erich" erich_st@users.sf.net wrote: