Extending Base._searchindex to "findall"?

Hello!

I have a Vector{UInt8}, in which I want to find all occurences of “Lorem”.

(Text from https://www.lipsum.com/)

TextToSearch   = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."

nTextToSearch  = length(TextToSearch)

TranscodedText = transcode(UInt8,TextToSearch)[:]



Needle        = "Lorem"
SearchNeedle  = codeunits(Needle)
nSearchNeedle = ncodeunits(Needle)

How do I go about doing this in a meaningful way. I’ve tried to make a while loop:

Condition1   = StartPoint >= nTextToSearch
Condition2   = SearchVal  <= 0

while(Condition1 == false || Condition2 == false)
    prevSearchVal = SearchVal
    SearchVal     = Base._searchindex(TranscodedText,SearchNeedle,StartPoint);
    push!(idHits,SearchVal)
    StartPoint    = nSearchNeedle+SearchVal
end

But I cannot get it to work properly (i.e. the condition never breaks, even if I put the condition statements inside the loop).

So I was thinking if it was better to find a way to overload findall to work on Vector{UInt8}?

Please do note, that I know I can use findall(TextToSearch,“Lorem”) directly, but I need it explicitly to work on Vector{UInt8}

Kind regards

Doing a google search I was fortunate enough to find this answer from 2 years ago, on a question I had asked my self… :sweat_smile:

Therefore a working loop can simply be done as:

idHits     = Vector{Int64}()
ind        = 0

while true
    ind  = Base._searchindex(TranscodedText, SearchNeedle, ind+1)
    if ind == 0
        break
    end
    push!(idHits,ind)
end

Kind regards