Intro
Hi everyone, I wanted to get some feedback on a feature that expands the functionality of the Glob pattern matcher.
Problem
Currently, the Glob pattern matching stuff does not support a way to exclude specific terms from matches.
Solution
Add an “inverted match” operator: {!foo}
. This will match literally everything so long as it is not precisely "foo"
.
Notice that this operator matches the existing syntax of the term expansion bracket syntax (i.e., {foo,bar}
will match any foo
or bar
).
Details
Prepend a !
to a term within curly brackets and the whole bracket expansion becomes “inverted”. Once one term is inverted, they all must be – this is enforced through pattern compilation errors.
This operator respects its surroundings just like other bracket operators.
The pattern: test{!_debug}
will match against strings starting with test
but not ending with _debug
.
So, it will match test
, test_qaz
, test_qux
but not test_debug
or missionimpossible
.
You can supply multiple inverted terms.
the_{!dog,!cat}_can_fly
will match against the_bird_can_fly
or the_alligator_can_fly
but not the_dog_can_fly
or the_cat_can_fly
Implementation
See my tree glob-negation.
This tree also includes a code snippet that allows for discriminating against certain types in arithmetic overflow checks utilizing this new operator.
For example, you can disable unsigned integer overflow sanitization for all types except size_t
with an ignorelist.txt
:
[unsigned-integer-overflow]
type:{!size_t}
Another way to accomplish this is to introduce “allowlists” in the sanitizer space. Currently, there is no allowlisting available. However, I have a sanitize-allowlist tree which aims to implement that.
Conclusion
Adding an inverted match operator can usefully expand the functionality of the GlobPattern
class and of those that use it.