[Lazarus] MatchesWindowsMask('[x]','[x]') return False

Rolf Wetjen rolf.wetjen at mail.de
Fri Mar 20 09:05:01 CET 2020


Hi Bart,

I did something similar yesterday:

TMask.InitMaskString(const AValue: String; const CaseSensitive: Boolean; 
*const UseSets: Boolean = True*);
TMask.Create(const AValue: String; const CaseSensitive: Boolean = False; 
*const UseSets: Boolean = True*);
TMaskList.Create(const AValue: String; ASeparator: Char = ';'; const 
CaseSensitive: Boolean = False; *const UseSets: Boolean = True*);

function MatchesMask(const FileName, Mask: String; const CaseSensitive: 
Boolean = False; *const UseSets: Boolean = True*): Boolean;
function MatchesWindowsMask(const FileName, Mask: String; const 
CaseSensitive: Boolean = False; *const UseSets: Boolean = False*): Boolean;
function MatchesMaskList(const FileName, Mask: String; Separator: Char = 
';'; const CaseSensitive: Boolean = False; *const UseSets: Boolean = 
True*): Boolean;
function MatchesWindowsMaskList(const FileName, Mask: String; Separator: 
Char = ';'; const CaseSensitive: Boolean = False; *const UseSets: 
Boolean = /False/*): Boolean;

The only code change is in TMask.InitMaskString
-      '[': AddCharSet;
+      '[': if fUseSets then
+             AddCharSet
+           else
+             AddChar;

This works fine.

Easy to implement it as Options.

Regards,

Rolf

Am 19.03.2020 um 18:37 schrieb Bart via lazarus:
> On Thu, Mar 19, 2020 at 8:25 AM Rolf Wetjen via lazarus
> <lazarus at lists.lazarus-ide.org> wrote:
>
>> seems that this isn't your favourite option.
> Without any context, I cannot comment on this.
>
>> Ok, what's about an additional TMask property to control the useage of
>> sets (default should be true for Delphi compatibility) and additional
>> options for the MatchesMask and MatchesWindowsMask functions?
> It's on my ToDo list (as long as other devels don't object to this.
> I intend to have an Options property for that, with for now
> moCaseSensitive and moDisableSets.
> There will be an overloaded constructor TMask,Create((const AValue:
> String; ASeparator: Char = ';'; const Options: TMaskOptions = []);
> (By default CaseSensitive and DisableSets must be off for backwards
> compatibility)
>
> It will only be for trunk and the next stable major release (so it
> won't go into fixes branch) anyhow.
>
>


-- 
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20200320/491bb47b/attachment.html>
-------------- next part --------------
Index: components/lazutils/masks.pas
===================================================================
--- components/lazutils/masks.pas	(revision 62701)
+++ components/lazutils/masks.pas	(working copy)
@@ -42,11 +42,12 @@
   private
     FMask: TMaskString;
     fCaseSensitive: Boolean;
+    fUseSets: Boolean;
     fInitialMask: String;
-    procedure InitMaskString(const AValue: String; const CaseSensitive: Boolean);
+    procedure InitMaskString(const AValue: String; const CaseSensitive: Boolean; const UseSets: Boolean = True);
     procedure ClearMaskString;
   public
-    constructor Create(const AValue: String; const CaseSensitive: Boolean = False);
+    constructor Create(const AValue: String; const CaseSensitive: Boolean = False; const UseSets: Boolean = True);
     destructor Destroy; override;
 
     function Matches(const AFileName: String): Boolean;
@@ -68,7 +69,7 @@
     function GetCount: Integer;
     function GetItem(Index: Integer): TMask;
   public
-    constructor Create(const AValue: String; ASeparator: Char = ';'; const CaseSensitive: Boolean = False);
+    constructor Create(const AValue: String; ASeparator: Char = ';'; const CaseSensitive: Boolean = False; const UseSets: Boolean = True);
     destructor Destroy; override;
 
     function Matches(const AFileName: String): Boolean;
@@ -78,10 +79,10 @@
     property Items[Index: Integer]: TMask read GetItem;
   end;
 
-function MatchesMask(const FileName, Mask: String; const CaseSensitive: Boolean = False): Boolean;
-function MatchesWindowsMask(const FileName, Mask: String; const CaseSensitive: Boolean = False): Boolean;
-function MatchesMaskList(const FileName, Mask: String; Separator: Char = ';'; const CaseSensitive: Boolean = False): Boolean;
-function MatchesWindowsMaskList(const FileName, Mask: String; Separator: Char = ';'; const CaseSensitive: Boolean = False): Boolean;
+function MatchesMask(const FileName, Mask: String; const CaseSensitive: Boolean = False; const UseSets: Boolean = True): Boolean;
+function MatchesWindowsMask(const FileName, Mask: String; const CaseSensitive: Boolean = False; const UseSets: Boolean = False): Boolean;
+function MatchesMaskList(const FileName, Mask: String; Separator: Char = ';'; const CaseSensitive: Boolean = False; const UseSets: Boolean = True): Boolean;
+function MatchesWindowsMaskList(const FileName, Mask: String; Separator: Char = ';'; const CaseSensitive: Boolean = False; const UseSets: Boolean = False): Boolean;
 
 implementation
 
@@ -105,11 +106,11 @@
 end;
 
 
-function MatchesMask(const FileName, Mask: String; const CaseSensitive: Boolean): Boolean;
+function MatchesMask(const FileName, Mask: String; const CaseSensitive: Boolean; const UseSets: Boolean = True): Boolean;
 var
   AMask: TMask;
 begin
-  AMask := TMask.Create(Mask, CaseSensitive);
+  AMask := TMask.Create(Mask, CaseSensitive, UseSets);
   try
     Result := AMask.Matches(FileName);
   finally
@@ -117,11 +118,11 @@
   end;
 end;
 
-function MatchesWindowsMask(const FileName, Mask: String; const CaseSensitive: Boolean): Boolean;
+function MatchesWindowsMask(const FileName, Mask: String; const CaseSensitive: Boolean; const UseSets: Boolean = False): Boolean;
 var
   AMask: TMask;
 begin
-  AMask := TMask.Create(Mask, CaseSensitive);
+  AMask := TMask.Create(Mask, CaseSensitive, UseSets);
   try
     Result := AMask.MatchesWindowsMask(FileName);
   finally
@@ -129,11 +130,11 @@
   end;
 end;
 
-function MatchesMaskList(const FileName, Mask: String; Separator: Char; const CaseSensitive: Boolean): Boolean;
+function MatchesMaskList(const FileName, Mask: String; Separator: Char; const CaseSensitive: Boolean; const UseSets: Boolean = True): Boolean;
 var
   AMaskList: TMaskList;
 begin
-  AMaskList := TMaskList.Create(Mask, Separator, CaseSensitive);
+  AMaskList := TMaskList.Create(Mask, Separator, CaseSensitive, UseSets);
   try
     Result := AMaskList.Matches(FileName);
   finally
@@ -141,11 +142,11 @@
   end;
 end;
 
-function MatchesWindowsMaskList(const FileName, Mask: String; Separator: Char; const CaseSensitive: Boolean): Boolean;
+function MatchesWindowsMaskList(const FileName, Mask: String; Separator: Char; const CaseSensitive: Boolean; const UseSets: Boolean = False): Boolean;
 var
   AMaskList: TMaskList;
 begin
-  AMaskList := TMaskList.Create(Mask, Separator, CaseSensitive);
+  AMaskList := TMaskList.Create(Mask, Separator, CaseSensitive, UseSets);
   try
     Result := AMaskList.MatchesWindowsMask(FileName);
   finally
@@ -155,7 +156,7 @@
 
 { TMask }
 
-procedure TMask.InitMaskString(const AValue: String; const CaseSensitive: Boolean);
+procedure TMask.InitMaskString(const AValue: String; const CaseSensitive: Boolean; const UseSets: Boolean = True);
 var
   I: Integer;
   SkipAnyText: Boolean;
@@ -293,6 +294,7 @@
 
 begin
   fCaseSensitive:=CaseSensitive;
+  fUseSets:=UseSets;
   SetLength(FMask.Chars, 0);
   FMask.MinLength := 0;
   FMask.MaxLength := 0;
@@ -304,7 +306,10 @@
     case GetCodePoint(AValue,I) of
       '*': AddAnyText;
       '?': AddAnyChar;
-      '[': AddCharSet;
+      '[': if fUseSets then
+             AddCharSet
+           else
+             AddChar;
       else AddChar;
     end;
   end;
@@ -319,12 +324,13 @@
       Dispose(FMask.Chars[I].SetValue);
 end;
 
-constructor TMask.Create(const AValue: String; const CaseSensitive: Boolean);
+constructor TMask.Create(const AValue: String; const CaseSensitive: Boolean; const UseSets: Boolean = True);
 
 begin
   fInitialMask := AValue;
   fCaseSensitive := CaseSensitive;
-  InitMaskString(AValue, CaseSensitive);
+  fUseSets:=UseSets;
+  InitMaskString(AValue, CaseSensitive, UseSets);
 end;
 
 destructor TMask.Destroy;
@@ -508,7 +514,7 @@
   Result := FMasks.Count;
 end;
 
-constructor TMaskList.Create(const AValue: String; ASeparator: Char; const CaseSensitive: Boolean);
+constructor TMaskList.Create(const AValue: String; ASeparator: Char; const CaseSensitive: Boolean; const UseSets: Boolean = True);
 var
   S: TParseStringList;
   I: Integer;
@@ -518,7 +524,7 @@
   S := TParseStringList.Create(AValue, ASeparator);
   try
     for I := 0 to S.Count - 1 do
-      FMasks.Add(TMask.Create(S[I], CaseSensitive));
+      FMasks.Add(TMask.Create(S[I], CaseSensitive, UseSets));
   finally
     S.Free;
   end;


More information about the lazarus mailing list