2
0
Эх сурвалжийг харах

* Second patch from Mattias Gaertner (bug 19623, should fix 19633 as well)

git-svn-id: trunk@17845 -
michael 14 жил өмнө
parent
commit
0d14fc2851

+ 14 - 10
rtl/objpas/classes/parser.inc

@@ -41,15 +41,11 @@ var
   BytesRead: integer;
   BytesRead: integer;
 begin
 begin
   BytesRead := FStream.Read(FBuf^, ParseBufSize);
   BytesRead := FStream.Read(FBuf^, ParseBufSize);
-  if BytesRead = 0 then
-  begin
-    FEofReached := True;
-    Exit;
-  end;
   FBuf[BytesRead] := #0;
   FBuf[BytesRead] := #0;
   Inc(FDeltaPos, BytesRead);
   Inc(FDeltaPos, BytesRead);
   FPos := 0;
   FPos := 0;
   FBufLen := BytesRead;
   FBufLen := BytesRead;
+  FEofReached:=BytesRead = 0;
 end;
 end;
 
 
 procedure TParser.CheckLoadBuffer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 procedure TParser.CheckLoadBuffer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
@@ -112,9 +108,12 @@ begin
   begin
   begin
     inc(fPos);
     inc(fPos);
     CheckLoadBuffer;
     CheckLoadBuffer;
-    if fBuf[fPos]=#10 then inc(fPos); //CR LF
-  end
-  else inc(fPos); //LF
+  end;
+  if fBuf[fPos]=#10 then
+  begin
+    inc(fPos); //CR LF or LF
+    CheckLoadBuffer;
+  end;
   inc(fSourceLine);
   inc(fSourceLine);
   fDeltaPos:=-(fPos-1);
   fDeltaPos:=-(fPos-1);
 end;
 end;
@@ -132,6 +131,7 @@ begin
   begin
   begin
     bom[i]:=fBuf[fPos];
     bom[i]:=fBuf[fPos];
     inc(fPos);
     inc(fPos);
+    CheckLoadBuffer;
     inc(i);
     inc(i);
   end;
   end;
   if (bom<>(#$EF+#$BB+#$BF)) then
   if (bom<>(#$EF+#$BB+#$BF)) then
@@ -140,15 +140,16 @@ end;
 
 
 procedure TParser.SkipSpaces;
 procedure TParser.SkipSpaces;
 begin
 begin
-  while fBuf[fPos] in [' ',#9] do
+  while fBuf[fPos] in [' ',#9] do begin
     inc(fPos);
     inc(fPos);
+    CheckLoadBuffer;
+  end;
 end;
 end;
 
 
 procedure TParser.SkipWhitespace;
 procedure TParser.SkipWhitespace;
 begin
 begin
   while true do
   while true do
   begin
   begin
-    CheckLoadBuffer;
     case fBuf[fPos] of
     case fBuf[fPos] of
       ' ',#9  : SkipSpaces;
       ' ',#9  : SkipSpaces;
       #10,#13 : HandleNewLine
       #10,#13 : HandleNewLine
@@ -205,6 +206,7 @@ begin
   begin
   begin
     fFloatType:=fBuf[fPos];
     fFloatType:=fBuf[fPos];
     inc(fPos);
     inc(fPos);
+    CheckLoadBuffer;
     fToken:=toFloat;
     fToken:=toFloat;
   end
   end
   else fFloatType:=#0;
   else fFloatType:=#0;
@@ -330,6 +332,7 @@ begin
   fToken:=fBuf[fPos];
   fToken:=fBuf[fPos];
   fLastTokenStr:=fToken;
   fLastTokenStr:=fToken;
   inc(fPos);
   inc(fPos);
+  CheckLoadBuffer;
 end;
 end;
 
 
 constructor TParser.Create(Stream: TStream);
 constructor TParser.Create(Stream: TStream);
@@ -400,6 +403,7 @@ begin
       Error(SParUnterminatedBinValue);
       Error(SParUnterminatedBinValue);
     b:=b or GetHexValue(fBuf[fPos]);
     b:=b or GetHexValue(fBuf[fPos]);
     inc(fPos);
     inc(fPos);
+    CheckLoadBuffer;
     outbuf[i]:=b;
     outbuf[i]:=b;
     inc(i);
     inc(i);
     if i>=ParseBufSize then
     if i>=ParseBufSize then