فهرست منبع

* Skip UTF-8 BOM in TParser (classes) and dfmreader (fcl-res)

git-svn-id: trunk@14292 -
giulio2 15 سال پیش
والد
کامیت
d257b19798
3فایلهای تغییر یافته به همراه24 افزوده شده و 0 حذف شده
  1. 3 0
      packages/fcl-res/src/dfmreader.pp
  2. 1 0
      rtl/objpas/classes/classesh.inc
  3. 20 0
      rtl/objpas/classes/parser.inc

+ 3 - 0
packages/fcl-res/src/dfmreader.pp

@@ -131,6 +131,9 @@ begin
   fLine:='';
   while fLine='' do
     ReadLine(aStream);
+  //skip UTF-8 BOM, if needed
+  if (copy(fLine,1,3)=(#$EF+#$BB+#$BF)) then
+    inc(fLinePos,3);
   tmp:=lowercase(GetIdent);
   if (tmp <> 'object') and (tmp<>'inherited') then exit;
   if GetIdent='' then exit;

+ 1 - 0
rtl/objpas/classes/classesh.inc

@@ -1414,6 +1414,7 @@ type
     function GetHexValue(c : char) : byte; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
     function GetAlphaNum : string;
     procedure HandleNewLine;
+    procedure SkipBOM;
     procedure SkipSpaces;
     procedure SkipWhitespace;
     procedure HandleEof;

+ 20 - 0
rtl/objpas/classes/parser.inc

@@ -119,6 +119,25 @@ begin
   fDeltaPos:=-(fPos-1);
 end;
 
+procedure TParser.SkipBOM;
+var
+  i : integer;
+  bom : string[3];
+  backup : integer;
+begin
+  i:=1;
+  bom:='   ';
+  backup:=fPos;
+  while (fBuf[fPos] in [#$BB,#$BF,#$EF]) and (i<=3) do
+  begin
+    bom[i]:=fBuf[fPos];
+    inc(fPos);
+    inc(i);
+  end;
+  if (bom<>(#$EF+#$BB+#$BF)) then
+    fPos:=backup;
+end;
+
 procedure TParser.SkipSpaces;
 begin
   while fBuf[fPos] in [' ',#9] do
@@ -304,6 +323,7 @@ begin
   fFloatType:=#0;
   fToken:=#0;
   LoadBuffer;
+  SkipBom;
   NextToken;
 end;