浏览代码

* Fix bug #29273 (extra argument for IsValidIdent)

git-svn-id: trunk@32791 -
michael 9 年之前
父节点
当前提交
67d0cd1770
共有 2 个文件被更改,包括 30 次插入15 次删除
  1. 29 14
      rtl/objpas/sysutils/sysstr.inc
  2. 1 1
      rtl/objpas/sysutils/sysstrh.inc

+ 29 - 14
rtl/objpas/sysutils/sysstr.inc

@@ -706,20 +706,35 @@ end;
     'A' to 'Z', 'a' to 'z' or '_' and the following characters are
     'A' to 'Z', 'a' to 'z' or '_' and the following characters are
     on of: 'A' to 'Z', 'a' to 'z', '0'..'9' or '_'    }
     on of: 'A' to 'Z', 'a' to 'z', '0'..'9' or '_'    }
 
 
-function IsValidIdent(const Ident: string): boolean;
-var i, len: integer;
-begin
-result := false;
-len := length(Ident);
-if len <> 0 then begin
-   result := Ident[1] in ['A'..'Z', 'a'..'z', '_'];
-   i := 1;
-   while (result) and (i < len) do begin
-      i := i + 1;
-      result := result and (Ident[i] in ['A'..'Z', 'a'..'z', '0'..'9', '_']);
-      end ;
-   end ;
-end ;
+function IsValidIdent(const Ident: string; AllowDots : Boolean = False): boolean;
+
+Const
+  Alpha = ['A'..'Z', 'a'..'z', '_'];
+  AlphaNum = Alpha + ['0'..'9'];
+  AlphaDot = AlphaNum + ['.'];
+  
+var 
+  i, len: integer;
+  allowed : Set of char;
+  
+begin
+  Len:=Length(Ident);
+  Result:=Len<>0;
+  if Result then 
+    begin
+    result:=Ident[1] in Alpha;
+    if AllowDots then
+      Allowed:=AlphaDot
+    else
+      Allowed:=AlphaNum;
+    I:=2;  
+    While Result and (I<=Len) do
+      begin
+      Result:=Ident[i] in Allowed;
+      Inc(I);
+      end;
+   end;
+end;
 
 
 {   IntToStr returns a string representing the value of Value    }
 {   IntToStr returns a string representing the value of Value    }
 
 

+ 1 - 1
rtl/objpas/sysutils/sysstrh.inc

@@ -103,7 +103,7 @@ function AnsiDequotedStr(const S: string; AQuote: Char): string;
 function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
 function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
 function AdjustLineBreaks(const S: string): string;
 function AdjustLineBreaks(const S: string): string;
 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;
 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;
-function IsValidIdent(const Ident: string): boolean;
+function IsValidIdent(const Ident: string; AllowDots : Boolean = False): boolean;
 function IntToStr(Value: Longint): string;
 function IntToStr(Value: Longint): string;
 function IntToStr(Value: Int64): string;
 function IntToStr(Value: Int64): string;
 function IntToStr(Value: QWord): string;
 function IntToStr(Value: QWord): string;