sipxportlib  Version 3.3
UtlRegex.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef _REGEX_H
12 #define _REGEX_H
13 
14 #include <string.h>
15 #include "utl/UtlString.h"
16 
17 // Forward declarations
18 struct real_pcre;
19 typedef struct real_pcre pcre;
20 struct pcre_extra;
21 
57 class RegEx
58 {
59  public:
60 
61 // ================================================================
64 
67  RegEx( const char * regex, //< the regular expression
68  int options = 0, //< any sum of PCRE options bits
69  unsigned long int maxDepth = MAX_RECURSION // see MAX_RECURSION
70  );
77  static const unsigned long int MAX_RECURSION;
101  RegEx( const RegEx& );
119  ~RegEx();
120 
122  int SubStrings(void) const;
135 
137 // ================================================================
145 
148  bool Search( const char * subject,
149  int len = -1,
150  int options = 0
151  );
161  bool SearchAt(const char* subject,
163  int offset,
164  int len = -1,
165  int options = 0
166  );
181  bool SearchAgain( int options = 0
183  );
203 // ================================================================
219 
222  int Matches();
240  bool MatchString(UtlString* matched,
246  int i = 0
251  );
273  bool Match(const int i,
275  int& offset,
276  int& length
277  );
313  int MatchStart(const int i
315  );
341 
343  bool BeforeMatchString(UtlString* before
348  );
366  bool AfterMatchString(UtlString* before
372  );
390  int AfterMatch(int i
392  );
412  const char * Match(int i = 0 );
429 
431  private:
432  /*
433  * Use the copy constructor above instead of the = operator.
434  */
435  RegEx& operator=(const char *);
436 
437  void ClearMatchList(void);
438 
439  pcre * re;
440  size_t re_size;
441  pcre_extra * pe;
442  bool allocated_study;
443  size_t study_size;
444  int substrcount; // maximum substrings in pattern
445  const char * subjectStr; // original subject
446  int subjectLen; // original length
447  int lastStart; // offset of start for most recent Search or SearchAgain
448  int lastMatches; // pcre_exec return for most recent Search or SearchAgain
449  int * ovector; // results from (and workspace for) pcre_exec
450  const char * * matchlist;// string cache for Match
451 };
452 
453 #endif // _REGEX_H
~RegEx()
Definition: UtlRegex.cpp:140
bool Search(const char *subject, int len=-1, int options=0)
Search a string for matches to this regular expression.
Definition: UtlRegex.cpp:165
int Matches()
Get the maximum substring value from the most recent search.
Definition: UtlRegex.cpp:222
int SubStrings(void) const
Count the number of possible substrings returned by this expression.
Definition: UtlRegex.cpp:159
struct real_pcre pcre
Definition: UtlRegex.h:19
bool SearchAt(const char *subject, int offset, int len=-1, int options=0)
Search a string starting at some offset for matches to this regular expression.
Definition: UtlRegex.cpp:178
static const unsigned long int MAX_RECURSION
Default maximum for the recursion depth in searches.
Definition: UtlRegex.h:78
int MatchStart(const int i)
Get the position of a match in the subject.
Definition: UtlRegex.cpp:376
bool MatchString(UtlString *matched, int i=0)
Append a match from the last search operation to a UtlString.
Definition: UtlRegex.cpp:302
bool SearchAgain(int options=0)
Repeat the last search operation, starting immediately after the previous match.
Definition: UtlRegex.cpp:199
Definition: UtlRegex.h:57
Definition: UtlString.h:48
int AfterMatch(int i)
Get the offset of the first character past the matched value.
Definition: UtlRegex.cpp:267
RegEx(const char *regex, int options=0, unsigned long int maxDepth=MAX_RECURSION)
Compile a regular expression to create the matching object.
Definition: UtlRegex.cpp:39
bool AfterMatchString(UtlString *before)
Append string following the most recently matched value to a UtlString.
Definition: UtlRegex.cpp:282
bool BeforeMatchString(UtlString *before)
Append string preceeding the most recently matched value to a UtlString.
Definition: UtlRegex.cpp:246
bool Match(const int i, int &offset, int &length)
Get the position and length of a match in the subject.
Definition: UtlRegex.cpp:341