Browse Source

+ Implement TSAXReader.Abort method, which can be used to end the parsing prematurely (Mantis #16703)

git-svn-id: trunk@15414 -
sergei 15 years ago
parent
commit
73bafe0444
3 changed files with 13 additions and 6 deletions
  1. 7 0
      packages/fcl-xml/src/sax.pp
  2. 3 2
      packages/fcl-xml/src/sax_html.pp
  3. 3 4
      packages/fcl-xml/src/sax_xml.pp

+ 7 - 0
packages/fcl-xml/src/sax.pp

@@ -177,6 +177,7 @@ type
   protected
     FCurColumnNumber, FCurLineNumber: Integer;
     FCurPublicID, FCurSystemID: SAXString;
+    FStopFlag: Boolean;
 
     function GetFeature(const Name: String): Boolean; virtual;
     function GetProperty(const Name: String): TObject; virtual;
@@ -213,6 +214,7 @@ type
     procedure Parse(AInput: TSAXInputSource); virtual; abstract; overload;
     procedure Parse(const SystemID: SAXString); virtual; overload;
     procedure ParseStream(AStream: TStream);
+    procedure Abort;
 
     // Current location
     property CurColumnNumber: Integer read FCurColumnNumber;
@@ -653,6 +655,11 @@ begin
   end;
 end;
 
+procedure TSAXReader.Abort;
+begin
+  FStopFlag := True;
+end;
+
 function TSAXReader.DoResolveEntity(const PublicID,
   SystemID: SAXString): TSAXInputSource;
 begin

+ 3 - 2
packages/fcl-xml/src/sax_html.pp

@@ -150,7 +150,8 @@ begin
   end;
 
   FEndOfStream := False;
-  while True do
+  FStopFlag := False;
+  while not FStopFlag do
   begin
     // Read data into the input buffer
     BufferSize := AInput.Stream.Read(Buffer, MaxBufferSize);
@@ -161,7 +162,7 @@ begin
     end;
 
     BufferPos := 0;
-    while BufferPos < BufferSize do
+    while (BufferPos < BufferSize) and not FStopFlag do
       case ScannerContext of
         scUnknown:
           case Buffer[BufferPos] of

+ 3 - 4
packages/fcl-xml/src/sax_xml.pp

@@ -141,7 +141,8 @@ begin
   end;
 
   FEndOfStream := False;
-  while True do
+  FStopFlag := False;
+  while not FStopFlag do
   begin
     // Read data into the input buffer
     BufferSize := AInput.Stream.Read(Buffer, MaxBufferSize);
@@ -152,7 +153,7 @@ begin
     end;
 
     BufferPos := 0;
-    while BufferPos < BufferSize do
+    while (BufferPos < BufferSize) and not FStopFlag do
       case ScannerContext of
         scUnknown:
           case Buffer[BufferPos] of
@@ -337,9 +338,7 @@ procedure TSAXXMLReader.EnterNewScannerContext(NewContext: TXMLScannerContext);
 var
   Attr: TSAXAttributes;
   TagName: String;
-  Found: Boolean;
   Ent: SAXChar;
-  i: Integer;
 begin
   case ScannerContext of
     scWhitespace: