mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 09:49:22 +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;
|
function ChangeLineEndings(const s, NewLineEnding: string): string;
|
||||||
var
|
var
|
||||||
NewLength: Integer;
|
NewLength: Integer;
|
||||||
p, StartPos: Integer;
|
p: Integer;
|
||||||
Src: PChar;
|
Src, Dest, StartPos, EndPos: PChar;
|
||||||
Dest: PChar;
|
|
||||||
EndLen: Integer;
|
EndLen: Integer;
|
||||||
EndPos: PChar;
|
|
||||||
begin
|
begin
|
||||||
if s='' then begin
|
if s='' then begin
|
||||||
Result:=s;
|
Result:=s;
|
||||||
@ -238,16 +236,28 @@ begin
|
|||||||
end;
|
end;
|
||||||
EndLen:=length(NewLineEnding);
|
EndLen:=length(NewLineEnding);
|
||||||
NewLength:=length(s);
|
NewLength:=length(s);
|
||||||
p:=1;
|
Src:=PChar(s);
|
||||||
while p<length(s) do begin
|
repeat
|
||||||
if s[p] in [#10,#13] then begin
|
case Src^ of
|
||||||
StartPos:=p;
|
#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);
|
inc(p);
|
||||||
if (s[p] in [#10,#13]) and (s[p]<>s[p-1]) then inc(p);
|
end;
|
||||||
inc(NewLength,EndLen-(p-StartPos));
|
until false;
|
||||||
end else
|
|
||||||
inc(p);
|
|
||||||
end;
|
|
||||||
SetLength(Result,NewLength);
|
SetLength(Result,NewLength);
|
||||||
Src:=PChar(s);
|
Src:=PChar(s);
|
||||||
Dest:=PChar(Result);
|
Dest:=PChar(Result);
|
||||||
|
@ -222,6 +222,13 @@ type
|
|||||||
function RemoveIdentifierDefinition(const CursorPos: TCodeXYPosition;
|
function RemoveIdentifierDefinition(const CursorPos: TCodeXYPosition;
|
||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
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)
|
// blocks (e.g. begin..end)
|
||||||
function FindBlockCounterPart(const CursorPos: TCodeXYPosition;
|
function FindBlockCounterPart(const CursorPos: TCodeXYPosition;
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
@ -4959,6 +4966,45 @@ begin
|
|||||||
end;
|
end;
|
||||||
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(
|
function TStandardCodeTool.FindBlockCounterPart(
|
||||||
const CursorPos: TCodeXYPosition;
|
const CursorPos: TCodeXYPosition;
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user