mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 05:39:19 +02:00
* Patch from Anthony Walter to make IsValidIdent more strict in case of dotted identifiers (bug ID 29364)
git-svn-id: trunk@32920 -
This commit is contained in:
parent
9225ff3293
commit
8544b8a500
@ -706,34 +706,39 @@ 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; AllowDots : Boolean = False): boolean;
|
function IsValidIdent(const Ident: string; AllowDots: Boolean = False; StrictDots: Boolean = False): Boolean;
|
||||||
|
const
|
||||||
Const
|
|
||||||
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
||||||
AlphaNum = Alpha + ['0'..'9'];
|
AlphaNum = Alpha + ['0'..'9'];
|
||||||
AlphaDot = AlphaNum + ['.'];
|
Dot = '.';
|
||||||
|
var
|
||||||
var
|
First: Boolean;
|
||||||
i, len: integer;
|
I, Len: Integer;
|
||||||
allowed : Set of char;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Len:=Length(Ident);
|
Len := Length(Ident);
|
||||||
Result:=Len<>0;
|
if Len < 1 then
|
||||||
if Result then
|
Exit(False);
|
||||||
|
First := True;
|
||||||
|
for I := 1 to Len do
|
||||||
|
begin
|
||||||
|
if First then
|
||||||
begin
|
begin
|
||||||
result:=Ident[1] in Alpha;
|
Result := Ident[I] in Alpha;
|
||||||
if AllowDots then
|
First := False;
|
||||||
Allowed:=AlphaDot
|
end
|
||||||
else
|
else if AllowDots and (Ident[I] = Dot) then
|
||||||
Allowed:=AlphaNum;
|
begin
|
||||||
I:=2;
|
if StrictDots then
|
||||||
While Result and (I<=Len) do
|
|
||||||
begin
|
begin
|
||||||
Result:=Ident[i] in Allowed;
|
Result := I < Len;
|
||||||
Inc(I);
|
First := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
Result := Ident[I] in AlphaNum;
|
||||||
|
if not Result then
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ IntToStr returns a string representing the value of Value }
|
{ IntToStr returns a string representing the value of Value }
|
||||||
|
@ -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; AllowDots : Boolean = False): boolean;
|
function IsValidIdent(const Ident: string; AllowDots: Boolean = False; StrictDots: 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user