mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 20:29:32 +02:00
* Fix lineending being converted to LF char in comments, patch by Joe Care (Bug ID 37808)
git-svn-id: trunk@46939 -
This commit is contained in:
parent
78dca42b0e
commit
409dacf52f
@ -4194,6 +4194,7 @@ var
|
||||
SectionLength, NestingLevel, Index: Integer;
|
||||
{$ifdef UsePChar}
|
||||
OldLength: integer;
|
||||
Ch: Char;
|
||||
{$else}
|
||||
s: string;
|
||||
l: integer;
|
||||
@ -4346,13 +4347,19 @@ begin
|
||||
begin
|
||||
SectionLength:=FTokenPos - TokenStart;
|
||||
{$ifdef UsePChar}
|
||||
SetLength(FCurTokenString, OldLength + SectionLength+1); // +1 for #10
|
||||
SetLength(FCurTokenString, OldLength + SectionLength + length(LineEnding)); // Corrected JC
|
||||
if SectionLength > 0 then
|
||||
Move(TokenStart^, FCurTokenString[OldLength + 1], SectionLength);
|
||||
Inc(OldLength, SectionLength+1);
|
||||
FCurTokenString[OldLength] := #10;
|
||||
Move(TokenStart^, FCurTokenString[OldLength + 1],SectionLength);
|
||||
|
||||
// Corrected JC: Append the correct lineending
|
||||
Inc(OldLength, SectionLength);
|
||||
for Ch in LineEnding do
|
||||
begin
|
||||
Inc(OldLength);
|
||||
FCurTokenString[OldLength] := Ch;
|
||||
end;
|
||||
{$else}
|
||||
FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+#10;
|
||||
FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+LineEnding; // Corrected JC
|
||||
{$endif}
|
||||
if not FetchLocalLine then
|
||||
begin
|
||||
@ -4656,13 +4663,19 @@ begin
|
||||
begin
|
||||
SectionLength := FTokenPos - TokenStart;
|
||||
{$ifdef UsePChar}
|
||||
SetLength(FCurTokenString, OldLength + SectionLength+1); // +1 for the #10
|
||||
SetLength(FCurTokenString, OldLength + SectionLength + length(LineEnding)); // Corrected JC
|
||||
if SectionLength > 0 then
|
||||
Move(TokenStart^, FCurTokenString[OldLength + 1],SectionLength);
|
||||
Inc(OldLength, SectionLength+1);
|
||||
FCurTokenString[OldLength] := #10;
|
||||
|
||||
// Corrected JC: Append the correct lineending
|
||||
Inc(OldLength, SectionLength);
|
||||
for Ch in LineEnding do
|
||||
begin
|
||||
Inc(OldLength);
|
||||
FCurTokenString[OldLength] := Ch;
|
||||
end;
|
||||
{$else}
|
||||
FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+#10;
|
||||
FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+LineEnding; // Corrected JC
|
||||
{$endif}
|
||||
if not FetchLocalLine then
|
||||
begin
|
||||
|
@ -80,6 +80,10 @@ type
|
||||
procedure TestComment3;
|
||||
procedure TestComment4;
|
||||
procedure TestComment5;
|
||||
procedure TestComment6;
|
||||
procedure TestComment7;
|
||||
procedure TestComment8;
|
||||
procedure TestComment9;
|
||||
procedure TestNestedComment1;
|
||||
procedure TestNestedComment2;
|
||||
procedure TestNestedComment3;
|
||||
@ -566,6 +570,34 @@ begin
|
||||
AssertEquals('Correct comment',' abc'+LineEnding+'def ',Scanner.CurTokenString);
|
||||
end;
|
||||
|
||||
procedure TTestScanner.TestComment6;
|
||||
|
||||
begin
|
||||
DoTestToken(tkComment,'{ abc }',False);
|
||||
AssertEquals('Correct comment',' abc ',Scanner.CurTokenString);
|
||||
end;
|
||||
|
||||
procedure TTestScanner.TestComment7;
|
||||
|
||||
begin
|
||||
DoTestToken(tkComment,'{ abc'+LineEnding+'def }',False);
|
||||
AssertEquals('Correct comment',' abc'+LineEnding+'def ',Scanner.CurTokenString);
|
||||
end;
|
||||
|
||||
procedure TTestScanner.TestComment8;
|
||||
|
||||
begin
|
||||
DoTestToken(tkComment,'// abc ',False);
|
||||
AssertEquals('Correct comment',' abc ',Scanner.CurTokenString);
|
||||
end;
|
||||
|
||||
procedure TTestScanner.TestComment9;
|
||||
|
||||
begin
|
||||
DoTestToken(tkComment,'// abc '+LineEnding,False);
|
||||
AssertEquals('Correct comment',' abc ',Scanner.CurTokenString);
|
||||
end;
|
||||
|
||||
procedure TTestScanner.TestNestedComment1;
|
||||
begin
|
||||
TestToken(tkComment,'// { comment } ');
|
||||
|
Loading…
Reference in New Issue
Block a user