diff options
Diffstat (limited to 'lib/Regex.cc')
| -rw-r--r-- | lib/Regex.cc | 26 | 
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/Regex.cc b/lib/Regex.cc index 2ef2c8e..9b70d68 100644 --- a/lib/Regex.cc +++ b/lib/Regex.cc @@ -1 +1,25 @@ -#include "Regex.h"
\ No newline at end of file +#include "Regex.h" + +char t[1024]; + +Regex empty("$^"), any(".*"); + +Regex::Regex(const String & regex, int cflags, int aeflags) throw (GeneralException) : eflags(aeflags) { +    int r; +    if ((r = regcomp(&preg, regex.to_charp(), cflags | REG_NOSUB))) { +	regerror(r, &preg, t, sizeof(t)); +	throw GeneralException(String("Regex \"") + regex + "\" failed to compile: " + t + "\n"); +    } +} + +Regex::~Regex() { +    regfree(&preg); +} + +bool Regex::Match(const String & s) const { +    if (regexec(&preg, s.to_charp(), 0, 0, eflags)) { +	return false; +    } else { +	return true; +    } +}  | 
