mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 19:59:31 +02:00
Implements case insensitive search for SynEdit - From bug #18842: [Patch] Find Dialog with UTF8 - case sensitive
git-svn-id: trunk@33031 -
This commit is contained in:
parent
7b99f8bda3
commit
956f7e0bab
@ -7235,7 +7235,7 @@ begin
|
|||||||
IncPaintLock;
|
IncPaintLock;
|
||||||
try
|
try
|
||||||
//DebugLn(['TCustomSynEdit.SearchReplace ptStart=',dbgs(ptStart),' ptEnd=',dbgs(ptEnd),' ASearch="',dbgstr(ASearch),'" AReplace="',dbgstr(AReplace),'"']);
|
//DebugLn(['TCustomSynEdit.SearchReplace ptStart=',dbgs(ptStart),' ptEnd=',dbgs(ptEnd),' ASearch="',dbgstr(ASearch),'" AReplace="',dbgstr(AReplace),'"']);
|
||||||
while fTSearch.FindNextOne(FTheLinesView,ptStart,ptEnd,ptFoundStart,ptFoundEnd) do
|
while fTSearch.FindNextOne(FTheLinesView,ptStart,ptEnd,ptFoundStart,ptFoundEnd, True) do
|
||||||
begin
|
begin
|
||||||
//DebugLn(['TCustomSynEdit.SearchReplace FOUND ptStart=',dbgs(ptStart),' ptEnd=',dbgs(ptEnd),' ptFoundStart=',dbgs(ptFoundStart),' ptFoundEnd=',dbgs(ptFoundEnd)]);
|
//DebugLn(['TCustomSynEdit.SearchReplace FOUND ptStart=',dbgs(ptStart),' ptEnd=',dbgs(ptEnd),' ptFoundStart=',dbgs(ptFoundStart),' ptFoundEnd=',dbgs(ptFoundEnd)]);
|
||||||
// check if found place is entirely in range
|
// check if found place is entirely in range
|
||||||
|
@ -109,7 +109,7 @@ type
|
|||||||
function Next: Integer;
|
function Next: Integer;
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
function FindNextOne(Lines: TStrings; StartPos, EndPos: TPoint;
|
function FindNextOne(Lines: TStrings; StartPos, EndPos: TPoint;
|
||||||
out FoundStartPos, FoundEndPos: TPoint): boolean;
|
out FoundStartPos, FoundEndPos: TPoint; ASupportUnicodeCase: Boolean=False): boolean;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
property Count: Integer read fCount write fCount;
|
property Count: Integer read fCount write fCount;
|
||||||
property Finished: Boolean read GetFinished;
|
property Finished: Boolean read GetFinished;
|
||||||
@ -408,8 +408,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
|
// ASupportUnicodeCase -> If we will support Unicode lowercase/uppercase
|
||||||
|
// by default this is off to increase the speed of the routine
|
||||||
function TSynEditSearch.FindNextOne(Lines: TStrings; StartPos, EndPos: TPoint;
|
function TSynEditSearch.FindNextOne(Lines: TStrings; StartPos, EndPos: TPoint;
|
||||||
out FoundStartPos, FoundEndPos: TPoint): boolean;
|
out FoundStartPos, FoundEndPos: TPoint; ASupportUnicodeCase: Boolean=False): boolean;
|
||||||
// Note: all points are 1 based
|
// Note: all points are 1 based
|
||||||
// only local variables are 0 based
|
// only local variables are 0 based
|
||||||
var
|
var
|
||||||
@ -799,6 +801,8 @@ var
|
|||||||
|
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
|
SearchForStr: string;
|
||||||
|
FCondition: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if Pattern='' then exit;
|
if Pattern='' then exit;
|
||||||
@ -841,8 +845,18 @@ begin
|
|||||||
end else
|
end else
|
||||||
FirstPattern:=copy(Pat,1,SearchLineEndPos-1);
|
FirstPattern:=copy(Pat,1,SearchLineEndPos-1);
|
||||||
end;
|
end;
|
||||||
SearchFor:=PChar(FirstPattern);
|
if ASupportUnicodeCase then
|
||||||
SearchLen:=length(FirstPattern);
|
begin
|
||||||
|
SearchForStr := FirstPattern;
|
||||||
|
if not fSensitive then SearchForStr := UTF8LowerCase(SearchForStr);
|
||||||
|
SearchFor:=PChar(SearchForStr);
|
||||||
|
SearchLen:=Length(SearchForStr);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
SearchFor:=PChar(FirstPattern);
|
||||||
|
SearchLen:=length(FirstPattern);
|
||||||
|
end;
|
||||||
|
|
||||||
if fRegExpr then begin
|
if fRegExpr then begin
|
||||||
RegExprEngine.ModifierI:=not fSensitive;
|
RegExprEngine.ModifierI:=not fSensitive;
|
||||||
@ -865,6 +879,7 @@ begin
|
|||||||
// regex multi line whole word
|
// regex multi line whole word
|
||||||
repeat
|
repeat
|
||||||
LineStr:=Lines[y];
|
LineStr:=Lines[y];
|
||||||
|
if ASupportUnicodeCase and (not fSensitive) then LineStr := UTF8LowerCase(LineStr);
|
||||||
LineLen:=length(LineStr);
|
LineLen:=length(LineStr);
|
||||||
Line:=PChar(LineStr);
|
Line:=PChar(LineStr);
|
||||||
if not IsFirstLine then begin
|
if not IsFirstLine then begin
|
||||||
@ -906,7 +921,8 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
// normal search
|
// normal search
|
||||||
MaxPos:=LineLen-SearchLen;
|
MaxPos:=LineLen-SearchLen;
|
||||||
if (SearchLen=0) and ((LineLen=0) or IsMultiLinePattern) then begin
|
if (SearchLen=0) and ((LineLen=0) or IsMultiLinePattern) then
|
||||||
|
begin
|
||||||
// first (last if backwards) line of pattern is empty line
|
// first (last if backwards) line of pattern is empty line
|
||||||
if FBackwards then
|
if FBackwards then
|
||||||
FoundStartPos:=Point(LineLen,y+1)
|
FoundStartPos:=Point(LineLen,y+1)
|
||||||
@ -919,14 +935,26 @@ begin
|
|||||||
//DebugLn(['TSynEditSearch.FindNextOne x=',x,' MaxPos=',MaxPos,' Line="',Line,'"']);
|
//DebugLn(['TSynEditSearch.FindNextOne x=',x,' MaxPos=',MaxPos,' Line="',Line,'"']);
|
||||||
while (x>=0) and (x<=MaxPos) do begin
|
while (x>=0) and (x<=MaxPos) do begin
|
||||||
//DebugLn(['TSynEditSearch.FindNextOne x=',x]);
|
//DebugLn(['TSynEditSearch.FindNextOne x=',x]);
|
||||||
if (SearchLen=0) or (CompTable[Line[x]]=CompTable[SearchFor^]) then begin
|
if ASupportUnicodeCase then FCondition := (SearchLen=0) or (Line[x]=SearchFor^)
|
||||||
|
else FCondition := (SearchLen=0) or (CompTable[Line[x]]=CompTable[SearchFor^]);
|
||||||
|
if FCondition then
|
||||||
|
begin
|
||||||
//DebugLn(['TSynEditSearch.FindNextOne First character found x=',x,' Line[x]=',Line[x]]);
|
//DebugLn(['TSynEditSearch.FindNextOne First character found x=',x,' Line[x]=',Line[x]]);
|
||||||
if (not fWhole)
|
if (not fWhole) or (x=0) or (not (Line[x-1] in FIdentChars)) then
|
||||||
or (x=0) or (not (Line[x-1] in FIdentChars)) then begin
|
begin
|
||||||
i:=1;
|
i:=1;
|
||||||
while (i<SearchLen) and (CompTable[Line[x+i]]=CompTable[SearchFor[i]])
|
|
||||||
do
|
if ASupportUnicodeCase then
|
||||||
inc(i);
|
begin
|
||||||
|
while (i<SearchLen) and (Line[x+i]=SearchFor[i]) do
|
||||||
|
inc(i);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
while (i<SearchLen) and (CompTable[Line[x+i]]=CompTable[SearchFor[i]]) do
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
|
||||||
//DebugLn(['TSynEditSearch.FindNextOne x=',x,' SearchLen=',SearchLen,' i=',i]);
|
//DebugLn(['TSynEditSearch.FindNextOne x=',x,' SearchLen=',SearchLen,' i=',i]);
|
||||||
if i=SearchLen then begin
|
if i=SearchLen then begin
|
||||||
// the pattern fits to this position
|
// the pattern fits to this position
|
||||||
|
Loading…
Reference in New Issue
Block a user