LazUtils: Replace TMask with a faster and better version from José Mejuto.

git-svn-id: trunk@64667 -
This commit is contained in:
juha 2021-02-26 16:17:16 +00:00
parent b8a5b2df73
commit d82f15fb2b
5 changed files with 961 additions and 483 deletions

View File

@ -795,12 +795,8 @@ var
// Deal with both files and directories // Deal with both files and directories
if (PathInfo.Attr and faDirectory) = 0 then if (PathInfo.Attr and faDirectory) = 0 then
begin // File begin // File
{$IFDEF Windows} if (MaskList = nil) or MaskList.Matches(PathInfo.Name) then
if (MaskList = nil) or MaskList.MatchesWindowsMask(PathInfo.Name) begin
{$ELSE}
if (MaskList = nil) or MaskList.Matches(PathInfo.Name)
{$ENDIF}
then begin
FPath := APath; FPath := APath;
FLevel := ALevel; FLevel := ALevel;
FFileInfo := PathInfo; FFileInfo := PathInfo;
@ -848,14 +844,9 @@ var
i: Integer; i: Integer;
Dir: String; Dir: String;
OtherDir: String; OtherDir: String;
MaskOptions: TMaskOptions;
begin begin
if FSearching then RaiseSearchingError; if FSearching then RaiseSearchingError;
if CaseSensitive then MaskList := TMaskList.CreateSysNative(ASearchMask, FMaskSeparator, CaseSensitive);
MaskOptions := [moCaseSensitive]
else
MaskOptions := [];
MaskList := TMaskList.Create(ASearchMask, FMaskSeparator, MaskOptions);
// empty mask = all files mask // empty mask = all files mask
if MaskList.Count = 0 then if MaskList.Count = 0 then
FreeAndNil(MaskList); FreeAndNil(MaskList);
@ -901,7 +892,7 @@ begin
finally finally
SearchDirectories.Free; SearchDirectories.Free;
FSearching := False; FSearching := False;
if MaskList <> nil then MaskList.Free; MaskList.Free;
end; end;
end; end;

View File

@ -16,7 +16,6 @@ interface
resourceString resourceString
lrsModified = ' modified '; lrsModified = ' modified ';
lrsInvalidCharSet = 'The char set in mask "%s" is not valid!';
lrsSize = ' size '; lrsSize = ' size ';
lrsFileDoesNotExist = 'file "%s" does not exist'; lrsFileDoesNotExist = 'file "%s" does not exist';
lrsFileIsADirectoryAndNotAnExecutable = 'file "%s" is a directory and not an' lrsFileIsADirectoryAndNotAnExecutable = 'file "%s" is a directory and not an'
@ -42,6 +41,15 @@ resourceString
lrsERRORInCode = 'ERROR in code: '; lrsERRORInCode = 'ERROR in code: ';
lrsCreatingGdbCatchableError = 'Creating gdb catchable error:'; lrsCreatingGdbCatchableError = 'Creating gdb catchable error:';
// Masks
rsInvalidCharMaskAt = 'Invalid char mask "%s" at %d';
rsInvalidCharMask = 'Invalid char mask "%s"';
rsMissingCloseCharMaskAt = 'Missing close char mask "%s" at %d';
rsMissingCloseCharMask = 'Missing close char mask "%s"';
rsIncompleteMask = 'Reached end of mask, but missing close/escape sequence.';
rsInvalidEscapeChar = 'Escape character must be ASCII <= 127';
rsInternalError = 'Internal %s error.';
// XPath // XPath
lrsNodeSet = 'node set'; lrsNodeSet = 'node set';
lrsBoolean = 'boolean'; lrsBoolean = 'boolean';

File diff suppressed because it is too large Load Diff

View File

@ -215,7 +215,7 @@ resourceString
// LResource, Menus, ExtCtrls, ImgList, Spin // LResource, Menus, ExtCtrls, ImgList, Spin
// StdCtrls, Calendar, CustomTimer, Forms, Grids, LCLProc, Controls, ComCtrls, // StdCtrls, Calendar, CustomTimer, Forms, Grids, LCLProc, Controls, ComCtrls,
// ExtDlgs, EditBtn, Masks, MaskEdit // ExtDlgs, EditBtn, MaskEdit
sInvalidActionRegistration = 'Invalid action registration'; sInvalidActionRegistration = 'Invalid action registration';
sInvalidActionUnregistration = 'Invalid action unregistration'; sInvalidActionUnregistration = 'Invalid action unregistration';
sInvalidActionEnumeration = 'Invalid action enumeration'; sInvalidActionEnumeration = 'Invalid action enumeration';
@ -229,7 +229,6 @@ resourceString
sDuplicateMenus = 'Duplicate menus'; sDuplicateMenus = 'Duplicate menus';
sCannotFocus = 'Cannot focus a disabled or invisible window'; sCannotFocus = 'Cannot focus a disabled or invisible window';
sParentRequired = 'Control "%s" has no parent window.'; sParentRequired = 'Control "%s" has no parent window.';
sInvalidCharSet = 'The char set in mask "%s" is not valid!';
SMaskEditNoMatch = 'The current text does not match the specified mask.'; SMaskEditNoMatch = 'The current text does not match the specified mask.';
rsInvalidPropertyValue = 'Invalid property value'; rsInvalidPropertyValue = 'Invalid property value';

View File

@ -680,7 +680,7 @@ var
MaskList: TMaskList; MaskList: TMaskList;
Files: TList; Files: TList;
FileItem: TFileItem; FileItem: TFileItem;
MaskOptions: TMaskOptions; CaseSens: Boolean;
{$if defined(windows) and not defined(wince)} {$if defined(windows) and not defined(wince)}
ErrMode : LongWord; ErrMode : LongWord;
{$endif} {$endif}
@ -696,14 +696,12 @@ begin
Delete(AMask, Length(AMask), 1); Delete(AMask, Length(AMask), 1);
if Trim(AMask) = '' then if Trim(AMask) = '' then
AMask := AllFilesMask; AMask := AllFilesMask;
MaskOptions := []; // was moDisableSets
{$ifdef NotLiteralFilenames} {$ifdef NotLiteralFilenames}
if (ACaseSensitivity = mcsCaseSensitive) then CaseSens := ACaseSensitivity = mcsCaseSensitive;
{$else} {$else}
if (ACaseSensitivity <> mcsCaseInsensitive) then CaseSens := ACaseSensitivity <> mcsCaseInsensitive;
{$endif} {$endif}
Include(MaskOptions, moCaseSensitive); MaskList := TMaskList.Create(AMask, ';', CaseSens);
MaskList := TMaskList.Create(AMask, ';', MaskOptions);
try try
if AFileSortType = fstNone then if AFileSortType = fstNone then
Files:=nil Files:=nil