mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-05 14:18:18 +02:00
codetools: skipping string constants in simple beautifier, bug #12681
git-svn-id: trunk@18405 -
This commit is contained in:
parent
a21dad9e56
commit
fd633ee9be
@ -90,10 +90,14 @@ type
|
||||
LastSrcLineStart: integer;// last line start, not added by splitting
|
||||
CurAtomType, LastAtomType: TAtomType;
|
||||
CurPos, AtomStart, AtomEnd, SrcLen, CurIndent, HiddenIndent: integer;
|
||||
CommentLvl: integer;
|
||||
CommentStartPos: array of integer;
|
||||
Src, UpperSrc: string;
|
||||
procedure AddAtom(var CurCode: string; NewAtom: string);
|
||||
procedure ReadNextAtom;
|
||||
procedure ReadTilDirectiveEnd;
|
||||
procedure StartComment(p: integer);
|
||||
procedure EndComment(CommentStart: char; p: integer);
|
||||
public
|
||||
LineLength: integer;
|
||||
LineEnd: string; // default: #13#10
|
||||
@ -1069,6 +1073,7 @@ begin
|
||||
end;
|
||||
#10,#13: // line break
|
||||
begin
|
||||
EndComment('/',CurPos);
|
||||
CurAtomType:=atNewLine;
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (IsLineEndChar[Src[CurPos]])
|
||||
@ -1109,7 +1114,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
'''','#': // string constant
|
||||
begin
|
||||
if CommentLvl=0 then begin
|
||||
CurAtomType:=atStringConstant;
|
||||
while (CurPos<=SrcLen) do begin
|
||||
case (Src[CurPos]) of
|
||||
@ -1132,6 +1137,10 @@ begin
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end else begin
|
||||
// normal character
|
||||
inc(CurPos);
|
||||
CurAtomType:=atSymbol;
|
||||
end;
|
||||
'%': // binary number
|
||||
begin
|
||||
@ -1149,6 +1158,7 @@ begin
|
||||
end;
|
||||
'{': // curly bracket comment or directive
|
||||
begin
|
||||
StartComment(CurPos);
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
|
||||
inc(CurPos);
|
||||
@ -1163,6 +1173,7 @@ begin
|
||||
end;
|
||||
'}': // curly bracket comment end
|
||||
begin
|
||||
EndComment('{',CurPos);
|
||||
inc(CurPos);
|
||||
CurAtomType:=atCommentEnd;
|
||||
end;
|
||||
@ -1170,6 +1181,7 @@ begin
|
||||
begin
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (Src[CurPos]='*') then begin
|
||||
StartComment(CurPos-1);
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
|
||||
inc(CurPos);
|
||||
@ -1194,6 +1206,7 @@ begin
|
||||
begin
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (Src[CurPos]=')') then begin
|
||||
EndComment('(',CurPos-1);
|
||||
inc(CurPos);
|
||||
CurAtomType:=atCommentEnd;
|
||||
end else begin
|
||||
@ -1204,6 +1217,7 @@ begin
|
||||
begin
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (Src[CurPos]='/') then begin
|
||||
StartComment(CurPos-1);
|
||||
inc(CurPos);
|
||||
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
|
||||
inc(CurPos);
|
||||
@ -1267,6 +1281,21 @@ begin
|
||||
until CurAtomType=atNone;
|
||||
end;
|
||||
|
||||
procedure TBeautifyCodeOptions.StartComment(p: integer);
|
||||
begin
|
||||
inc(CommentLvl);
|
||||
if length(CommentStartPos)<CommentLvl then
|
||||
SetLength(CommentStartPos,length(CommentStartPos)*2+10);
|
||||
CommentStartPos[CommentLvl-1]:=p;
|
||||
end;
|
||||
|
||||
procedure TBeautifyCodeOptions.EndComment(CommentStart: char; p: integer);
|
||||
begin
|
||||
if (CommentLvl>0)
|
||||
and (Src[CommentStartPos[CommentLvl-1]]=CommentStart) then
|
||||
dec(CommentLvl);
|
||||
end;
|
||||
|
||||
function TBeautifyCodeOptions.BeautifyProc(const AProcCode: string;
|
||||
IndentSize: integer; AddBeginEnd: boolean): string;
|
||||
begin
|
||||
@ -1325,6 +1354,7 @@ begin
|
||||
LastSrcLineStart:=1;
|
||||
CurLineLen:=length(Result);
|
||||
LastAtomType:=atNone;
|
||||
CommentLvl:=0;
|
||||
// read atoms
|
||||
while (CurPos<=SrcLen) do begin
|
||||
repeat
|
||||
|
@ -1,5 +1,5 @@
|
||||
{ This file was automatically created by Lazarus. Do not edit!
|
||||
This source is only used to compile and install the package.
|
||||
{ This file was automatically created by Lazarus. do not edit!
|
||||
This source is only used to compile and install the package.
|
||||
}
|
||||
|
||||
unit SQLDBLaz;
|
||||
@ -7,7 +7,7 @@ unit SQLDBLaz;
|
||||
interface
|
||||
|
||||
uses
|
||||
registersqldb, sqldb, SQLStringsPropertyEditorDlg, LazarusPackageIntf;
|
||||
registersqldb, sqldb, SQLStringsPropertyEditorDlg, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user