mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 23:49:28 +02:00
LazUtils: Check for Pascal keywords in LazIsValidIdent. Must be prepended with '&'. Merge request 11 by Abdullahi Usman.
This commit is contained in:
parent
0b817c8df3
commit
5a1abf733a
@ -16,7 +16,7 @@ unit LazStringUtils;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils, PascodeGen,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazUTF8, LazLoggerBase, LazTracer;
|
LazUTF8, LazLoggerBase, LazTracer;
|
||||||
|
|
||||||
@ -1415,27 +1415,30 @@ end;
|
|||||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||||
StrictDots: Boolean = False): Boolean;
|
StrictDots: Boolean = False): Boolean;
|
||||||
// This is a copy of IsValidIdent from FPC 3.1.
|
// This is a copy of IsValidIdent from FPC 3.1.
|
||||||
// ToDo: Switch to using IsValidIdent from FPC 3.2 when it is the minimum requirement.
|
// Later modified to check for Pascal keywords. They must be prepended with '&'.
|
||||||
const
|
const
|
||||||
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
||||||
AlphaNum = Alpha + ['0'..'9'];
|
AlphaNum = Alpha + ['0'..'9'];
|
||||||
Dot = '.';
|
|
||||||
var
|
var
|
||||||
First: Boolean;
|
First: Boolean;
|
||||||
I, Len: Integer;
|
I, Len, Poz: Integer;
|
||||||
begin
|
begin
|
||||||
Len := Length(Ident);
|
Len := Length(Ident);
|
||||||
if Len < 1 then
|
if (Len < 1) or (TPascalCodeGenerator(nil).IsKeyWord(Ident)) then
|
||||||
Exit(False);
|
Exit(False);
|
||||||
First := True;
|
First := True;
|
||||||
for I := 1 to Len do
|
if Ident[1] = '&' then
|
||||||
|
Poz := 2
|
||||||
|
else
|
||||||
|
Poz := 1;
|
||||||
|
for I := Poz to Len do
|
||||||
begin
|
begin
|
||||||
if First then
|
if First then
|
||||||
begin
|
begin
|
||||||
Result := Ident[I] in Alpha;
|
Result := Ident[I] in Alpha;
|
||||||
First := False;
|
First := False;
|
||||||
end
|
end
|
||||||
else if AllowDots and (Ident[I] = Dot) then
|
else if AllowDots and (Ident[I] = '.') then
|
||||||
begin
|
begin
|
||||||
if StrictDots then
|
if StrictDots then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user