[yunqa.de] Re: DIRegx 4.7.2: PCRE_ERROR_PARTIAL when using TDIRegExSearchStream_Binary, even if PCRE_PARTIAL is disabled

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Fri, 29 May 2009 11:16:58 +0200

At 18:08 28.05.2009, Luigi D. Sandon wrote:

>I often get PCRE_ERROR_PARTIAL results if I perform a search using 
>TDIRegExSearchStream_Binary, even if PCRE_PARTIAL (moPartial) in not set in 
>MatchOptions. 

TDIRegExSearchStream_Binary (or any TDIRegExSearchStream descendant) always 
sets PCRE_PARTIAL internally because it relies on partial matching to perform 
block-wise matching.

With TDIRegExSearchStream_Binary, PCRE_ERROR_PARTIAL indicates that an initial 
part of the pattern was matched, but the stream ended before the entire pattern 
could be matched.

This example code searches for 1000 'a' characters. Since only 999 are 
provided, it returns PCRE_ERROR_PARTIAL:

procedure ERROR_PARTIAL;
var
  RE: TDIRegExSearchStream_Binary;
  s: TStream;
  ByteStart, ByteLength: Int64;
  CharStart, CharLength: Int64;
begin
  {$ASSERTIONS ON}
  RE := TDIRegExSearchStream_Binary.Create(nil);
  try
    s := TStringStream.Create(StringOfChar('a', 999));
    try
      Assert(RE.CompileMatchPatternStr('a{1000}'));
      RE.SearchInit(s);
      Assert(RE.SearchNext(ByteStart, ByteLength, CharStart, CharLength) =
        PCRE_ERROR_PARTIAL);
    finally
      s.Free;
    end;
  finally
    RE.Free;
  end;
end;

>The error disappears if I use TDIPerlRegEx instead.

TDIRegExSearchStream_Binary is based on TDIDfaRegEx. In order to facilitate 
partial matching, it uses an alternative matching algorithm than TDIPerlRegEx. 
Search the DIRegEx help for "pcrematching man page" for a full discussion of 
the differences.

>I am still using DIRegx 4.7.2, is this an issue fixed in a later version of 
>not?

I do not see this as an issue, and it has not changed since 4.7.2.

Changing this behaviour would introduce a backward incompatibility if 
PCRE_ERROR_NOMATCH is returned instead of PCRE_ERROR_PARTIAL. Also, it would 
give up the possibility to detect if the data ends prematurely.

Ralf 

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: