codetools: skipping string constants in simple beautifier, bug #12681

git-svn-id: trunk@18405 -
This commit is contained in:
mattias 2009-01-24 11:16:20 +00:00
parent a21dad9e56
commit fd633ee9be
2 changed files with 34 additions and 4 deletions

View File

@ -90,10 +90,14 @@ type
LastSrcLineStart: integer;// last line start, not added by splitting LastSrcLineStart: integer;// last line start, not added by splitting
CurAtomType, LastAtomType: TAtomType; CurAtomType, LastAtomType: TAtomType;
CurPos, AtomStart, AtomEnd, SrcLen, CurIndent, HiddenIndent: integer; CurPos, AtomStart, AtomEnd, SrcLen, CurIndent, HiddenIndent: integer;
CommentLvl: integer;
CommentStartPos: array of integer;
Src, UpperSrc: string; Src, UpperSrc: string;
procedure AddAtom(var CurCode: string; NewAtom: string); procedure AddAtom(var CurCode: string; NewAtom: string);
procedure ReadNextAtom; procedure ReadNextAtom;
procedure ReadTilDirectiveEnd; procedure ReadTilDirectiveEnd;
procedure StartComment(p: integer);
procedure EndComment(CommentStart: char; p: integer);
public public
LineLength: integer; LineLength: integer;
LineEnd: string; // default: #13#10 LineEnd: string; // default: #13#10
@ -1069,6 +1073,7 @@ begin
end; end;
#10,#13: // line break #10,#13: // line break
begin begin
EndComment('/',CurPos);
CurAtomType:=atNewLine; CurAtomType:=atNewLine;
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (IsLineEndChar[Src[CurPos]]) if (CurPos<=SrcLen) and (IsLineEndChar[Src[CurPos]])
@ -1109,7 +1114,7 @@ begin
end; end;
end; end;
'''','#': // string constant '''','#': // string constant
begin if CommentLvl=0 then begin
CurAtomType:=atStringConstant; CurAtomType:=atStringConstant;
while (CurPos<=SrcLen) do begin while (CurPos<=SrcLen) do begin
case (Src[CurPos]) of case (Src[CurPos]) of
@ -1132,6 +1137,10 @@ begin
break; break;
end; end;
end; end;
end else begin
// normal character
inc(CurPos);
CurAtomType:=atSymbol;
end; end;
'%': // binary number '%': // binary number
begin begin
@ -1149,6 +1158,7 @@ begin
end; end;
'{': // curly bracket comment or directive '{': // curly bracket comment or directive
begin begin
StartComment(CurPos);
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
inc(CurPos); inc(CurPos);
@ -1163,6 +1173,7 @@ begin
end; end;
'}': // curly bracket comment end '}': // curly bracket comment end
begin begin
EndComment('{',CurPos);
inc(CurPos); inc(CurPos);
CurAtomType:=atCommentEnd; CurAtomType:=atCommentEnd;
end; end;
@ -1170,6 +1181,7 @@ begin
begin begin
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos]='*') then begin if (CurPos<=SrcLen) and (Src[CurPos]='*') then begin
StartComment(CurPos-1);
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
inc(CurPos); inc(CurPos);
@ -1194,6 +1206,7 @@ begin
begin begin
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos]=')') then begin if (CurPos<=SrcLen) and (Src[CurPos]=')') then begin
EndComment('(',CurPos-1);
inc(CurPos); inc(CurPos);
CurAtomType:=atCommentEnd; CurAtomType:=atCommentEnd;
end else begin end else begin
@ -1204,6 +1217,7 @@ begin
begin begin
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos]='/') then begin if (CurPos<=SrcLen) and (Src[CurPos]='/') then begin
StartComment(CurPos-1);
inc(CurPos); inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
inc(CurPos); inc(CurPos);
@ -1267,6 +1281,21 @@ begin
until CurAtomType=atNone; until CurAtomType=atNone;
end; 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; function TBeautifyCodeOptions.BeautifyProc(const AProcCode: string;
IndentSize: integer; AddBeginEnd: boolean): string; IndentSize: integer; AddBeginEnd: boolean): string;
begin begin
@ -1325,6 +1354,7 @@ begin
LastSrcLineStart:=1; LastSrcLineStart:=1;
CurLineLen:=length(Result); CurLineLen:=length(Result);
LastAtomType:=atNone; LastAtomType:=atNone;
CommentLvl:=0;
// read atoms // read atoms
while (CurPos<=SrcLen) do begin while (CurPos<=SrcLen) do begin
repeat repeat

View File

@ -1,5 +1,5 @@
{ This file was automatically created by Lazarus. Do not edit! { This file was automatically created by Lazarus. do not edit!
This source is only used to compile and install the package. This source is only used to compile and install the package.
} }
unit SQLDBLaz; unit SQLDBLaz;
@ -7,7 +7,7 @@ unit SQLDBLaz;
interface interface
uses uses
registersqldb, sqldb, SQLStringsPropertyEditorDlg, LazarusPackageIntf; registersqldb, sqldb, SQLStringsPropertyEditorDlg, LazarusPackageIntf;
implementation implementation