From 23d91060b557f77fc37e629a168ca810cd66a364 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 29 Nov 2001 17:42:23 +0000 Subject: Fixing regex --- lib/Regex.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lib') 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 { -- cgit v1.2.3