Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Regexp.h

Go to the documentation of this file.
00001 #ifndef REGEXEXCEPTION_H
00002 #define REGEXEXCEPTION_H
00003 
00004 /*
00005  * OO wrapper for regular expression functions
00006  * 
00007  * Copyright (C) 2003  Enrico Zini <enrico@debian.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022  */
00023 
00024 #include <tagcoll/Exception.h>
00025 #include <sys/types.h>
00026 #include <regex.h>
00027 
00028 namespace Debtags
00029 {
00030 
00032 
00033 class RegexpException : public SystemException
00034 {
00035 protected:
00036     std::string _message;
00037 
00038 public:
00039     RegexpException(const regex_t& re, int code, const std::string& context)
00040         throw ();
00041     ~RegexpException() throw () {}
00042 
00043     virtual const char* type() const throw () { return "RegexpException"; }
00044     virtual std::string desc() const throw () { return _message + " " + _context; }
00045 };
00046 
00047 class Regexp
00048 {
00049 protected:
00050     regex_t re;
00051     regmatch_t* pmatch;
00052     int nmatch;
00053     std::string lastMatch;
00054 
00055 public:
00056     Regexp(const std::string& expr, int match_count = 0, int flags = 0) throw (RegexpException);
00057     ~Regexp() throw ();
00058 
00059     bool match(const std::string& str, int flags = 0) throw (RegexpException);
00060     
00061     std::string operator[](int idx) throw (OutOfRangeException);
00062 };
00063 
00064 class ExtendedRegexp : public Regexp
00065 {
00066 public:
00067     ExtendedRegexp(const std::string& expr, int match_count = 0, int flags = 0) throw (RegexpException)
00068         : Regexp(expr, match_count, flags | REG_EXTENDED) {}
00069 };
00070 
00071 };
00072 
00073 // vim:set ts=4 sw=4:
00074 #endif

Generated on Wed Jul 13 19:19:40 2005 for libdebtags by  doxygen 1.4.3-20050530