jbeuhler-flexelint-bugs-found-20031128
[openafs.git] / src / WINNT / afsapplib / regexp.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #ifndef REGEXP_H
11 #define REGEXP_H
12
13 #ifndef EXPORTED
14 #define EXPORTED
15 #endif
16
17 /*
18  * This class (hopefully) makes it easy to use regular-expression pattern
19  * matching. As an example, you can do the following:
20  *
21  *    LPREGEXP pExpr = new REGEXP (TEXT("sl[ia]p-h.ppy$"));
22  *    if (pExpr->Matches (TEXT("slap-happy")))
23  *       ...
24  *    else if (pExpr->Matches (TEXT("slip-hoppy")))
25  *       ...
26  *    else if (!pExpr->Matches (TEXT("slug-hoppy")))
27  *       ...
28  *    delete pExpr;
29  *
30  * As a convenience, you can also use a simpler, more limited interface...
31  *
32  *    if (REGEXP::Matches (TEXT("sl[ia]p-h.ppy$"), TEXT("slug-hoppy")))
33  *       ...
34  *
35  * You can also test a string to see if it looks like a regular expression:
36  *
37  *    LPREGEXP pExpr = new REGEXP (TEXT("ab[cC]d"));
38  *    if (pExpr->fIsRegExp())
39  *       ...
40  *    if (!REGEXP::fIsRegExp (TEXT("testing")))
41  *       ...
42  *
43  */
44
45 /*
46  * DEFINITIONS ________________________________________________________________
47  *
48  */
49
50 #define cchCOMPILED_BUFFER_MAX     512
51 #define nCOMPILED_PARENS_MAX         9    // "\1" through "\9"
52
53 typedef class EXPORTED REGEXP REGEXP, *LPREGEXP;
54
55 class EXPORTED REGEXP
56    {
57    public:
58       REGEXP (void);
59       REGEXP (LPCTSTR pszExpr);
60       ~REGEXP (void);
61
62       BOOL SetExpression (LPCTSTR pszExpr);
63
64       BOOL Matches (LPCTSTR pszString);
65       static BOOL Matches (LPCTSTR pszExpr, LPCTSTR pszString);
66
67       BOOL fIsRegExp (void);
68       static BOOL fIsRegExp (LPCTSTR pszExpr);
69
70    private:
71       BOOL Compile (LPCTSTR pszExpr);
72       BOOL MatchSubset (LPCTSTR pszString, LPCTSTR pchCompiled, LPCTSTR *aParenStarts, LPCTSTR *aParenEnds);
73       BOOL CompareParen (int ii, LPCTSTR pszString, LPCTSTR *aParenStarts, LPCTSTR *aParenEnds);
74       BOOL fIsInCharSet (LPCTSTR pszCharSet, TCHAR chTest, int fInclusive);
75
76       BOOL m_fMatchFromStart;
77       TCHAR m_achCompiled[ cchCOMPILED_BUFFER_MAX ];
78    };
79
80
81 #endif
82