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,2024 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  Words = 512,
91 
93  NotBol = 1024,
94  NotEol = 2048
95  };
96 
98  enum Error {
99  ErrOK = 0,
100  ErrEmpty = 1,
101  ErrMore = 2,
102  ErrParent = 3,
103  ErrBracket = 4,
104  ErrBrace = 5,
105  ErrRange = 6,
106  ErrEscape = 7,
107  ErrCount = 8,
108  ErrNoAtom = 9,
109  ErrRepeat = 10,
110  ErrBackRef = 11,
111  ErrClass = 12,
112  ErrComplex = 13,
113  ErrMemory = 14,
114  ErrToken = 15,
115  ErrLong = 16,
116  ErrSupport = 17
117  };
118 
119 public:
120 
125  FXRex();
126 
130  FXRex(const FXRex& orig);
131 
133  FXRex(const FXchar* pattern,FXint mode=Normal,Error* error=nullptr);
134 
136  FXRex(const FXString& pattern,FXint mode=Normal,Error* error=nullptr);
137 
143  FXbool empty() const { return code.empty(); }
144 
152  Error parse(const FXchar* pattern,FXint mode=Normal);
153  Error parse(const FXString& pattern,FXint mode=Normal);
154 
161  FXbool amatch(const FXchar* string,FXint len,FXint pos=0,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
162  FXbool amatch(const FXString& string,FXint pos=0,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
163 
164 
173  FXint search(const FXchar* string,FXint len,FXint fm,FXint to,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
174  FXint search(const FXString& string,FXint fm,FXint to,FXint mode=Normal,FXint* beg=nullptr,FXint* end=nullptr,FXint npar=0) const;
175 
185  static FXString substitute(const FXchar* string,FXint len,FXint* beg,FXint* end,const FXchar* replace,FXint npar=1);
186  static FXString substitute(const FXchar* string,FXint len,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
187  static FXString substitute(const FXString& string,FXint* beg,FXint* end,const FXchar* replace,FXint npar=1);
188  static FXString substitute(const FXString& string,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
189 
191  static const FXchar* getError(Error err){ return errors[err]; }
192 
194  FXRex& operator=(const FXRex& orig);
195 
197  FXbool operator==(const FXRex& rex) const;
198  FXbool operator!=(const FXRex& rex) const;
199 
204  static FXString escape(const FXString& str);
205 
207  friend FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
208  friend FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
209 
213  void clear();
214 
216  ~FXRex();
217  };
218 
219 
220 // Serialization
221 extern FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
222 extern FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
223 
224 }
225 
226 #endif
Error
Regular expression error codes.
Definition: FXRex.h:98
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:143
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:191
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp