diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-11-01 06:58:18 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-11-01 07:23:49 +0100 |
commit | 9f6cba5c0370aee2f9803abbc35ab7e67f57ee84 (patch) | |
tree | b03485f177d6ff700aac7fc8ff1e7e9e23a61866 /src/glob.h | |
parent | b5e6f4c61b7b8e220fb3faa071e30b3dfc559f2f (diff) | |
download | sciteco-9f6cba5c0370aee2f9803abbc35ab7e67f57ee84.tar.gz |
globbing supports character classes now and ^EN string building construct to escape glob patterns
* globbing is fnmatch(3) compatible, now on every supported platform.
* which means that escaping of glob patterns is possible now.
^ENq has been introduced to ease this task.
* This finally allows you to pass unmodified filenames to EB.
Previously it was impossible to open file names containing glob wildcards.
* this was achieved by moving from GPattern to GRegex as the underlying
implementation.
* The glob pattern is converted to a regular expression before being
compiled to a GRegex.
This turned out to be trickier than anticipated (~140 lines of code)
and has a runtime penalty of course (complexity is O(2*n) over the
pattern length).
It is IMHO still better than the alternatives, like importing
external code from libiberty, which is potentially non-cross-platform.
* Using GRegex also opens the potential of supporting brace "expansions"
later in the form of glob pattern constructs
(they won't actually expand but match alternatives).
* is_glob_pattern() has been simplified and moved to Globber::is_pattern().
It makes sense to reuse the Globber class namespace instead of using
plain functions for functions working on glob patterns.
* The documentation has a new subsection on glob patterns now.
* Testsuite extended with glob pattern test cases
Diffstat (limited to 'src/glob.h')
-rw-r--r-- | src/glob.h | 31 |
1 files changed, 12 insertions, 19 deletions
@@ -18,6 +18,8 @@ #ifndef __GLOB_H #define __GLOB_H +#include <string.h> + #include <glib.h> #include <glib/gstdio.h> @@ -26,29 +28,11 @@ namespace SciTECO { -/* - * Auxiliary functions - */ -static inline bool -is_glob_pattern(const gchar *str) -{ - if (!str) - return false; - - while (*str) { - if (*str == '*' || *str == '?') - return true; - str++; - } - - return false; -} - class Globber { GFileTest test; gchar *dirname; GDir *dir; - GPatternSpec *pattern; + GRegex *pattern; public: Globber(const gchar *pattern, @@ -56,6 +40,15 @@ public: ~Globber(); gchar *next(void); + + static inline bool + is_pattern(const gchar *str) + { + return str && strpbrk(str, "*?[") != NULL; + } + + static gchar *escape_pattern(const gchar *pattern); + static GRegex *compile_pattern(const gchar *pattern); }; /* |