[Lazarus] TMask revisited
José Mejuto
joshyfun at gmail.com
Thu Oct 21 10:29:32 CEST 2021
El 20/10/2021 a las 22:59, Bart via lazarus escribió:
>> Range syntax: [a-z]
>> Set syntax: [abcdefghijklmnopqrstuvwxyz]
>
> What would be the effective difference between [a-e] and [abcde] then?
> I did understand that both meant: a single charcter being either 'a',
> 'b', 'c', 'd', or 'e'?
Hello,
Technically the set requires one check for every possible char and a
range only two checks, but the most important one is the easy to write
for every day situations. It is quite usual to try to match strings that
starts with a number and not with a letter, so you write a mask like:
"[0-9]*"
Of course you can write it with sets:
"[0123456789]*"
Now you need to match a string that starts with a number and the second
char must be a letter, with a set it will be too large and unclear:
"[0123456789][abcdefghijklmnopqrstuvwxyz]*"
with ranges:
"[0-9][a-z]*"
So the question is, why sets if ranges can be used ? Because sometimes
you need to exclude strings that starts with number 1:
"[0234567989][a-z]"
> Naming them different just confuses me (which probably is my fault).
Because they are different beast in the code and in the syntax, many
times ranges apparently are syntactic sugar for sets, but ranges have a
begin and an end, and both have a mission, one, ranges, add clarity to
the desired match, and the second, sets, add flexibility to the mask write.
Most times when you need support for one also need for the other, so
when needs to be disabled, the other, quite sure, needs to be disabled also.
--
More information about the lazarus
mailing list