diff options
author | Pixel <Pixel> | 2001-11-29 17:42:23 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-29 17:42:23 +0000 |
commit | 23d91060b557f77fc37e629a168ca810cd66a364 (patch) | |
tree | 1af217429ab2e9f00188381f560e6a0bdea968b1 /lib | |
parent | a6f79293000e96e07ab2688541fcb38225d4094f (diff) |
Fixing regex
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Regex.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/Regex.cc b/lib/Regex.cc index 9b70d68..3c566bd 100644 --- a/lib/Regex.cc +++ b/lib/Regex.cc @@ -2,18 +2,33 @@ char t[1024]; -Regex empty("$^"), any(".*"); +Regex empty("^$"), any(".*"); -Regex::Regex(const String & regex, int cflags, int aeflags) throw (GeneralException) : eflags(aeflags) { +Regex::Regex(const String & regex, int acflags, int aeflags) throw (GeneralException) : cflags(acflags), eflags(aeflags), pattern(regex.strdup()) { int r; - if ((r = regcomp(&preg, regex.to_charp(), cflags | REG_NOSUB))) { + + if ((r = regcomp(&preg, pattern, cflags | REG_NOSUB))) { + cerr << "Error in regcomp:"; regerror(r, &preg, t, sizeof(t)); + cerr << t << endl; throw GeneralException(String("Regex \"") + regex + "\" failed to compile: " + t + "\n"); } } +Regex::Regex(const Regex & regex) : pattern(Base::strdup(pattern)) { + int r; + + if ((r = regcomp(&preg, pattern, cflags | REG_NOSUB))) { + cerr << "Error in regcomp:"; + regerror(r, &preg, t, sizeof(t)); + cerr << t << endl; + throw GeneralException(String("Regex \"") + pattern + "\" failed to compile: " + t + "\n"); + } +} + Regex::~Regex() { regfree(&preg); + free(pattern); } bool Regex::Match(const String & s) const { |