edelib  2.1.0
Regex.h
1 /*
2  * $Id: Regex.h 2839 2009-09-28 11:36:20Z karijes $
3  *
4  * Regex class
5  * Copyright (c) 2007-2009 edelib authors
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __EDELIB_REGEX_H__
22 #define __EDELIB_REGEX_H__
23 
24 #include "List.h"
25 #include "String.h"
26 
27 EDELIB_NS_BEGIN
28 
34 enum RegexMode {
35  RX_EXTENDED = (1 << 1),
36  RX_CASELESS = (1 << 2),
37  RX_DOLLAR_ENDONLY = (1 << 3),
38  RX_DOTALL = (1 << 4),
39  RX_MULTILINE = (1 << 5),
40  RX_UNGREEDY = (1 << 6)
41 };
42 
49  RX_MATCH_ANCHORED = (1 << 1),
50  RX_MATCH_NOTBOL = (1 << 2),
51  RX_MATCH_NOTEOL = (1 << 3),
52  RX_MATCH_NOTEMPTY = (1 << 4)
53 };
54 
55 #ifndef SKIP_DOCS
56 struct RegexData;
57 #endif
58 
65 struct RegexMatch {
67  int offset;
69  int length;
70 };
71 
98 class EDELIB_API Regex {
99 private:
100  RegexData* data;
101 
102  void clear(void);
104 public:
107 
111  Regex();
112 
116  ~Regex();
117 
125  bool compile(const char* pattern, int m = 0);
126 
136  operator bool(void) const;
137 
150  int match(const char* str, int match_mode, int start, int len, MatchVec* matches);
151 
156  int match(const char* str, int match_mode = 0, MatchVec* matches = 0)
157  { return match(str, match_mode, 0, -1, matches); }
158 
167  int split(const char* str, list<String>& ls, int match_mode = 0);
168 
172  const char* strerror(void) const;
173 };
174 
175 EDELIB_NS_END
176 #endif
int match(const char *str, int match_mode=0, MatchVec *matches=0)
Definition: Regex.h:156
Match only at the first position.
Definition: Regex.h:49
list< RegexMatch > MatchVec
Definition: Regex.h:106
^ and $ match newlines within data
Definition: Regex.h:39
$ not to match newline at end
Definition: Regex.h:37
Linked list class.
Definition: List.h:160
RegexMode
Flags used for compile()
Definition: Regex.h:34
RegexMatchMode
Flags used for match()
Definition: Regex.h:48
RegexMatch class.
Definition: Regex.h:65
Subject is not the end of a line.
Definition: Regex.h:51
extended features
Definition: Regex.h:35
int offset
Definition: Regex.h:67
int length
Definition: Regex.h:69
#define E_DISABLE_CLASS_COPY(klass)
Definition: edelib-global.h:161
Regex class.
Definition: Regex.h:98