On 03/11/2018 00:43, Geoff Canyon via use-livecode wrote:
I like that, changing it. Now available at
https://github.com/gcanyon/alloffsets

One thing I don't see how to do without significantly impacting performance
is to return all offsets if there are overlapping strings. For example:

allOffsets("aba","abababa")

would return 1,5, when it might be reasonable to expect it to return 1,3,5.
Using the offset function with numToSkip would make that easy; adapting
allOffsets to do so would be harder to do cleanly I think.

Can I suggest changing it to "someOffsets()" :-) :-)

But seriously, can you not iteratively run "allofsets" ?
something like .... (typed straight into email - totally untested)

function allOffsets pDel, pStr
 repeat with c = 1 to 255  -- or some other upper limit ?
    if NOT pDel contains numtochar(c) then
       put numtochar(c) into c
       exit repeat
    end if
  end repeat
  repeat forever
    put someOffsets(pDel, pStr) into newR
    if the number of items in newR = 0 then exit repeat
    repeat for each item I in newR
       put c into char I of newR
    end repeat
    put newR after R
  end repeat
  sort items of R numeric
  return R
end alloffsets

-- Alex.

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to