mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-27 13:48:27 +02:00
Converter: refactoring and some variable name changes.
git-svn-id: trunk@40564 -
This commit is contained in:
parent
ae910387d1
commit
cd0e43972f
@ -37,7 +37,7 @@ uses
|
|||||||
// IDE
|
// IDE
|
||||||
LazarusIDEStrConsts, LazIDEIntf, FormEditor, IDEMsgIntf,
|
LazarusIDEStrConsts, LazIDEIntf, FormEditor, IDEMsgIntf,
|
||||||
// codetools
|
// codetools
|
||||||
CodeToolManager, StdCodeTools, CodeTree, CodeAtom, AVL_Tree,
|
CodeToolManager, StdCodeTools, CodeTree, CodeAtom,
|
||||||
FindDeclarationTool, PascalReaderTool, PascalParserTool, LFMTrees,
|
FindDeclarationTool, PascalReaderTool, PascalParserTool, LFMTrees,
|
||||||
ExprEval, KeywordFuncLists, BasicCodeTools, LinkScanner,
|
ExprEval, KeywordFuncLists, BasicCodeTools, LinkScanner,
|
||||||
CodeCache, SourceChanger, CustomCodeTool, CodeToolsStructs, EventCodeTool,
|
CodeCache, SourceChanger, CustomCodeTool, CodeToolsStructs, EventCodeTool,
|
||||||
|
@ -15,11 +15,10 @@ type
|
|||||||
|
|
||||||
TStringMapUpdater = class
|
TStringMapUpdater = class
|
||||||
private
|
private
|
||||||
fStringMap: TStringToStringTree;
|
fStringToStringMap: TStringToStringTree;
|
||||||
fMapNames: TStringList; // Names (keys) in fStringMap.
|
|
||||||
fSeenNames: TStringList;
|
fSeenNames: TStringList;
|
||||||
public
|
public
|
||||||
constructor Create(AStringsMap: TStringToStringTree);
|
constructor Create(AStringToStringMap: TStringToStringTree);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function FindReplacement(AIdent: string; out AReplacement: string): boolean;
|
function FindReplacement(AIdent: string; out AReplacement: string): boolean;
|
||||||
end;
|
end;
|
||||||
@ -31,7 +30,7 @@ type
|
|||||||
fGrid: TStringGrid;
|
fGrid: TStringGrid;
|
||||||
GridEndInd: Integer;
|
GridEndInd: Integer;
|
||||||
public
|
public
|
||||||
constructor Create(AStringsMap: TStringToStringTree; AGrid: TStringGrid);
|
constructor Create(AStringToStringMap: TStringToStringTree; AGrid: TStringGrid);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function AddUnique(AOldIdent: string): string;
|
function AddUnique(AOldIdent: string): string;
|
||||||
end;
|
end;
|
||||||
@ -198,18 +197,15 @@ end;
|
|||||||
|
|
||||||
{ TStringMapUpdater }
|
{ TStringMapUpdater }
|
||||||
|
|
||||||
constructor TStringMapUpdater.Create(AStringsMap: TStringToStringTree);
|
constructor TStringMapUpdater.Create(AStringToStringMap: TStringToStringTree);
|
||||||
begin
|
begin
|
||||||
fStringMap:=AStringsMap;
|
fStringToStringMap:=AStringToStringMap;
|
||||||
fMapNames:=TStringList.Create;
|
|
||||||
fStringMap.GetNames(fMapNames);
|
|
||||||
fSeenNames:=TStringList.Create;
|
fSeenNames:=TStringList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TStringMapUpdater.Destroy;
|
destructor TStringMapUpdater.Destroy;
|
||||||
begin
|
begin
|
||||||
fSeenNames.Free;
|
fSeenNames.Free;
|
||||||
fMapNames.Free;
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -218,31 +214,35 @@ function TStringMapUpdater.FindReplacement(AIdent: string;
|
|||||||
// Try to find a matching replacement using regular expression.
|
// Try to find a matching replacement using regular expression.
|
||||||
var
|
var
|
||||||
RE: TRegExpr;
|
RE: TRegExpr;
|
||||||
|
MapNames: TStringList; // Names (keys) in fStringToStringMap.
|
||||||
i: Integer;
|
i: Integer;
|
||||||
Key: string;
|
Key: string;
|
||||||
begin
|
begin
|
||||||
if fStringMap.Contains(AIdent) then begin
|
if fStringToStringMap.Contains(AIdent) then begin
|
||||||
AReplacement:=fStringMap[AIdent];
|
AReplacement:=fStringToStringMap[AIdent];
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end
|
end
|
||||||
else begin // Not found by name, try regexp.
|
else begin // Not found by name, try regexp.
|
||||||
Result:=false;
|
Result:=false;
|
||||||
AReplacement:='';
|
AReplacement:='';
|
||||||
RE:=TRegExpr.Create;
|
RE:=TRegExpr.Create;
|
||||||
|
MapNames:=TStringList.Create;
|
||||||
try
|
try
|
||||||
for i:=0 to fMapNames.Count-1 do begin
|
fStringToStringMap.GetNames(MapNames);
|
||||||
Key:=fMapNames[i]; // fMapNames has names extracted from fStringMap.
|
for i:=0 to MapNames.Count-1 do begin
|
||||||
|
Key:=MapNames[i]; // fMapNames has names extracted from fStringToStringMap.
|
||||||
// If key contains special chars, assume it is a regexp.
|
// If key contains special chars, assume it is a regexp.
|
||||||
if (Pos('(',Key)>0) or (Pos('*',Key)>0) or (Pos('+',Key)>0) then begin
|
if (Pos('(',Key)>0) or (Pos('*',Key)>0) or (Pos('+',Key)>0) then begin
|
||||||
RE.Expression:=Key;
|
RE.Expression:=Key;
|
||||||
if RE.Exec(AIdent) then begin // Match with regexp.
|
if RE.Exec(AIdent) then begin // Match with regexp.
|
||||||
AReplacement:=RE.Substitute(fStringMap[Key]);
|
AReplacement:=RE.Substitute(fStringToStringMap[Key]);
|
||||||
Result:=true;
|
Result:=true;
|
||||||
Break;
|
Break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
MapNames.Free;
|
||||||
RE.Free;
|
RE.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -251,9 +251,9 @@ end;
|
|||||||
|
|
||||||
{ TGridUpdater }
|
{ TGridUpdater }
|
||||||
|
|
||||||
constructor TGridUpdater.Create(AStringsMap: TStringToStringTree; AGrid: TStringGrid);
|
constructor TGridUpdater.Create(AStringToStringMap: TStringToStringTree; AGrid: TStringGrid);
|
||||||
begin
|
begin
|
||||||
inherited Create(AStringsMap);
|
inherited Create(AStringToStringMap);
|
||||||
fGrid:=AGrid;
|
fGrid:=AGrid;
|
||||||
GridEndInd:=1;
|
GridEndInd:=1;
|
||||||
end;
|
end;
|
||||||
@ -269,7 +269,7 @@ function TGridUpdater.AddUnique(AOldIdent: string): string;
|
|||||||
begin
|
begin
|
||||||
if fSeenNames.IndexOf(AOldIdent)<0 then begin
|
if fSeenNames.IndexOf(AOldIdent)<0 then begin
|
||||||
// Add only one instance of each name.
|
// Add only one instance of each name.
|
||||||
fSeenNames.Append(AOldIdent);
|
fSeenNames.Add(AOldIdent);
|
||||||
FindReplacement(AOldIdent, Result);
|
FindReplacement(AOldIdent, Result);
|
||||||
if fGrid.RowCount<GridEndInd+1 then
|
if fGrid.RowCount<GridEndInd+1 then
|
||||||
fGrid.RowCount:=GridEndInd+1;
|
fGrid.RowCount:=GridEndInd+1;
|
||||||
|
Loading…
Reference in New Issue
Block a user