regex.h
Go to the documentation of this file.
00001 #ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00002 #define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 
00009 #include <vector>
00010 #include <string>
00011 
00012 namespace YAML_PM
00013 {
00014         class Stream;
00015 
00016         enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
00017 
00018         // simplified regular expressions
00019         // . Only straightforward matches (no repeated characters)
00020         // . Only matches from start of string
00021         class RegEx
00022         {
00023         public:
00024                 RegEx();
00025                 RegEx(char ch);
00026                 RegEx(char a, char z);
00027                 RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
00028                 ~RegEx() {}
00029 
00030                 friend RegEx operator ! (const RegEx& ex);
00031                 friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
00032                 friend RegEx operator && (const RegEx& ex1, const RegEx& ex2);
00033                 friend RegEx operator + (const RegEx& ex1, const RegEx& ex2);
00034                 
00035                 bool Matches(char ch) const;
00036                 bool Matches(const std::string& str) const;
00037                 bool Matches(const Stream& in) const;
00038                 template <typename Source> bool Matches(const Source& source) const;
00039 
00040                 int Match(const std::string& str) const;
00041                 int Match(const Stream& in) const;
00042                 template <typename Source> int Match(const Source& source) const;
00043 
00044         private:
00045                 RegEx(REGEX_OP op);
00046                 
00047                 template <typename Source> bool IsValidSource(const Source& source) const;
00048                 template <typename Source> int MatchUnchecked(const Source& source) const;
00049 
00050                 template <typename Source> int MatchOpEmpty(const Source& source) const;
00051                 template <typename Source> int MatchOpMatch(const Source& source) const;
00052                 template <typename Source> int MatchOpRange(const Source& source) const;
00053                 template <typename Source> int MatchOpOr(const Source& source) const;
00054                 template <typename Source> int MatchOpAnd(const Source& source) const;
00055                 template <typename Source> int MatchOpNot(const Source& source) const;
00056                 template <typename Source> int MatchOpSeq(const Source& source) const;
00057 
00058         private:
00059                 REGEX_OP m_op;
00060                 char m_a, m_z;
00061                 std::vector <RegEx> m_params;
00062         };
00063 }
00064 
00065 #include "regeximpl.h"
00066 
00067 #endif // REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:42