📄 _stregex.pas
字号:
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* 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 TurboPower SysTools
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1996-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* _STREGEX.PAS 3.00 *}
{*********************************************************}
{$I STDEFINE.INC}
{$I STCOMDEF.INC}
unit _StRegEx;
interface
uses
ComObj, ActiveX, AxCtrls, Classes, StUtils, StStrms, StRegEx, SysTools_TLB, StdVcl;
type
TStRegEx = class(TAutoObject, IConnectionPointContainer, IStRegEx)
private { Private declarations }
FConnectionPoints: TConnectionPoints;
FConnectionPoint: TConnectionPoint;
FSinkList: TList;
FEvents: IStRegExEvents;
FStRegEx : StRegEx.TStStreamRegEx;
FMatchPattern : IStStringList;
FSelAvoidPattern : IStStringList;
FReplacePattern : IStStringList;
FIsLicensed : Boolean;
procedure _OnProgress(Sender : TObject; Percent : Word);
public { Public declarations }
procedure Initialize; override;
destructor Destroy; override;
protected { Protected declarations }
{ IConnectionPointContainer }
property ConnectionPoints: TConnectionPoints read FConnectionPoints
implements IConnectionPointContainer;
procedure EventSinkChanged(const EventSink: IUnknown); override;
{ IStRegEx properties (GET) }
function Get_Avoid: WordBool; safecall;
function Get_IgnoreCase: WordBool; safecall;
function Get_InFixedLineLength: Integer; safecall;
function Get_InLineTermChar: WideString; safecall;
function Get_InLineTerminator: TStLineTerminator; safecall;
function Get_LineCount: Integer; safecall;
function Get_LineNumbers: WordBool; safecall;
function Get_LinesMatched: Integer; safecall;
function Get_LinesPerSecond: Integer; safecall;
function Get_LinesReplaced: Integer; safecall;
function Get_LinesSelected: Integer; safecall;
function Get_MatchPattern: IStStringList; safecall;
function Get_OutFixedLineLength: Integer; safecall;
function Get_OutLineTermChar: WideString; safecall;
function Get_OutLineTerminitor: Integer; safecall;
function Get_OutputOptions: TStOutputOption; safecall;
function Get_ReplacePattern: IStStringList; safecall;
function Get_SelAvoidPattern: IStStringList; safecall;
function Get_Stream: OleVariant; safecall;
{ IStRegEx properties (SET) }
procedure Set_Avoid(Value: WordBool); safecall;
procedure Set_IgnoreCase(Value: WordBool); safecall;
procedure Set_InFixedLineLength(Value: Integer); safecall;
procedure Set_InLineTermChar(const Value: WideString); safecall;
procedure Set_InLineTerminator(Value: TStLineTerminator); safecall;
procedure Set_LineNumbers(Value: WordBool); safecall;
procedure Set_MatchPattern(const Value: IStStringList); safecall;
procedure Set_OutFixedLineLength(Value: Integer); safecall;
procedure Set_OutLineTermChar(const Value: WideString); safecall;
procedure Set_OutLineTerminitor(Value: Integer); safecall;
procedure Set_OutputOptions(Value: TStOutputOption); safecall;
procedure Set_ReplacePattern(const Value: IStStringList); safecall;
procedure Set_SelAvoidPattern(const Value: IStStringList); safecall;
procedure Set_Stream(Value: OleVariant); safecall;
{ IStRegEx Methods }
function CheckString(const S: WideString; var StartPos, EndPos, Length: Integer): WordBool; safecall;
function DOSMaskToRegEx(const Masks: WideString): WordBool; safecall;
function Execute: WordBool; safecall;
procedure LoadFromFile(const FileName: WideString); safecall;
procedure SaveToFile(const FileName: WideString); safecall;
function License(const Key: WideString): WordBool; safecall;
end;
implementation
uses ComServ, _StUtil {$IFDEF LICENSE}, StComLic {$ENDIF};
{ ********** TStRegExp Interface - IConnectionPointContainer Methods ********************* }
procedure TStRegEx.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as IStRegExEvents;
if FConnectionPoint <> nil then
FSinkList := FConnectionPoint.SinkList;
end;
{ ********** TStRegExp Interface ********************************************************* }
procedure TStRegEx.Initialize;
begin
inherited Initialize;
FConnectionPoints := TConnectionPoints.Create(Self);
if AutoFactory.EventTypeInfo <> nil then
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
AutoFactory.EventIID, ckSingle, EventConnect)
else FConnectionPoint := nil;
{$IFDEF LICENSE}
FIsLicensed := False;
{$ELSE}
FIsLicensed := True;
{$ENDIF}
FStRegEx := StRegEx.TStStreamRegEx.Create;
FStRegEx.InputStream := Classes.TMemoryStream.Create;
FStRegEx.OutputStream := Classes.TMemoryStream.Create;
FMatchPattern := TStStringList.Create(FStRegEx.MatchPattern);
FSelAvoidPattern := TStStringList.Create(FStRegEx.SelAvoidPattern);
FReplacePattern := TStStringList.Create(FStRegEx.ReplacePattern);
FStRegEx.OnProgress := _OnProgress;
end;
destructor TStRegEx.Destroy;
begin
if Assigned(FStRegEx.InputStream) then
FStRegEx.InputStream.Free;
if Assigned(FStRegEx.OutputStream) then
FStRegEx.OutputStream.Free;
FMatchPattern := nil;
FSelAvoidPattern := nil;
FReplacePattern := nil;
if Assigned(FStRegEx) then
FStRegEx.Free;
inherited Destroy;
end;
{ ********** TStRegExp Events ************************************************************ }
procedure TStRegEx._OnProgress(Sender : TObject; Percent : Word);
begin
if Assigned(FEvents) then
FEvents.OnProgress(Integer(Percent));
end;
{ ********** TStRegExp Properties *** (Get) ********************************************** }
function TStRegEx.Get_Avoid: WordBool;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.Avoid;
end;
function TStRegEx.Get_IgnoreCase: WordBool;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.IgnoreCase;
end;
function TStRegEx.Get_InFixedLineLength: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.InFixedLineLength;
end;
function TStRegEx.Get_InLineTermChar: WideString;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.InLineTermChar;
end;
function TStRegEx.Get_InLineTerminator: TStLineTerminator;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := TStLineTerminator(FStRegEx.InLineTerminator);
end;
function TStRegEx.Get_LineCount: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.LineCount;
end;
function TStRegEx.Get_LineNumbers: WordBool;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.LineNumbers;
end;
function TStRegEx.Get_LinesMatched: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.LinesMatched;
end;
function TStRegEx.Get_LinesPerSecond: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.LinesPerSecond;
end;
function TStRegEx.Get_LinesReplaced: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.LinesReplaced;
end;
function TStRegEx.Get_LinesSelected: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.LinesSelected;
end;
function TStRegEx.Get_MatchPattern: IStStringList;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FMatchPattern;
end;
function TStRegEx.Get_OutFixedLineLength: Integer;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.OutFixedLineLength;
end;
function TStRegEx.Get_OutLineTermChar: WideString;
begin
{$IFDEF LICENSE}
if (not FIsLicensed) or (not COMHasBeenLicensed) then
OleError(CLASS_E_NOTLICENSED);
{$ENDIF}
Result := FStRegEx.OutLineTermChar;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -