From 490804cee40c1029881f3733a8ce44977c7382ab Mon Sep 17 00:00:00 2001 From: juha Date: Sun, 27 Oct 2019 15:46:04 +0000 Subject: [PATCH] LazUtils: Move function LazIsValidIdent from PackageDependencyIntf (IdeIntf) to LazStringUtils. git-svn-id: trunk@62133 - --- components/ideintf/packagedependencyintf.pas | 42 +------------------- components/ideintf/propedits.pp | 6 +-- components/lazutils/lazstringutils.pas | 42 ++++++++++++++++++++ components/todolist/todolist.pas | 2 +- ide/sourcefilemanager.pas | 8 ++-- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/components/ideintf/packagedependencyintf.pas b/components/ideintf/packagedependencyintf.pas index c66124ed6d..cf8dcef7d3 100644 --- a/components/ideintf/packagedependencyintf.pas +++ b/components/ideintf/packagedependencyintf.pas @@ -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); diff --git a/components/ideintf/propedits.pp b/components/ideintf/propedits.pp index aa0837690b..ba5ab230fe 100644 --- a/components/ideintf/propedits.pp +++ b/components/ideintf/propedits.pp @@ -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; diff --git a/components/lazutils/lazstringutils.pas b/components/lazutils/lazstringutils.pas index 948d5073ad..a6e831f0ea 100644 --- a/components/lazutils/lazstringutils.pas +++ b/components/lazutils/lazstringutils.pas @@ -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. diff --git a/components/todolist/todolist.pas b/components/todolist/todolist.pas index f9ece943c3..dfbe0b977e 100644 --- a/components/todolist/todolist.pas +++ b/components/todolist/todolist.pas @@ -69,7 +69,7 @@ uses // Codetools CodeCache, CodeToolManager, BasicCodeTools, FileProcs, // IDEIntf - LazIDEIntf, IDEImagesIntf, PackageIntf, ProjectIntf, PackageDependencyIntf, + LazIDEIntf, IDEImagesIntf, PackageIntf, ProjectIntf, // ToDoList ToDoListStrConsts; diff --git a/ide/sourcefilemanager.pas b/ide/sourcefilemanager.pas index 9ded43bb4f..96b499ed66 100644 --- a/ide/sourcefilemanager.pas +++ b/ide/sourcefilemanager.pas @@ -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;