### Author Topic: instrany instrevany  (Read 341 times)

0 Members and 1 Guest are viewing this topic.

#### jcfuller

• Full Member
• Posts: 143
##### instrany instrevany
« on: March 29, 2018, 04:00:10 AM »
Charles,
Two items I miss from the ParseUtil.inc functions are:
instrAny and instrevAny
Extending existing ones is not necessary. I  would be happy with new functions.
Thank You and keep up the good work.

James

#### Charles Pegge

• Posts: 3721
##### Re: instrany instrevany
« Reply #1 on: March 29, 2018, 08:03:20 AM »

Hi James,

I'll include these functions in ParseUtil.inc in the next release:

Code: [Select]
`macro instrab(mm,bb,bk,lk,  bt,bm,lm)=====================================byte bt=bbbyte bm at @bkint lm=lkmm=0while lm  lm--  if bm=bt then mm=1 : exit while  @bm++wendend macrofunction instranyb(sys pb,pk, int lb,lk,i,di) as int====================================================int mmbyte *bb,*bk@bb=pb+i-1@bk=pkif di=0 then di=1while lb  lb--  instrab(mm,bb,bk,lk)  if mm then return @bb-pb+1  @bb+=diwendreturn 0end functionfunction instrany(int i,string*s,*k) as int===========================================if i<0 then i+=len(s)+1return instranyb(strptr(s),strptr(k), len(s)-i+1, len(k), i, 1)end functionfunction instrevany(int i,string*s,*k) as int=============================================if i<0 then i+=len(s)+1return instranyb(strptr(s),strptr(k), i, len(k), i,-1)end function`

#### jcfuller

• Full Member
• Posts: 143
##### Re: instrany instrevany
« Reply #2 on: March 29, 2018, 08:49:30 AM »
Charles,
Thanks Charles. But there is a problem or I am missing something?
instr is an intrinsic so we can leave out the the start position.
instrev (in ParseUtil) uses the length if start is zero but instrevany does not.
I also think instrany should also work this way. If start position is zero it starts at 1 (one)?

James

#### Charles Pegge

`macro instrab(mm,bb,bk,lk,  bt,bm,lm)=====================================byte bt=bbbyte bm at @bkint lm=lkmm=0while lm  lm--  if bm=bt then mm=1 : exit while  @bm++wendend macrofunction instranyb(sys pb,pk, int ls,lk,i,di) as int====================================================if not ls then return 0if i<0 then i+=ls+1if i<0 then i=1if i>ls then i=lsif di=0 then di=1if di>0 then  if i=0 then i=1  ls=ls-i+1else  if i=0 then i=ls  ls=iend ifint mmbyte *bb,*bk@bb=pb+i-1@bk=pkwhile ls  ls--  instrab(mm,bb,bk,lk)  if mm then return @bb-pb+1  @bb+=diwendreturn 0end functionfunction instrany(int i,string*s,*k) as int===========================================return instranyb(strptr(s),strptr(k), len(s), len(k), i, 1)end functionfunction instrevany(int i,string*s,*k) as int=============================================return instranyb(strptr(s),strptr(k), len(s), len(k), i,-1)end function`