Find vs. Offset

Geoff Canyon gcanyon at gmail.com
Fri Dec 28 13:18:55 EST 2012


I'm a big advocate of clean functions, and I just want to point out that
this is really nicely done: clear, compact, efficient, documented, and the
function name itself perfectly describes what it does.

Really nice!

On Wed, Dec 19, 2012 at 4:33 PM, Peter M. Brigham <pmbrig at gmail.com> wrote:

> function offsets str,container,includeOverlaps
>    -- returns a comma-delimited list of all the offsets of str in container
>    -- third param is optional:
>    --     offsets("xx","xxxxxx") returns "1,3,5" not "1,2,3,4,5"
>    --     ie, by default, overlapping offsets are not counted
>    --     if you want overlapping offsets then pass "true" in 3rd param
>    -- returns 0 if str is not in container
>    if str is not in container then return 0
>    if includeOverlaps = empty then put false into includeOverlaps
>    put empty into offsetList
>    put 0 into startPoint
>    repeat
>       put offset(str,container,startPoint) into thisOffset
>       if thisOffset = 0 then exit repeat
>       add thisOffset to startPoint
>       put startPoint & comma after offsetList
>       if not includeOverlaps then
>          add length(str)-1 to startPoint
>       end if
>    end repeat
>    return item 1 to -1 of offsetList -- delete trailing comma
> end offsets
>
>



More information about the use-livecode mailing list