libcommonc++  0.7
RegExp.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_RegExp_hxx
24 #define __ccxx_RegExp_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/String.h++>
28 
29 #include <sys/types.h>
30 
31 namespace ccxx {
32 
40 {
41  friend class RegExp;
42 
43  public:
44 
47  : rm_so(-1), rm_eo(-1)
48  { }
49 
51  inline bool isValid() const
52  { return(rm_so >= 0); }
53 
55  inline uint_t getStartIndex() const
56  { return(rm_so >= 0 ? rm_so : 0); }
57 
61  inline uint_t getEndIndex() const
62  { return((rm_eo >= 0) && (rm_so >= 0) ? rm_eo : 0); }
63 
64  private:
65 
66  int rm_so;
67  int rm_eo;
68 };
69 
76 {
77  public:
78 
80  RegExp();
81 
83  RegExp(const RegExp& other);
84 
86  ~RegExp();
87 
96  void setPattern(const char* pattern, bool caseInsensitive = false)
97  { setPattern(String(pattern), caseInsensitive); }
98 
107  void setPattern(const String& pattern, bool caseInsensitive = false);
108 
110  inline String getPattern() const
111  { return(_pattern); }
112 
114  inline String toString() const
115  { return(getPattern()); }
116 
124  bool match(const String& text) const;
125 
135  bool match(const String& text, RegExpMatch matches[], int numMatches) const;
136 
138  RegExp& operator=(const RegExp& other);
139 
141  inline bool isNull() const
142  { return(_pattern.isNull()); }
143 
145  inline bool operator!() const
146  { return(_pattern.isNull()); }
147 
154  static String escapeMeta(const String& text);
155 
156  private:
157 
158  String _pattern;
159  void *_regex;
160  bool _compiled;
161 };
162 
163 } // namespace ccxx
164 
165 #endif // __ccxx_RegExp_hxx
String getPattern() const
Get the regular expression pattern.
Definition: RegExp.h++:110
void setPattern(const char *pattern, bool caseInsensitive=false)
Set the regular expression pattern.
Definition: RegExp.h++:96
String toString() const
Get a String representation of the RegExp.
Definition: RegExp.h++:114
uint_t getEndIndex() const
Get the end index of the substring.
Definition: RegExp.h++:61
A regular expression.
Definition: RegExp.h++:75
bool operator!() const
Determine if this regular expression has a null pattern.
Definition: RegExp.h++:145
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
bool isNull() const
Determine if this regular expression has a null pattern.
Definition: RegExp.h++:141
RegExpMatch()
Constructor.
Definition: RegExp.h++:46
#define COMMONCPP_API
Definition: Common.h++:126
A regular expression substring match.
Definition: RegExp.h++:39
uint_t getStartIndex() const
Get the start index of the substring.
Definition: RegExp.h++:55
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
bool isValid() const
Determine if this match is valid.
Definition: RegExp.h++:51
Definition: AllocationMap.c++:25