Browse Source

* Fix lineending being converted to LF char in comments, patch by Joe Care (Bug ID 37808)

git-svn-id: trunk@46939 -
michael 4 years ago
parent
commit
409dacf52f
2 changed files with 54 additions and 9 deletions
  1. 22 9
      packages/fcl-passrc/src/pscanner.pp
  2. 32 0
      packages/fcl-passrc/tests/tcscanner.pas

+ 22 - 9
packages/fcl-passrc/src/pscanner.pp

@@ -4194,6 +4194,7 @@ var
   SectionLength, NestingLevel, Index: Integer;
   SectionLength, NestingLevel, Index: Integer;
   {$ifdef UsePChar}
   {$ifdef UsePChar}
   OldLength: integer;
   OldLength: integer;
+  Ch: Char;
   {$else}
   {$else}
   s: string;
   s: string;
   l: integer;
   l: integer;
@@ -4346,13 +4347,19 @@ begin
             begin
             begin
             SectionLength:=FTokenPos - TokenStart;
             SectionLength:=FTokenPos - TokenStart;
             {$ifdef UsePChar}
             {$ifdef UsePChar}
-            SetLength(FCurTokenString, OldLength + SectionLength+1); // +1 for #10
+            SetLength(FCurTokenString, OldLength + SectionLength + length(LineEnding)); // Corrected JC
             if SectionLength > 0 then
             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}
             {$else}
-            FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+#10;
+            FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+LineEnding; // Corrected JC
             {$endif}
             {$endif}
             if not FetchLocalLine then
             if not FetchLocalLine then
               begin
               begin
@@ -4656,13 +4663,19 @@ begin
           begin
           begin
           SectionLength := FTokenPos - TokenStart;
           SectionLength := FTokenPos - TokenStart;
           {$ifdef UsePChar}
           {$ifdef UsePChar}
-          SetLength(FCurTokenString, OldLength + SectionLength+1); // +1 for the #10
+          SetLength(FCurTokenString, OldLength + SectionLength + length(LineEnding)); // Corrected JC
           if SectionLength > 0 then
           if SectionLength > 0 then
             Move(TokenStart^, FCurTokenString[OldLength + 1],SectionLength);
             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}
           {$else}
-          FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+#10;
+          FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+LineEnding; // Corrected JC
           {$endif}
           {$endif}
           if not FetchLocalLine then
           if not FetchLocalLine then
           begin
           begin

+ 32 - 0
packages/fcl-passrc/tests/tcscanner.pas

@@ -80,6 +80,10 @@ type
     procedure TestComment3;
     procedure TestComment3;
     procedure TestComment4;
     procedure TestComment4;
     procedure TestComment5;
     procedure TestComment5;
+    procedure TestComment6;
+    procedure TestComment7;
+    procedure TestComment8;
+    procedure TestComment9;
     procedure TestNestedComment1;
     procedure TestNestedComment1;
     procedure TestNestedComment2;
     procedure TestNestedComment2;
     procedure TestNestedComment3;
     procedure TestNestedComment3;
@@ -566,6 +570,34 @@ begin
   AssertEquals('Correct comment',' abc'+LineEnding+'def ',Scanner.CurTokenString);
   AssertEquals('Correct comment',' abc'+LineEnding+'def ',Scanner.CurTokenString);
 end;
 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;
 procedure TTestScanner.TestNestedComment1;
 begin
 begin
   TestToken(tkComment,'// { comment } ');
   TestToken(tkComment,'// { comment } ');