I am reading file data using TFileStreams in buffers of 1024 bytes (mostly).
I then use TRegExpr to see if a certain reg exp is found in the buffer. If it is, it 'does stuff' with the hit and then moves onto the next 1024 bytes of data and repeats until all the file is read.
Trouble is, sometimes, the buffer can contain the reg expr more than once, but the second (and upwards) occurances of the hit are obviously missed this way.
I am trying to work out how to get my program to "Parse the buffer for the regular expression. If found, do stuff, then check the rest of the buffer before reading the next segment".
The nearest string based function I found is NPos (
http://www.freepascal.org/docs-html/rtl/strutils/npos.html) but I not sure if that is what I need - I think it needs to know the N-th number you want in advance.
Bascially, I have so far :
function MyFunc(SourceFile:TFileStream): string
var
Buffer : array [1..1024] of char;
TotalBytesRead, BytesRead : Int64;
MyRegExpr : TRegExpr;
try
SourceFile.Position := 0;
while TotalBytesRead < SourceFile.Size do
begin
BytesRead := SourceFile.Read(Buffer,sizeof(Buffer)); // Read 1024 bytes of data
inc(TotalBytesRead, BytesRead); // Keep track of the amount of data read
// Buffer is then converted to ASCII and non-ASCII content removed and assigned to string variable 's'
if MyRegExpr.Exec(s) then
// Do stuff with the hit found in s
end;
end; // Go and read the next 1024 bytes
end; // All data read
finally
// Free Resources etc