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

  • Admin Support Member
  • *****
  • Posts: 3721
    • Oxygen Basic
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=bb
byte bm at @bk
int lm=lk
mm=0
while lm
  lm--
  if bm=bt then mm=1 : exit while
  @bm++
wend
end macro


function instranyb(sys pb,pk, int lb,lk,i,di) as int
====================================================
int mm
byte *bb,*bk
@bb=pb+i-1
@bk=pk
if di=0 then di=1
while lb
  lb--
  instrab(mm,bb,bk,lk)
  if mm then return @bb-pb+1
  @bb+=di
wend
return 0
end function


function instrany(int i,string*s,*k) as int
===========================================
if i<0 then i+=len(s)+1
return instranyb(strptr(s),strptr(k), len(s)-i+1, len(k), i, 1)
end function


function instrevany(int i,string*s,*k) as int
=============================================
if i<0 then i+=len(s)+1
return 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

  • Admin Support Member
  • *****
  • Posts: 3721
    • Oxygen Basic
Re: instrany instrevany
« Reply #3 on: March 29, 2018, 04:21:40 PM »
Okay, James.

 I've also added boundary limits, and negative index, so -i means index from the right.

Code: [Select]
macro instrab(mm,bb,bk,lk,  bt,bm,lm)
=====================================
byte bt=bb
byte bm at @bk
int lm=lk
mm=0
while lm
  lm--
  if bm=bt then mm=1 : exit while
  @bm++
wend
end macro


function instranyb(sys pb,pk, int ls,lk,i,di) as int
====================================================
if not ls then return 0
if i<0 then i+=ls+1
if i<0 then i=1
if i>ls then i=ls
if di=0 then di=1
if di>0 then
  if i=0 then i=1
  ls=ls-i+1
else
  if i=0 then i=ls
  ls=i
end if
int mm
byte *bb,*bk
@bb=pb+i-1
@bk=pk
while ls
  ls--
  instrab(mm,bb,bk,lk)
  if mm then return @bb-pb+1
  @bb+=di
wend
return 0
end function


function instrany(int i,string*s,*k) as int
===========================================
return instranyb(strptr(s),strptr(k), len(s), len(k), i, 1)
end function


function instrevany(int i,string*s,*k) as int
=============================================
return instranyb(strptr(s),strptr(k), len(s), len(k), i,-1)
end function