mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 07:02:44 +02:00
codetools: fixed ChangeLineEndings if #10 at end
git-svn-id: trunk@47831 -
This commit is contained in:
parent
7aa5c7eaed
commit
9a8ecaceff
@ -226,11 +226,9 @@ end;
|
||||
function ChangeLineEndings(const s, NewLineEnding: string): string;
|
||||
var
|
||||
NewLength: Integer;
|
||||
p, StartPos: Integer;
|
||||
Src: PChar;
|
||||
Dest: PChar;
|
||||
p: Integer;
|
||||
Src, Dest, StartPos, EndPos: PChar;
|
||||
EndLen: Integer;
|
||||
EndPos: PChar;
|
||||
begin
|
||||
if s='' then begin
|
||||
Result:=s;
|
||||
@ -238,16 +236,28 @@ begin
|
||||
end;
|
||||
EndLen:=length(NewLineEnding);
|
||||
NewLength:=length(s);
|
||||
p:=1;
|
||||
while p<length(s) do begin
|
||||
if s[p] in [#10,#13] then begin
|
||||
StartPos:=p;
|
||||
Src:=PChar(s);
|
||||
repeat
|
||||
case Src^ of
|
||||
#0:
|
||||
if Src-PChar(s)=length(s) then
|
||||
break
|
||||
else
|
||||
inc(Src);
|
||||
#10,#13:
|
||||
begin
|
||||
if (Src[1] in [#10,#13]) and (Src^<>Src[1]) then begin
|
||||
inc(Src,2);
|
||||
inc(NewLength,EndLen-2);
|
||||
end else begin
|
||||
inc(Src);
|
||||
inc(NewLength,EndLen-1);
|
||||
end;
|
||||
end;
|
||||
else
|
||||
inc(p);
|
||||
if (s[p] in [#10,#13]) and (s[p]<>s[p-1]) then inc(p);
|
||||
inc(NewLength,EndLen-(p-StartPos));
|
||||
end else
|
||||
inc(p);
|
||||
end;
|
||||
end;
|
||||
until false;
|
||||
SetLength(Result,NewLength);
|
||||
Src:=PChar(s);
|
||||
Dest:=PChar(Result);
|
||||
|
@ -222,6 +222,13 @@ type
|
||||
function RemoveIdentifierDefinition(const CursorPos: TCodeXYPosition;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
function InsertStatements(const CursorPos: TCodeXYPosition;
|
||||
Statements: string; FrontGap, AfterGap: TGapTyp;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
function InsertStatements(CleanPos: integer;
|
||||
Statements: string; FrontGap, AfterGap: TGapTyp;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// blocks (e.g. begin..end)
|
||||
function FindBlockCounterPart(const CursorPos: TCodeXYPosition;
|
||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||
@ -4959,6 +4966,45 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.InsertStatements(const CursorPos: TCodeXYPosition;
|
||||
Statements: string; FrontGap, AfterGap: TGapTyp;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
var
|
||||
CleanCursorPos: integer;
|
||||
begin
|
||||
BeginParsingAndGetCleanPos(lsrEnd,CursorPos,CleanCursorPos);
|
||||
Result:=InsertStatements(CleanCursorPos,Statements,FrontGap,AfterGap,
|
||||
SourceChangeCache);
|
||||
Result:=SourceChangeCache.Apply;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.InsertStatements(CleanPos: integer;
|
||||
Statements: string; FrontGap, AfterGap: TGapTyp;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
{
|
||||
ToDo: check for "uses" in Statements and extend uses section
|
||||
e.g. "uses unit1, unit2 in 'filename'; statements
|
||||
ToDo: check for single statement (e.g. for .. do | dosome;) and add begin/end
|
||||
|
||||
}
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
Node:=FindDeepestNodeAtPos(CleanPos,true);
|
||||
if not (Node.Desc in AllPascalStatements) then begin
|
||||
MoveCursorToCleanPos(CleanPos);
|
||||
RaiseException('invalid position for insertion');
|
||||
end;
|
||||
if Node.Desc=ctnBeginBlock then
|
||||
Node:=BuildSubTreeAndFindDeepestNodeAtPos(Node,CleanPos,true);
|
||||
|
||||
// ToDo: check for CleanPos
|
||||
|
||||
|
||||
SourceChangeCache.MainScanner:=Scanner;
|
||||
Result:=SourceChangeCache.Replace(FrontGap,AfterGap,CleanPos,CleanPos,Statements);
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.FindBlockCounterPart(
|
||||
const CursorPos: TCodeXYPosition;
|
||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user