CBuild wiki
Glob syntax implementation over POSIX ERE regex.
License: GPL-3.0-or-later.
This glob is implemented as a preprocessor and a series of wrappers around POSIX regex API. This preprocessor translate glob patter to valid and equal regex pattern. This includes both escaping regex’s special characters and translating glob’s special characters to equal sequences of regexes.
In general any valid glob patter can be used, it support this “operators”:
? - match any single character. (Translates to
.).* - match any sequence of characters. (Translates to
.*).[...] - matches any character from character class.
(Translates to itself literally).! as first element of character class to invert
character class. (Translates to ‘^’).It also supports some syntax extensions:
[...]*. This glob engine
support same syntax. If ]* sequence is found it will not be
translated in any way.\ as escape character. Glob also
support is so no preprocessing is needed here. But this preprocessor
supports its own escape character too - #. Next character
after it will be literally copied into output regex pattern.These characters are escaped with \ by default in
generated regex:
(.).{.}.^.$...|.+.By default pattern is wrapped in ^...$ to match full
string.
typedef struct cbuild_glob_t {
struct __cbuild_glob_res_t {
const char* res;
size_t res_idx;
regmatch_t captures[CBUILD_GLOB_CAPTURE_COUNT];
} *data;
size_t size;
size_t capacity;
regex_t regex;
regmatch_t captures[CBUILD_GLOB_CAPTURE_COUNT];
} cbuild_glob_t;Glob context.
__cbuild_glob_res_t*
data Data for dynamic array of
matches.
const char*
data.res Match text. Points to
original data.size_t data.res_idx Match index.regmatch_t[CBUILD_GLOB_CAPTURE_COUNT]
data.captures Copy of capture groups
for that match.size_t capacity Capacity for dynamic array of
matches.size_t size Count of elements for dynamic array
of matches.regex_t regex Cache for compiled regex.regmatch_t[CBUILD_GLOB_CAPTURE_COUNT]
captures Scratchpad captures for
regex engine.Options for pattern compilation
bool partial_match Do not wrap pattern in
^...$.CBUILDDEF bool cbuild_glob_compile_opt(cbuild_glob_t* glob, const char* pattern,
struct cbuild_glob_opts_t opts);Compile new glob patter.
This is a two-step process, first it will transform glob expression
into a regx one and then it will call regcomp. POSIX ERE
will be used.
Compile new glob patter.
This is a two-step process, first it will transform glob expression
into a regx one and then it will call regcomp. POSIX ERE
will be used.
cbuild_glob_t*
glob Glob object.const char*
pattern Pattern to compile....cbulid_glob_opts_t
… Fields of configuration structure in
initializer-list form.Find matches in a list.
bool true
if at least one match was found. false if no matches were
found.
Match single element with a glob.
This function resets glob matches but does not set them. You should
check return value to know if glob matched. To get capture groups values
you can use outer captures array.
bool true
if at least one match was found. false if no matches were
found.
Clean underlying regex and free matches array.