mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 15:39:18 +02:00
codetools: CleanCodeFromComments added parameter KeepDirectives
git-svn-id: branches/fixes_1_6@51270 -
This commit is contained in:
parent
e92baf1992
commit
06fe3f3117
@ -69,8 +69,8 @@ function FindNextIncludeDirective(const ASource: string;
|
|||||||
CommentStartPos, CommentEndPos: integer): integer;
|
CommentStartPos, CommentEndPos: integer): integer;
|
||||||
function FindNextIDEDirective(const ASource: string; StartPos: integer;
|
function FindNextIDEDirective(const ASource: string; StartPos: integer;
|
||||||
NestedComments: boolean; EndPos: integer = 0): integer;
|
NestedComments: boolean; EndPos: integer = 0): integer;
|
||||||
function CleanCodeFromComments(const DirtyCode: string;
|
function CleanCodeFromComments(const Src: string;
|
||||||
NestedComments: boolean): string;
|
NestedComments: boolean; KeepDirectives: boolean = false): string;
|
||||||
function ExtractCommentContent(const ASource: string; CommentStart: integer;
|
function ExtractCommentContent(const ASource: string; CommentStart: integer;
|
||||||
NestedComments: boolean;
|
NestedComments: boolean;
|
||||||
TrimStart: boolean = false; TrimEnd: boolean = false;
|
TrimStart: boolean = false; TrimEnd: boolean = false;
|
||||||
@ -3990,27 +3990,36 @@ begin
|
|||||||
Result:=-1;
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CleanCodeFromComments(const DirtyCode: string;
|
function CleanCodeFromComments(const Src: string;
|
||||||
NestedComments: boolean): string;
|
NestedComments: boolean; KeepDirectives: boolean): string;
|
||||||
var
|
var
|
||||||
DirtyPos: Integer;
|
SrcPos: Integer;
|
||||||
CleanPos: Integer;
|
ResultPos: Integer;
|
||||||
StartPos: Integer;
|
StartPos: Integer;
|
||||||
l: Integer;
|
l: Integer;
|
||||||
|
p: PChar;
|
||||||
begin
|
begin
|
||||||
SetLength(Result,length(DirtyCode));
|
SetLength(Result,length(Src));
|
||||||
DirtyPos:=1;
|
SrcPos:=1;
|
||||||
CleanPos:=1;
|
ResultPos:=1;
|
||||||
while DirtyPos<=length(DirtyCode) do begin
|
while SrcPos<=length(Src) do begin
|
||||||
StartPos:=FindNextComment(DirtyCode,DirtyPos);
|
StartPos:=FindNextComment(Src,SrcPos);
|
||||||
l:=StartPos-DirtyPos;
|
l:=StartPos-SrcPos;
|
||||||
if l>0 then begin
|
if (l>0) then begin
|
||||||
System.Move(DirtyCode[DirtyPos],Result[CleanPos],l);
|
System.Move(Src[SrcPos],Result[ResultPos],l);
|
||||||
inc(CleanPos,l);
|
inc(ResultPos,l);
|
||||||
end;
|
end;
|
||||||
DirtyPos:=FindCommentEnd(DirtyCode,StartPos,NestedComments);
|
SrcPos:=FindCommentEnd(Src,StartPos,NestedComments);
|
||||||
|
if KeepDirectives and (StartPos<=length(Src)) then begin
|
||||||
|
p:=@Src[StartPos];
|
||||||
|
if (p^='{') and (p[1]='$') then begin
|
||||||
|
l:=SrcPos-StartPos;
|
||||||
|
System.Move(Src[StartPos],Result[ResultPos],l);
|
||||||
|
inc(ResultPos,l);
|
||||||
end;
|
end;
|
||||||
SetLength(Result,CleanPos-1);
|
end;
|
||||||
|
end;
|
||||||
|
SetLength(Result,ResultPos-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExtractCommentContent(const ASource: string; CommentStart: integer;
|
function ExtractCommentContent(const ASource: string; CommentStart: integer;
|
||||||
|
@ -405,7 +405,8 @@ type
|
|||||||
|
|
||||||
// keywords and comments
|
// keywords and comments
|
||||||
function IsKeyword(Code: TCodeBuffer; const KeyWord: string): boolean;
|
function IsKeyword(Code: TCodeBuffer; const KeyWord: string): boolean;
|
||||||
function ExtractCodeWithoutComments(Code: TCodeBuffer): string;
|
function ExtractCodeWithoutComments(Code: TCodeBuffer;
|
||||||
|
KeepDirectives: boolean = false): string;
|
||||||
function GetPasDocComments(Code: TCodeBuffer; X, Y: integer;
|
function GetPasDocComments(Code: TCodeBuffer; X, Y: integer;
|
||||||
out ListOfPCodeXYPosition: TFPList): boolean;
|
out ListOfPCodeXYPosition: TFPList): boolean;
|
||||||
|
|
||||||
@ -3447,10 +3448,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.ExtractCodeWithoutComments(Code: TCodeBuffer): string;
|
function TCodeToolManager.ExtractCodeWithoutComments(Code: TCodeBuffer;
|
||||||
|
KeepDirectives: boolean): string;
|
||||||
begin
|
begin
|
||||||
Result:=CleanCodeFromComments(Code.Source,
|
Result:=CleanCodeFromComments(Code.Source,
|
||||||
GetNestedCommentsFlagForFile(Code.Filename));
|
GetNestedCommentsFlagForFile(Code.Filename),KeepDirectives);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.GetPasDocComments(Code: TCodeBuffer; X, Y: integer;
|
function TCodeToolManager.GetPasDocComments(Code: TCodeBuffer; X, Y: integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user