SynEdit search: Fix searching multi-line text. Found text could have longer lines (Pattern expected line-end), if start matched.

git-svn-id: trunk@39845 -
This commit is contained in:
martin 2013-01-14 01:49:07 +00:00
parent 81894596dd
commit ade191f786
2 changed files with 37 additions and 7 deletions

View File

@ -612,13 +612,12 @@ var
//DebugLn(['MultiLinePatternFits Forward: line too short']);
exit; // line too short
end;
if (LineEndPos=length(Pat)) and (CompareEndPos>length(CurLineStr)) then
begin
//DebugLn(['MultiLinePatternFits Forward: line too long']);
exit; // line too long
end;
if (LineStartPos<=length(Pat))
and (not CompareContent(PChar(CurLineStr),@Pat[LineStartPos],
If (CompareEndPos <> length(CurLineStr)) and
(LineEndPos+1+Length(LineEnding) <= length(Pat)) and
CompareMem(@Pat[LineEndPos+1], PChar(LineEnding), length(LineEnding))
then
exit; // Not last line, and not same length
if (not CompareContent(PChar(CurLineStr),@Pat[LineStartPos],
CompareEndPos))
then begin
//DebugLn(['MultiLinePatternFits Forward: line mismatches']);

View File

@ -26,6 +26,7 @@ type
procedure TestSearchSimpleUtf8;
procedure TestSearchSimpleRegEx;
procedure FindMatchingBracket;
procedure TestSearchMultiLine; // not regex
end;
implementation
@ -251,6 +252,36 @@ begin
hl.Free;
end;
procedure TTestSynSearch.TestSearchMultiLine;
begin
ReCreateEdit;
SetLines(['', // 1
'a',
'',
'b',
'', // 5
'a',
'x',
'b',
'',
'a', // 10
'x2',
'b',
'']);
fTSearch := TSynEditSearch.Create;
fTSearch.Sensitive := False;
fTSearch.Whole := False;
fTSearch.Backwards := False;
fTSearch.RegularExpressions := False;
fTSearch.RegExprMultiLine := False;
fTSearch.Replacement := '';
TestFindNext('3 lines middle empty', 'a'+LineEnding+LineEnding+'b', 1,1, 1,9, true, 1,2, 2,4);
TestFindNext('3 lines middle empty - no match', 'a'+LineEnding+LineEnding+'b', 1,5, 1,9, False, 1,2, 2,4);
end;
//more ftsearch:
//function FindAll(const NewText: string): integer;
//function FindFirstUTF8(const NewText: string): Integer;