mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 16:56:01 +02:00
added syneditregexsearch.pas
git-svn-id: trunk@2324 -
This commit is contained in:
parent
db29a16dcd
commit
19b1eab0d1
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -47,6 +47,7 @@ components/synedit/syneditkeycmds.pp svneol=native#text/pascal
|
||||
components/synedit/syneditmiscclasses.pp svneol=native#text/pascal
|
||||
components/synedit/syneditmiscprocs.pp svneol=native#text/pascal
|
||||
components/synedit/syneditplugins.pas svneol=native#text/pascal
|
||||
components/synedit/syneditregexsearch.pas svneol=native#text/pascal
|
||||
components/synedit/syneditsearch.pp svneol=native#text/pascal
|
||||
components/synedit/syneditstrconst.pp svneol=native#text/pascal
|
||||
components/synedit/synedittextbuffer.pp svneol=native#text/pascal
|
||||
|
@ -127,11 +127,6 @@ const
|
||||
{$ENDIF}
|
||||
|
||||
type
|
||||
TSynSearchOption = (ssoMatchCase, ssoWholeWord, ssoBackwards,
|
||||
ssoEntireScope, ssoSelectedOnly, ssoReplace, ssoReplaceAll, ssoPrompt
|
||||
{$IFDEF SYN_LAZARUS}, ssoRegExpr, ssoRegExprMultiLine{$ENDIF});
|
||||
TSynSearchOptions = set of TSynSearchOption;
|
||||
|
||||
TSynReplaceAction = (raCancel, raSkip, raReplace, raReplaceAll);
|
||||
|
||||
ESynEditError = class(Exception);
|
||||
|
@ -43,12 +43,11 @@ interface
|
||||
|
||||
uses
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
LCLLinux,
|
||||
LCLType, GraphType,
|
||||
LCLLinux, LCLType, GraphType,
|
||||
{$ELSE}
|
||||
Windows,
|
||||
{$ENDIF}
|
||||
Classes, Graphics, Controls, SysUtils;
|
||||
Classes, Graphics, Controls, SysUtils, SynEditTypes;
|
||||
|
||||
type
|
||||
TSynSelectedColor = class(TPersistent)
|
||||
@ -200,6 +199,27 @@ type
|
||||
procedure DrawMarkTransparent(ACanvas: TCanvas; Number, X, Y,
|
||||
LineHeight: integer; TransparentColor: TColor);
|
||||
end;
|
||||
|
||||
|
||||
{ TSynEditSearchCustom }
|
||||
|
||||
TSynEditSearchCustom = class(TComponent)
|
||||
protected
|
||||
function GetPattern: string; virtual; abstract;
|
||||
procedure SetPattern(const Value: string); virtual; abstract;
|
||||
function GetLength(aIndex: integer): integer; virtual; abstract;
|
||||
function GetResult(aIndex: integer): integer; virtual; abstract;
|
||||
function GetResultCount: integer; virtual; abstract;
|
||||
procedure SetOptions(const Value: TSynSearchOptions); virtual; abstract;
|
||||
public
|
||||
function FindAll(const NewText: string): integer; virtual; abstract;
|
||||
property Pattern: string read GetPattern write SetPattern;
|
||||
property ResultCount: integer read GetResultCount;
|
||||
property Results[aIndex: integer]: integer read GetResult;
|
||||
property Lengths[aIndex: integer]: integer read GetLength;
|
||||
property Options: TSynSearchOptions write SetOptions;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
|
152
components/synedit/syneditregexsearch.pas
Normal file
152
components/synedit/syneditregexsearch.pas
Normal file
@ -0,0 +1,152 @@
|
||||
{-------------------------------------------------------------------------------
|
||||
The contents of this file are subject to the Mozilla Public License
|
||||
Version 1.1 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||
the specific language governing rights and limitations under the License.
|
||||
|
||||
The Original Code is: SynEditRegexSearch.pas, released 2002-07-26.
|
||||
|
||||
Original Code by Eduardo Mauro, Gerald Nunn and Flávio Etrusco.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributors to the SynEdit project are listed in the Contributors.txt file.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of the
|
||||
GNU General Public License Version 2 or later (the "GPL"), in which case
|
||||
the provisions of the GPL are applicable instead of those above.
|
||||
If you wish to allow use of your version of this file only under the terms
|
||||
of the GPL and not to allow others to use your version of this file
|
||||
under the MPL, indicate your decision by deleting the provisions above and
|
||||
replace them with the notice and other provisions required by the GPL.
|
||||
If you do not delete the provisions above, a recipient may use your version
|
||||
of this file under either the MPL or the GPL.
|
||||
|
||||
$Id$
|
||||
|
||||
You may retrieve the latest version of this file at the SynEdit home page,
|
||||
located at http://SynEdit.SourceForge.net
|
||||
|
||||
Known Issues:
|
||||
-------------------------------------------------------------------------------}
|
||||
|
||||
unit SynEditRegexSearch;
|
||||
|
||||
{$I SynEdit.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes,
|
||||
SynEditTypes,
|
||||
SynRegExpr,
|
||||
SynEditMiscClasses;
|
||||
|
||||
type
|
||||
TSynEditRegexSearch = class(TSynEditSearchCustom)
|
||||
private
|
||||
fRegex : TRegExpr;
|
||||
fPositions: TList;
|
||||
fLengths: TList;
|
||||
protected
|
||||
function GetPattern: string; override;
|
||||
procedure SetPattern(const Value: string); override;
|
||||
procedure SetOptions(const Value: TSynSearchOptions); override;
|
||||
function GetLength(aIndex: integer): integer; override;
|
||||
function GetResult(aIndex: integer): integer; override;
|
||||
function GetResultCount: integer; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
function FindAll(const NewText: string): integer; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{$IFNDEF SYN_LAZARUS}
|
||||
uses
|
||||
{$IFDEF SYN_CLX}
|
||||
QConsts;
|
||||
{$ELSE}
|
||||
Consts;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{ TSynEditRegexSearch }
|
||||
|
||||
constructor TSynEditRegexSearch.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
fRegex := TRegExpr.Create;
|
||||
fPositions := TList.Create;
|
||||
fLengths := TList.Create;
|
||||
end;
|
||||
|
||||
destructor TSynEditRegexSearch.Destroy;
|
||||
begin
|
||||
fRegex.Free;
|
||||
fPositions.Free;
|
||||
fLengths.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TSynEditRegexSearch.FindAll(const NewText: string): integer;
|
||||
|
||||
procedure AddResult(const aPos, aLength: integer);
|
||||
begin
|
||||
fPositions.Add( pointer(aPos) );
|
||||
fLengths.Add( pointer(aLength) );
|
||||
end;
|
||||
|
||||
begin
|
||||
fPositions.Clear;
|
||||
fLengths.Clear;
|
||||
if fRegex.Exec( NewText ) then
|
||||
begin
|
||||
AddResult( fRegex.MatchPos[0], fRegex.MatchLen[0] );
|
||||
Result := 1;
|
||||
while fRegex.ExecNext do
|
||||
begin
|
||||
AddResult( fRegex.MatchPos[0], fRegex.MatchLen[0] );
|
||||
Inc( Result );
|
||||
end;
|
||||
end
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TSynEditRegexSearch.GetLength(aIndex: integer): integer;
|
||||
begin
|
||||
Result := integer( fLengths[ aIndex ] );
|
||||
end;
|
||||
|
||||
function TSynEditRegexSearch.GetPattern: string;
|
||||
begin
|
||||
Result := fRegex.Expression;
|
||||
end;
|
||||
|
||||
function TSynEditRegexSearch.GetResult(aIndex: integer): integer;
|
||||
begin
|
||||
Result := integer( fPositions[ aIndex ] );
|
||||
end;
|
||||
|
||||
function TSynEditRegexSearch.GetResultCount: integer;
|
||||
begin
|
||||
Result := fPositions.Count;
|
||||
end;
|
||||
|
||||
procedure TSynEditRegexSearch.SetOptions(const Value: TSynSearchOptions);
|
||||
begin
|
||||
fRegex.ModifierI := not( ssoMatchCase in Value );
|
||||
end;
|
||||
|
||||
procedure TSynEditRegexSearch.SetPattern(const Value: string);
|
||||
begin
|
||||
fRegex.Expression := Value;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -56,6 +56,11 @@ type
|
||||
PSynSelectionMode = ^TSynSelectionMode;
|
||||
TSynSelectionMode = (smNormal, smLine, smColumn);
|
||||
|
||||
TSynSearchOption = (ssoMatchCase, ssoWholeWord, ssoBackwards,
|
||||
ssoEntireScope, ssoSelectedOnly, ssoReplace, ssoReplaceAll, ssoPrompt
|
||||
{$IFDEF SYN_LAZARUS}, ssoRegExpr, ssoRegExprMultiLine{$ENDIF});
|
||||
TSynSearchOptions = set of TSynSearchOption;
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user