Difference between revisions of "Masks"

From Free Pascal wiki
Jump to navigationJump to search
Line 29: Line 29:
The default value for the matching method is [mocAnyChar,mocAnyCharOrNone,mocAnyText,mocRange,mocSet,mocNegateGroup,mocEscapeChar].
The default value for the matching method is [mocAnyChar,mocAnyText,mocRange,mocSet,mocNegateGroup].
=== Specific Windows Quirks ===
=== Specific Windows Quirks ===

Revision as of 20:50, 29 October 2021

This page describes the Masks unit as per Lazarus version 2.3



The masks unit provides classes and functions for pattern matching using wildcards, sets/ranges and/or literal characters.

Controlling how the mask is interpreted


TMaskOpcodes is defined as set of TMaskOpcode.
The TMaskOpcode enumeration type consist of:

Name Interpretation
mocAnyChar Treat ? as a wildcard to match exactly one char
mocAnyCharOrNone Treat [?] to match any char or the absence of a char
mocAnyText Treat * as a wildcard to mach zero or any mumber of chars
mocRange treat [a-c] to match either 'a', 'b' or 'c'. '-' is treated as a range indicator.

To have a literal '-' in a range, it must be the first character in the range: [-a-c] matches '-', 'a', 'b', or 'c'.

mocSet Treat [a-c] to match either 'a', '-' or 'c'
mocNegateGroup Treat [!a-c] to not match 'a', 'b', or 'c', but match any other char. Requires mocRange and/or mocSet
mocEscapeChar Treat EscapeChar (defaults to '\') to take the next char as a literal, so '\*' is treated as a literal '*'.

The default value for the matching method is [mocAnyChar,mocAnyText,mocRange,mocSet,mocNegateGroup].

Specific Windows Quirks

Windows mask works in a different mode than regular masks, it has many quirks and corner cases inherited from CP/M, then adapted to DOS (8.3) file names and adapted again for long file names.

TWindowsQuirks is defined as set of TWindowsQuirks. The TWindowsQuirk enumeration type consists of:

Name Example mask Interpretation
wqAnyExtension Anything*.* The filename is not required to have an extension
wqFilenameEnd Anything??.abc The '?' matches 1 or 0 chars (except '.')
wqExtension3More Anything.abc Matches Anything.abc but also Anything.abc* (so '*.pas' also matches with 'file.pas.bak')
wqEmptyIsAny Empty string matches anything, so acts like '*'
wqAllByExtension .abc Is treated as *.abc
wqNoExtension Anything*. Matches Anything* without extension

TWindowsQuirks can only be used in the Windows specfic classses and functions. The default value for those matching methods is [wqAnyExtension,wqFilenameEnd,wqEmptyIsAny,wqNoExtension]