Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

Pi Digital via use-livecode
I’m working on an update to the stack now. Moving buttons to the left side to make it easier to add more.

Thanks,
Brian
On Nov 4, 2018, 10:02 PM -0600, Mark Wieder via use-livecode <[hidden email]>, wrote:

> On 11/4/18 4:45 PM, Brian Milby via use-livecode wrote:
> > My updated solution always looks for overlap but if none are found it uses optimized versions of the search (private functions instead of inside the main function). I special case for no overlap and a single overlap in the delimiter. It is about the same speed as Geoff’s.
>
> Nice. I tried to get tricky and replace that 'replace with' loop with a
> 'repeat for each' loop, but ended up about 20% slower. Not at all what I
> expected.
>
> --
> Mark Wieder
> [hidden email]
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

Pi Digital via use-livecode
Here's an image of the stack in my fork of the repo:
https://github.com/bwmilby/alloffsets/blob/bwm/bwm/stack_allOffsets_card_id_1018.png


On Sun, Nov 4, 2018 at 10:07 PM Brian Milby <[hidden email]> wrote:

> I’m working on an update to the stack now. Moving buttons to the left side
> to make it easier to add more.
>
> Thanks,
> Brian
> On Nov 4, 2018, 10:02 PM -0600, Mark Wieder via use-livecode <
> [hidden email]>, wrote:
>
> On 11/4/18 4:45 PM, Brian Milby via use-livecode wrote:
>
> My updated solution always looks for overlap but if none are found it uses
> optimized versions of the search (private functions instead of inside the
> main function). I special case for no overlap and a single overlap in the
> delimiter. It is about the same speed as Geoff’s.
>
>
> Nice. I tried to get tricky and replace that 'replace with' loop with a
> 'repeat for each' loop, but ended up about 20% slower. Not at all what I
> expected.
>
> --
> Mark Wieder
> [hidden email]
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

Pi Digital via use-livecode
In reply to this post by Pi Digital via use-livecode
On Sun, Nov 4, 2018 at 7:42 PM Bob Sneidar via use-livecode <
[hidden email]> wrote:

> Simply add 1 to the last offset pointer. If after the first iteration you
> return 1, then set the charsToSkip to 2 instead of offset +
> len(searchString) if you take my meaning.
>
> Bob S
>

The method we're using avoids charsToSkip because it suffers mightily with
multi-byte characters. But the latest updates handle overlapping results,
see other posts in this thread.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

Pi Digital via use-livecode
In reply to this post by Pi Digital via use-livecode
On Sun, Nov 4, 2018 at 7:11 PM Mark Wieder via use-livecode <
[hidden email]> wrote:

>
> If you're looking for 'romeo' in pText, would you set pOverlaps to true
> or to false?


I'd set it to false, there's no way for "romeo" to overlap. But even if I
were looking for "radar", which could overlap, I'd set it to false if I
were searching an english text document, because there's no word
"radaradar". But as I said, I've switched it to default to finding overlaps.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

Pi Digital via use-livecode
In reply to this post by Pi Digital via use-livecode
I've updated my GitHub to the following, which adopts Brian's "starts with"
(I can't count how many times I've had to re-remember that "starts with" is
faster than comparing to char 1 through <whatever>) and added minor
optimizations to the wrapping-up code.

gc

function allOffsets D,S,pCase,pNoOverlaps
   -- returns a comma-delimited list of the offsets of D in S
   set the caseSensitive to pCase is true
   put length(D) into dLength
   put pNoOverlaps and dLength > 1 into pNoOverlaps
   put numtochar(chartonum(char -1 of D) mod 2 + 1) after S
   if not pNoOverlaps then
      repeat with i = 1 to dLength - 1
         if not (char i + 1 to -1 of D is char 1 to dLength - i of D) then
next repeat
         put char -i to -1 of D into OV[i]
         put i & cr after kList
      end repeat
   end if
   set the itemDel to D
   put 1 - dLength into C
   if pNoOverlaps or kList is empty then
      repeat for each item i in S
         add length(i) + dLength to C
         put C,"" after R
      end repeat
   else
      repeat for each item i in S
         repeat for each line K in kList
            if i & D begins with OV[K] then put (C + K),"" after R
         end repeat
         add length(i) + dLength to C
         put C,"" after R
      end repeat
   end if
   set the itemDel to comma
   repeat with i = 1 to 99999999999
      if item i of R > 0 then exit repeat
   end repeat
   delete item 1 to i - 1 of R
   if R begins with C then return 0
   return char 1 to -3 - length(C) of R
end allOffsets
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
12