| 60 | \*---------------------------------------------------------------------------*/ |
| 61 | |
| 62 | class regExp |
| 63 | { |
| 64 | // Private data |
| 65 | |
| 66 | //- Precompiled regular expression |
| 67 | mutable regex_t* preg_; |
| 68 | |
| 69 | |
| 70 | // Private Member Functions |
| 71 | |
| 72 | //- Disallow default bitwise copy construct |
| 73 | regExp(const regExp&); |
| 74 | |
| 75 | //- Disallow default bitwise assignment |
| 76 | void operator=(const regExp&); |
| 77 | |
| 78 | //- Return true if it matches and sets the sub-groups matched. |
| 79 | // Templated to support both std::string and Foam::string |
| 80 | template<class StringType> |
| 81 | bool matchGrouping |
| 82 | ( |
| 83 | const std::string&, |
| 84 | List<StringType>& groups |
| 85 | ) const; |
| 86 | |
| 87 | |
| 88 | public: |
| 89 | |
| 90 | // Static Member Functions |
| 91 | |
| 92 | //- Is character a regular expression meta-character? |
| 93 | // any character: '.' \n |
| 94 | // quantifiers: '*', '+', '?' \n |
| 95 | // grouping: '(', '|', ')' \n |
| 96 | // range: '[', ']' \n |
| 97 | // |
| 98 | // Don't bother checking for '{digit}' bounds |
| 99 | inline static bool meta(char c) |
| 100 | { |
| 101 | return |
| 102 | ( |
| 103 | (c == '.') // any character |
| 104 | || (c == '*' || c == '+' || c == '?') // quantifiers |
| 105 | || (c == '(' || c == ')' || c == '|') // grouping/branching |
| 106 | || (c == '[' || c == ']') // range |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | // Constructors |
| 112 | |
| 113 | //- Construct null |
| 114 | regExp(); |
| 115 | |
| 116 | //- Construct from character array, optionally ignoring case |
| 117 | regExp(const char*, const bool ignoreCase=false); |
| 118 | |
| 119 | //- Construct from std::string (or string), optionally ignoring case |