On 13 September 2012 13:04, Toni Cárdenas <
to...@tcardenas.me> wrote:
> Here is a more illustrative test:
http://play.golang.org/p/toGyzf5toG
>
> Examining the output, FindReaderIndex seems to take a certain amount of
> runes from the buffer and to consume from it until the pattern is found, but
> then it doesn't put back the remaining taken runes onto the buffer. I don't
> know if this behaviour is to be expected, but if it is, which would be a
> more proper way of parsing a file?
>
> I can remake the buffer on each iteration like this:
>
http://play.golang.org/p/fYkIYBlPdx , but certainly it doesn't look nice.
This is an interesting problem that I made a little toy solution for
some time ago:
http://play.golang.org/p/1pFFrhYKXW
I think it's about as good as you can get - there is the inherent
problem that you have to buffer all input until a match has
occurred, because the match might actually happen
right at the beginning.
So searching for a string that's never found in a large stream
is inefficient. If you were doing it for real, you might use
a temporary file.