SHell-compatible WILDcards
shwild is a small, standalone library, implemented in C++ with a C and a C++ API, that provides shell-compatible wildcard matching.
Detailed instructions - via CMake, via bundling, via custom makefile parameters - are provided in the accompanying INSTALL.md file.
The shwild C API comprises the following functions:
shwild_init()
;shwild_uninit()
;shwild_match()
;shwild_match_s()
;shwild_compile_pattern()
;shwild_compile_pattern_s()
;shwild_destroy_pattern()
;shwild_match_pattern()
;shwild_match_pattern_s()
;
and used as in the following simple example:
#include <shwild/shwild.h>
. . .
int r = shwild_init();
if (r < 0) {
. . . // report failure and exit
} else {
shwild_handle_t hCompiledPattern;
int r2 = shwild_compile_pattern("X[0-9]*", 0, &hCompiledPattern);
if (r2 < 0) {
. . . // report failure and exit
} else {
assert(0 == shwild_match_pattern(hCompiledPattern, "X0"));
assert(0 == shwild_match_pattern(hCompiledPattern, "X8abc"));
assert(0 != shwild_match_pattern(hCompiledPattern, "X"));
assert(0 != shwild_match_pattern(hCompiledPattern, "Y0"));
shwild_destroy_pattern(hCompiledPattern);
}
shwild_uninit();
}
The shwild C++ API is a simple wrapper over the shwild C API, with the following components:
shwild::Pattern
;shwild::PatternException
;
and used as in the following simple example:
#include <shwild/shwild.hpp>
. . .
shwild::Pattern pattern("X[0-9]*", 0);
assert( pattern.match("X0"));
assert( pattern.match("X8abc"));
assert(!pattern.match("X"));
assert(!pattern.match("Y0"));
Examples are provided in the examples
directory, along with a markdown description for each.
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/shwild.
The original (~2005) implementation used STLSoft for discrimination of compilers and for library support. For modern compilers with broad support for the latest language standards this is not necessary. Hence, if the preprocessor symbol SHWILD_NO_STLSOFT
is specified then all dependencies on STLSoft are removed and basic C++-14 features are used instead. (This is done in the CMake configuration provided - see INSTALL.md.)
If you do need STLSoft, then version 1.10.6 or later is recommended. If you're using a very old compiler you may wish to use STLSoft-1.9, for which version 1.9.136 is recommended. Further, the makefiles require definition of the environment variable STLSOFT
that should be set to the root directory of a clone of STLSoft.
- STLSoft 1.9
- STLSoft 1.10 (Recommended)
Projects in which shwild is used include:
Projects in which shwild is used for testing include:
shwild is released under the 3-clause BSD license. See LICENSE for details.