Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXRex.h
1 /********************************************************************************
2 * *
3 * R e g u l a r E x p r e s s i o n C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1999,2026 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXREX_H
22 #define FXREX_H
23 
24 namespace FX {
25 
26 
67 class FXAPI FXRex {
68 private:
69  FXString code;
70 private:
71  static const FXchar *const errors[];
72 public:
73 
75  enum {
76 
78  Normal = 0,
79  Unicode = 1,
80 
82  Syntax = 2,
83  Verbatim = 4,
84  Capture = 8,
85  IgnoreCase = 16,
86  Newline = 32,
87  Exact = 64,
88  NotEmpty = 128,
89  Reverse = 256,
90  WordBeg = 512,
91  WordEnd = 1024,
92  Words = 1536,
93 
95  NotBol = 2048,
96  NotEol = 4096
97  };
98 
100  enum Error {
101  ErrOK = 0,
102  ErrEmpty = 1,
103  ErrMore = 2,
104  ErrParent = 3,
105  ErrBracket = 4,
106  ErrBrace = 5,
107  ErrRange = 6,
108  ErrEscape = 7,
109  ErrCount = 8,
110  ErrNoAtom = 9,
111  ErrRepeat = 10,
112  ErrBackRef = 11,
113  ErrClass = 12,
114  ErrComplex = 13,
115  ErrMemory = 14,
116  ErrToken = 15,
117  ErrLong = 16,
118  ErrSupport = 17
119  };
120 
121 public:
122 
127  FXRex();
128 
132  FXRex(const FXRex& orig);
133 
135  FXRex(const FXchar* pattern,FXint mode=Normal,Error* error=nullptr);
136 
138  FXRex(const FXString& pattern,FXint mode=Normal,Error* error=nullptr);
139 
145  FXbool empty() const { return code.empty(); }
146 
154  Error parse(const FXchar* pattern,FXint mode=Normal);
155  Error parse(const FXString& pattern,FXint mode=Normal);
156 
163  FXbool amatch(const FXchar* string,FXint len,FXint pos=0,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
164  FXbool amatch(const FXString& string,FXint pos=0,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
165 
166 
175  FXint search(const FXchar* string,FXint len,FXint fm,FXint to,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
176  FXint search(const FXString& string,FXint fm,FXint to,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
177 
187  static FXString substitute(const FXchar* string,FXint len,FXint* beg,FXint* end,const FXchar* replace,FXint npar=1);
188  static FXString substitute(const FXchar* string,FXint len,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
189  static FXString substitute(const FXString& string,FXint* beg,FXint* end,const FXchar* replace,FXint npar=1);
190  static FXString substitute(const FXString& string,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
191 
193  static const FXchar* getError(Error err){ return errors[err]; }
194 
196  FXRex& operator=(const FXRex& orig);
197 
199  FXbool operator==(const FXRex& rex) const;
200  FXbool operator!=(const FXRex& rex) const;
201 
206  static FXString escape(const FXString& str);
207 
209  friend FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
210  friend FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
211 
215  void clear();
216 
218  ~FXRex();
219  };
220 
221 
222 // Serialization
223 extern FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
224 extern FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
225 
226 }
227 
228 #endif
Error
Regular expression error codes.
Definition: FXRex.h:100
FXbool empty() const
See if regular expression is empty; the regular expression will be empty when it is unable to parse a...
Definition: FXRex.h:145
FXRex is a regular expression class implementing a NFA matcher.
Definition: FXRex.h:67
FXbool empty() const
See if string is empty.
Definition: FXString.h:125
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
Definition: FX4Splitter.h:28
static const FXchar * getError(Error err)
Returns error message text for a given error code.
Definition: FXRex.h:193
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2026 Jeroen van der Zijp