From fd633ee9be8b7e22a2fcf3a4bfdc769c5d125c34 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 24 Jan 2009 11:16:20 +0000 Subject: [PATCH] codetools: skipping string constants in simple beautifier, bug #12681 git-svn-id: trunk@18405 - --- components/codetools/sourcechanger.pas | 32 +++++++++++++++++++++++++- components/sqldb/sqldblaz.pas | 6 ++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/components/codetools/sourcechanger.pas b/components/codetools/sourcechanger.pas index 4d4a704faa..aee2ad6cf1 100644 --- a/components/codetools/sourcechanger.pas +++ b/components/codetools/sourcechanger.pas @@ -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)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 diff --git a/components/sqldb/sqldblaz.pas b/components/sqldb/sqldblaz.pas index 33073773da..6adf407400 100644 --- a/components/sqldb/sqldblaz.pas +++ b/components/sqldb/sqldblaz.pas @@ -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