I can see how to do this in principle but I can't iron out the details and I'm sure there must be some ready made code for doing it 'out there' on the internet. It's just rather difficult to come up with search terms when I don't know what to call it.
To explain in detail I want to search for a (constant) string in a byte stream that I can't rewind and I don't want to use any significant buffer space (the constant string I'm looking for is quite long).
So, obviously one reads a byte at a time from the stream to see if it matches the first character of the constant string, if that matches one moves on to the second, etc. When the whole string has been matched then it's found - so far so good. However, when a character *doesn't* match one can't go back up the input stream, *but* we know the previous characters as they're the ones in the constant string that we have matched so far. Thus we can 'wind back' by using the constant string for the number of characters that did match and then continue down the stream.
If anyone can follow that rubbish explanation then could they possibly tell me what the algorithm is called and/or point me at some sample code?