mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 10:16:17 +02:00
LazUtils: Move function LazIsValidIdent from PackageDependencyIntf (IdeIntf) to LazStringUtils.
git-svn-id: trunk@62133 -
This commit is contained in:
parent
9e4c5d207e
commit
490804cee4
@ -7,7 +7,7 @@ interface
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
// LazUtils
|
||||
LazFileUtils;
|
||||
LazFileUtils, LazStringUtils;
|
||||
|
||||
type
|
||||
|
||||
@ -99,8 +99,6 @@ type
|
||||
property Removed: boolean read FRemoved write FRemoved;
|
||||
end;
|
||||
|
||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||
StrictDots: Boolean = False): Boolean;
|
||||
function IsValidUnitName(AUnitName: String): Boolean; inline;
|
||||
function IsValidPkgName(APkgName: String): Boolean; inline;
|
||||
function PackageFileNameIsValid(const AFilename: string): boolean;
|
||||
@ -108,44 +106,6 @@ function PackageFileNameIsValid(const AFilename: string): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||
StrictDots: Boolean = False): Boolean;
|
||||
// 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.
|
||||
const
|
||||
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
||||
AlphaNum = Alpha + ['0'..'9'];
|
||||
Dot = '.';
|
||||
var
|
||||
First: Boolean;
|
||||
I, Len: Integer;
|
||||
begin
|
||||
Len := Length(Ident);
|
||||
if Len < 1 then
|
||||
Exit(False);
|
||||
First := True;
|
||||
for I := 1 to Len do
|
||||
begin
|
||||
if First then
|
||||
begin
|
||||
Result := Ident[I] in Alpha;
|
||||
First := False;
|
||||
end
|
||||
else if AllowDots and (Ident[I] = Dot) then
|
||||
begin
|
||||
if StrictDots then
|
||||
begin
|
||||
Result := I < Len;
|
||||
First := True;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Result := Ident[I] in AlphaNum;
|
||||
if not Result then
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
function IsValidUnitName(AUnitName: String): Boolean;
|
||||
begin
|
||||
Result := LazIsValidIdent(AUnitName, True, True);
|
||||
|
@ -31,10 +31,10 @@ uses
|
||||
// LazControls
|
||||
{$IFnDEF UseOINormalCheckBox} CheckBoxThemed, {$ENDIF}
|
||||
// LazUtils
|
||||
FileUtil, StringHashList, LazMethodList, LazLoggerBase, LazUtilities, UITypes,
|
||||
FPCAdds, // for StrToQWord in older fpc versions
|
||||
FileUtil, StringHashList, LazMethodList, LazLoggerBase, LazUtilities, LazStringUtils,
|
||||
UITypes, FPCAdds, // for StrToQWord in older fpc versions
|
||||
// IdeIntf
|
||||
ObjInspStrConsts, PropEditUtils, PackageDependencyIntf,
|
||||
ObjInspStrConsts, PropEditUtils,
|
||||
// Forms with .lfm files
|
||||
FrmSelectProps, StringsPropEditDlg, KeyValPropEditDlg, CollectionPropEditForm,
|
||||
FileFilterPropEditor, PagesPropEditDlg, IDEWindowIntf;
|
||||
|
@ -93,6 +93,10 @@ function SwapCase(Const S: String): String;
|
||||
function StringCase(const AString: String; const ACase: array of String {; const AIgnoreCase = False, APartial = false: Boolean}): Integer; overload;
|
||||
function StringCase(const AString: String; const ACase: array of String; const AIgnoreCase, APartial: Boolean): Integer; overload;
|
||||
|
||||
// Test over a string
|
||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||
StrictDots: Boolean = False): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function IsNumber(s: String): Boolean;
|
||||
@ -1234,5 +1238,43 @@ begin
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||
StrictDots: Boolean = False): Boolean;
|
||||
// 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.
|
||||
const
|
||||
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
||||
AlphaNum = Alpha + ['0'..'9'];
|
||||
Dot = '.';
|
||||
var
|
||||
First: Boolean;
|
||||
I, Len: Integer;
|
||||
begin
|
||||
Len := Length(Ident);
|
||||
if Len < 1 then
|
||||
Exit(False);
|
||||
First := True;
|
||||
for I := 1 to Len do
|
||||
begin
|
||||
if First then
|
||||
begin
|
||||
Result := Ident[I] in Alpha;
|
||||
First := False;
|
||||
end
|
||||
else if AllowDots and (Ident[I] = Dot) then
|
||||
begin
|
||||
if StrictDots then
|
||||
begin
|
||||
Result := I < Len;
|
||||
First := True;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Result := Ident[I] in AlphaNum;
|
||||
if not Result then
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -69,7 +69,7 @@ uses
|
||||
// Codetools
|
||||
CodeCache, CodeToolManager, BasicCodeTools, FileProcs,
|
||||
// IDEIntf
|
||||
LazIDEIntf, IDEImagesIntf, PackageIntf, ProjectIntf, PackageDependencyIntf,
|
||||
LazIDEIntf, IDEImagesIntf, PackageIntf, ProjectIntf,
|
||||
// ToDoList
|
||||
ToDoListStrConsts;
|
||||
|
||||
|
@ -1763,8 +1763,7 @@ function AddUnitToProject(const AEditor: TSourceEditorInterface): TModalResult;
|
||||
var
|
||||
ActiveSourceEditor: TSourceEditor;
|
||||
ActiveUnitInfo: TUnitInfo;
|
||||
s, ShortUnitName, LFMFilename, LFMType, LFMComponentName,
|
||||
LFMClassName: string;
|
||||
s, ShortUnitName, LFMFilename, LFMType, LFMComponentName, LFMClassName: string;
|
||||
OkToAdd: boolean;
|
||||
Owners: TFPList;
|
||||
i: Integer;
|
||||
@ -1840,7 +1839,7 @@ begin
|
||||
Result:=RenameUnitLowerCase(ActiveUnitInfo,true);
|
||||
if Result=mrIgnore then Result:=mrOk;
|
||||
if Result<>mrOk then begin
|
||||
DebugLn('AddActiveUnitToProject A RenameUnitLowerCase failed ',ActiveUnitInfo.Filename);
|
||||
DebugLn('AddUnitToProject A RenameUnitLowerCase failed ',ActiveUnitInfo.Filename);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
@ -7994,8 +7993,7 @@ begin
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
if not CodeToolBoss.RenameIdentifier(PascalReferences,
|
||||
OldUnitName,NewUnitName)
|
||||
if not CodeToolBoss.RenameIdentifier(PascalReferences,OldUnitName,NewUnitName)
|
||||
then begin
|
||||
if (not IgnoreErrors) and (not Quiet) then
|
||||
MainIDE.DoJumpToCodeToolBossError;
|
||||
|
Loading…
Reference in New Issue
Block a user