SEEK into buffer

Started by newdep, March 17, 2004, 03:39:30 PM

Previous topic - Next topic

newdep

Hello Lutz,



Is there a quick way to do a repeated find into a buffer with index return?

(without converting it into list first exploding it and joining back to buffer)



I was thinking of an extention on the current 'seek and 'find.

Where seek is also able to seek (with buffer-pointer, indexed) in a buffer.

And 'find can start finding from a given index.





ie.

(set 'pointer (find "code" bigbuffer 1)  ; return i.e  100

(seek bigbuffer pointer)

; now the next FIND will start at 100 instead of 0

(set 'pointer (find "code" bigbuffer 1) ; return i.e 3000

...

etc...

etc...



Or

(find "code" bigbuffer 1|0 'index|nil )





Because im actualy missing an 'next' to move the pointer, i was thinking

perhpas 'seek could be extended and would have impact on 'find as well.



Thus find will normaly start from 0 except when index-pointer is defined

it will 'seek from that indexpointer first and then start finding from that indexpointer on.





Hope its a litlle clear ;-)



Regards,

Norman.
-- (define? (Cornflakes))

Lutz

#1
I understand what you are looking for, but wonder about the wider context in which you would use such an ability?



If the indices returned from find ar used to access the stuff in between the "code" (the search keys) than you could just use 'parse' i.e.:



(set 'str "hello123this is123an example")



(parse str "123") => ("hello" "this is" "an example")



and with an additional option the key string could be a regular expression. This will give you all the pieces in between your search string.



If you insist on getting the pointer positions, you could use 'slice' to advance the pointer:



(set 'ptr 0)

(while (set 'ptr (find key (slice buffer ptr)))

   (do-something-with buffer ptr))





Lutz

newdep

#2
Hello Lutz,



'Slice is an option I use currently, though its not very charming when

using buffers of i.e.  2 MB (raw binary data)..also its 1 step extra.

So i though that 'seek and/or 'find could be extended?



Parse is not realy an option either because of the index pointer..

So I have to choose currently for the slice option.



Perhaps its an idea for enhancement of 'find? with an index?



Regards,

Norman.
-- (define? (Cornflakes))