CMS 3D CMS Logo

Regexp.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_REGEXP_H
00002 # define CLASSLIB_REGEXP_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/utils/RegexpMatch.h"
00007 # include <utility>
00008 # include <string>
00009 # include <vector>
00010 # include <list>
00011 
00012 namespace lat {
00013 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00014 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00015 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00016 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00017 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00018 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00019 
00020 class Regexp
00021 {
00022 public:
00024     // Predefined regular expressions.
00025     static const Regexp rxwhite;        // = \s+   (or: [ \n\t\r\v\f]+)
00026     static const Regexp rxint;          // = -?\d+ (or: -?[0-9]+)
00027     static const Regexp rxdouble;       // = -?(\d+\.\d*|\d+|\.\d+)([eE][-+]?\d+)?
00028     // = -?(([0-9]+\\.[0-9]*)|([0-9]+)|(\\.[0-9]+))([eE][---+]?[0-9]+)?
00029     static const Regexp rxalpha;        // = [[:alpha:]]+
00030     static const Regexp rxlowercase;    // = [[:lower:]]+
00031     static const Regexp rxuppercase;    // = [[:upper:]]+
00032     static const Regexp rxalphanum;     // = [[:alpha:]\d]+
00033     static const Regexp rxidentifier;   // = [A-Za-z_$][A-Za-z0-9_$]*
00034 
00036     // Regular expression syntax.
00037     enum Syntax {
00038         POSIXBasic      = 0x0001,       //< POSIX.1 basic regular expression
00039         POSIXExtended   = 0x0002,       //< POSIX.1 extended regular expression
00040         Perl            = 0x0003,       //< PERL regular expression
00041         Wildcard        = 0x0004        //< Bourne shell file name glob pattern
00042     };
00043 
00045     // Regular expression options.
00046     enum Options {
00047         AnchorAtStart   = 0x0010, // PCRE
00048         IgnoreCase      = 0x0020, // PCRE, POSIX
00049         DollarAtEndOnly = 0x0040, // PCRE
00050         DotMatchesAll   = 0x0080, // PCRE
00051         Extended        = 0x0100, // PCRE
00052         MultiLine       = 0x0200, // PCRE
00053         Minimal         = 0x0400, // PCRE
00054         // UTF8Chars    = 0x0400, // PCRE
00055         // Extra        = 0x0800, // PCRE
00056         // NoMatchData  = 0x1000, // PCRE?, POSIX
00057         StandardLocale  = 0x2000  // PCRE, POSIX?
00058     };
00059 
00061     // Match options.
00062     enum MatchOptions {
00077         MatchNotBOL     = 0x01,
00078 
00091         MatchOffsetBOL  = 0x02,
00092 
00100         MatchNotEOL     = 0x04,
00101 
00108         MatchNoEmpty    = 0x08,
00109 
00111         MatchAnchored   = 0x10,
00112 
00114         MatchAll        = 0x20,
00115 
00120         MatchContinue   = 0x40
00121     };
00122 
00124     Regexp (void);
00125     Regexp (const std::string &pat, unsigned options = 0, Syntax s = Perl);
00126     // Regexp (const std::string &pat, const char *options, Syntax s = Perl);
00127     Regexp (const Regexp &x);
00128     Regexp &operator= (const Regexp &x);
00129     Regexp &operator= (const std::string &x);
00130     ~Regexp (void);
00131 
00132     bool                operator== (const Regexp &x) const;
00133     bool                operator!= (const Regexp &x) const;
00134 
00135     static std::string  escape (const std::string &text);
00136 
00137     Syntax              syntax (void) const;
00138     bool                empty (void) const;
00139     bool                valid (void) const;
00140 
00141     int                 errorOffset (void) const;
00142     const char *        errorMessage (void) const;
00143     void                clearError (void);
00144 
00145     unsigned            options (void) const;
00146     void                setOptions (unsigned value);
00147     void                enableOptions (unsigned mask);
00148     void                disableOptions (unsigned mask);
00149 
00150     std::string         pattern (void) const;
00151     void                setPattern (const std::string &pat);
00152 
00153     bool                compile (bool force = false);
00154     void                study (void);
00155 
00156     bool                exactMatch (const char *s) const;
00157     bool                exactMatch (const std::string &s) const;
00158 
00159     bool                match (const char *s, int offset = 0,
00160                                int flags = 0, RegexpMatch *result = 0) const;
00161     bool                match (const std::string &s, int offset = 0,
00162                                int flags = 0, RegexpMatch *result = 0) const;
00163 
00164     int                 search (const char *s, int offset = 0,
00165                                 int flags = 0, RegexpMatch *result = 0) const;
00166     int                 search (const std::string &s, int offset = 0,
00167                                 int flags = 0, RegexpMatch *result = 0) const;
00168 
00169     int                 rsearch (const char *s, int offset = -1,
00170                                  int flags = 0, RegexpMatch *result = 0) const;
00171     int                 rsearch (const std::string &s, int offset = -1,
00172                                  int flags = 0, RegexpMatch *result = 0) const;
00173 
00174 protected:
00175     void                uncompile (void);
00176 
00177     // bool             dosearch (const std::string &s, int offset);
00178     // void             split (const std::string &s, int limit, int start,
00179     //                         int end, StringList &into);
00180     // std::string      replaceVarRefs (const std::string &s);
00181     // void             zero (void);
00182 
00183     // unsigned         parseMods (const char *mods);
00184     // int              doSubs (const std::string &s, std::string &final,
00185     //                          const char *with, int *ovec, int nmatch);
00186 
00187 private:
00188     static const int SyntaxMask = 0x000F;
00189     struct Rep;
00190     struct PCRERep;
00191     struct POSIXRep;
00192 
00193     std::string         m_pattern;
00194     unsigned            m_options;
00195     Rep                 *m_rep;
00196 };
00197 
00198 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00199 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00200 
00201 } // namespace lat
00202 #endif // CLASSLIB_REGEXP_H

Generated on Tue Jun 9 17:38:55 2009 for CMSSW by  doxygen 1.5.4