~ubuntu-branches/ubuntu/intrepid/dansguardian/intrepid-security

« back to all changes in this revision

Viewing changes to src/RegExp.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt
  • Date: 2008-04-06 14:47:06 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080406144706-2r26l1rougdmb1sd
Tags: 2.9.9.3-2
This time build with gcc 4.3 (Closes: #454889) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// RegExp class - search text using regular expressions
 
2
 
 
3
//Please refer to http://dansguardian.org/?page=copyright2
 
4
//for the license for this code.
 
5
//Written by Daniel Barron (daniel@// jadeb.com).
 
6
//For support go to http://groups.yahoo.com/group/dansguardian
 
7
 
 
8
//  This program is free software; you can redistribute it and/or modify
 
9
//  it under the terms of the GNU General Public License as published by
 
10
//  the Free Software Foundation; either version 2 of the License, or
 
11
//  (at your option) any later version.
 
12
//
 
13
//  This program 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 General Public License for more details.
 
17
//
 
18
//  You should have received a copy of the GNU General Public License
 
19
//  along with this program; if not, write to the Free Software
 
20
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 
 
22
#ifndef __HPP_REGEXP
 
23
#define __HPP_REGEXP
 
24
 
 
25
 
 
26
// INCLUDES
 
27
 
 
28
#include "platform.h"
 
29
 
 
30
#include <sys/types.h>          // needed for size_t used in regex.h
 
31
 
 
32
#ifdef __PCRE
 
33
#include <pcreposix.h>
 
34
#else
 
35
#include <regex.h>
 
36
#endif
 
37
 
 
38
#include <string>
 
39
#include <deque>
 
40
 
 
41
#ifdef __GCCVER3
 
42
using namespace std;
 
43
#endif
 
44
 
 
45
 
 
46
// DECLARATIONS
 
47
 
 
48
class RegExp
 
49
{
 
50
public:
 
51
        // constructor - set sensible defaults
 
52
        RegExp();
 
53
        // destructor - delete regexp if compiled
 
54
        ~RegExp();
 
55
        // copy constructor
 
56
        RegExp(const RegExp & r);
 
57
        
 
58
        // compile the given regular expression
 
59
        bool comp(const char *exp);
 
60
        // match the given text against the pre-compiled expression
 
61
        bool match(const char *text);
 
62
        
 
63
        // how many matches did the last run generate?
 
64
        int numberOfMatches();
 
65
        // did it generate any at all?
 
66
        bool matched();
 
67
        
 
68
        // the i'th match from the last run
 
69
        std::string result(int i);
 
70
        // position of the i'th match in the overall text
 
71
        unsigned int offset(int i);
 
72
        // length of the i'th match
 
73
        unsigned int length(int i);
 
74
        
 
75
        // faster equivalent of STL::Search
 
76
        char *search(char *file, char *fileend, char *phrase, char *phraseend);
 
77
 
 
78
private:
 
79
        // the match results, their positions in the text & their lengths
 
80
        std::deque<std::string> results;
 
81
        std::deque<unsigned int> offsets;
 
82
        std::deque<unsigned int> lengths;
 
83
 
 
84
        // have we matched something yet?
 
85
        bool imatched;
 
86
 
 
87
        // the expression itself
 
88
        regex_t reg;
 
89
        // whether it's been pre-compiled
 
90
        bool wascompiled;
 
91
        
 
92
        // the uncompiled form of the expression (checkme: is this only used
 
93
        // for debugging purposes?)
 
94
        std::string searchstring;
 
95
};
 
96
 
 
97
#endif