richmemo: default search engine

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4587 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2016-03-24 12:56:23 +00:00
parent ba01d58f3f
commit d5f2adb382

View File

@ -294,7 +294,67 @@ end;
class function TWSCustomRichMemo.Search(const AWinControl: TWinControl; const ANiddle: string; class function TWSCustomRichMemo.Search(const AWinControl: TWinControl; const ANiddle: string;
const SearchOpts: TIntSearchOpt): Integer; const SearchOpts: TIntSearchOpt): Integer;
var
Hay : UnicodeString;
Niddle : UnicodeString;
Hay8 : String;
isUnicode : Boolean;
i, se, ln : Integer;
begin begin
if not Assigned(AWinControl) or not (AWinControl is TCustomRichMemo) then begin
Result:=-1;
Exit;
end;
if not GetTextLen(AWinControl, ln) then begin
Result:=-1;
Exit;
end;
isUnicode:=false;
if not GetSubText(AWinControl, 0, ln, true, isUnicode, Hay8, Hay) then begin
Result:=-1;
Exit;
end;
if not isUnicode then begin
Hay:=UTF8Decode(Hay8);
Hay8:='';
end;
if not (soMatchCase in SearchOpts.Options) then begin
Niddle:=WideLowerCase(UTF8Decode(ANiddle));
Hay:=WideLowercase(Hay);
end else
Niddle:=UTF8Decode(ANiddle);
i:=SearchOpts.start;
if i<=0 then i:=1 else inc(i);
if soBackward in SearchOpts.Options then begin
dec(i); // to allow repeatative search
se:=0;
if (SearchOpts.len>0) then se:=i-SearchOpts.len;
if se<=0 then se:=1;
for i:=i downto se do
//todo: unicode comparison is "a bit more" complex, than just memory comparison
if CompareMem(@Niddle[1], @Hay[i], length(Niddle)*2) then begin
Result:=i-1; // offset one character! since it should be cursor position
Exit;
end;
end else begin
se:=length(Hay)-length(Niddle);
if (SearchOpts.len>0) and (se-i>SearchOpts.len) then
se:=i+SearchOpts.len;
for i:=i to se do
//todo: unicode comparison is "a bit more" complex, than just memory comparison
if CompareMem(@Niddle[1], @Hay[i], length(Niddle)*2) then begin
Result:=i-1; // offset one character! since it should be cursor position
Exit;
end;
end;
Result:=-1; Result:=-1;
end; end;