Browse Source

* Patch from Pascal Riekenberg to allow using BOM markers in source files (bug ID 34344)

git-svn-id: trunk@39832 -
michael 6 years ago
parent
commit
4bb4eb5cca
2 changed files with 14 additions and 0 deletions
  1. 7 0
      packages/fcl-passrc/src/pscanner.pp
  2. 7 0
      packages/fcl-passrc/tests/tcscanner.pas

+ 7 - 0
packages/fcl-passrc/src/pscanner.pp

@@ -4259,6 +4259,13 @@ begin
     FCurLine := CurSourceFile.ReadLine;
     FTokenStr := PChar(CurLine);
     Result := true;
+    if (FCurRow = 0)
+    and (Length(CurLine) >= 3)
+    and (FTokenStr[0] = #$EF)
+    and (FTokenStr[1] = #$BB)
+    and (FTokenStr[2] = #$BF) then
+      // ignore UTF-8 Byte Order Mark
+      inc(FTokenStr, 3);
     Inc(FCurRow);
     inc(FModuleRow);
     FCurColumnOffset:=1;

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

@@ -244,6 +244,7 @@ type
     procedure TestIfError;
     Procedure TestModeSwitch;
     Procedure TestOperatorIdentifier;
+    Procedure TestUTF8BOM;
   end;
 
 implementation
@@ -1744,6 +1745,12 @@ begin
   TestToken(tkidentifier,'operator',True);
 end;
 
+procedure TTestScanner.TestUTF8BOM;
+
+begin
+  DoTestToken(tkLineEnding,#$EF+#$BB+#$BF);
+end;
+
 initialization
   RegisterTests([TTestTokenFinder,TTestStreamLineReader,TTestScanner]);
 end.