1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#ifndef TNet_StkMatch_h
#define TNet_StkMatch_h
#include <string>
namespace TNet
{
/*
EPSHeader
File: filmatch.h
Author: J. Kercheval
Created: Thu, 03/14/1991 22:24:34
*/
/*
EPSRevision History
O. Glembek Thu, 03/11/2005 01:58:00 Added Mask extraction support (char % does this)
J. Kercheval Wed, 02/20/1991 22:28:37 Released to Public Domain
J. Kercheval Sun, 03/10/1991 18:02:56 add is_valid_pattern
J. Kercheval Sun, 03/10/1991 18:25:48 add error_type in is_valid_pattern
J. Kercheval Sun, 03/10/1991 18:47:47 error return from matche()
J. Kercheval Tue, 03/12/1991 22:24:49 Released as V1.1 to Public Domain
J. Kercheval Thu, 03/14/1991 22:25:00 remove '\' for DOS file matching
J. Kercheval Thu, 03/28/1991 21:03:59 add in PATTERN_ESC & MATCH_LITERAL
*/
/*
Wildcard Pattern Matching
*/
/* match defines */
#define MATCH_PATTERN 6 /* bad pattern */
#define MATCH_LITERAL 5 /* match failure on literal match */
#define MATCH_RANGE 4 /* match failure on [..] construct */
#define MATCH_ABORT 3 /* premature end of text string */
#define MATCH_END 2 /* premature end of pattern string */
#define MATCH_VALID 1 /* valid match */
/* pattern defines */
#define PATTERN_VALID 0 /* valid pattern */
#define PATTERN_ESC -1 /* literal escape at end of pattern */
#define PATTERN_RANGE -2 /* malformed range in [..] construct */
#define PATTERN_CLOSE -3 /* no end bracket in [..] construct */
#define PATTERN_EMPTY -4 /* [..] contstruct is empty */
/*----------------------------------------------------------------------------
*
* Match the pattern PATTERN against the string TEXT;
*
* match() returns TRUE if pattern matches, FALSE otherwise.
* matche() returns MATCH_VALID if pattern matches, or an errorcode
* as follows otherwise:
*
* MATCH_PATTERN - bad pattern
* MATCH_RANGE - match failure on [..] construct
* MATCH_ABORT - premature end of text string
* MATCH_END - premature end of pattern string
* MATCH_VALID - valid match
*
*
* A match means the entire string TEXT is used up in matching.
*
* In the pattern string:
* `*' matches any sequence of characters (zero or more)
* `?' matches any character
* [SET] matches any character in the specified set,
* [!SET] or [^SET] matches any character not in the specified set.
*
* A set is composed of characters or ranges; a range looks like
* character hyphen character (as in 0-9 or A-Z). [0-9a-zA-Z_] is the
* minimal set of characters allowed in the [..] pattern construct.
* Other characters are allowed (ie. 8 bit characters) if your system
* will support them.
*
* To suppress the special syntactic significance of any of `[]*?!^-\',
* in a [..] construct and match the character exactly, precede it
* with a `\'.
*
----------------------------------------------------------------------------*/
bool
match (const char *pattern, const char *text, char *s);
int
matche(register const char *pattern, register const char *text, register char *s);
/*----------------------------------------------------------------------------
*
* Return TRUE if PATTERN has any special wildcard characters
*
----------------------------------------------------------------------------*/
bool
is_pattern (const char *pattern);
/** --------------------------------------------------------------------------
*
* Return TRUE if PATTERN has is a well formed regular expression according
* to the above syntax
*
* error_type is a return code based on the type of pattern error. Zero is
* returned in error_type if the pattern is a valid one. error_type return
* values are as follows:
*
* PATTERN_VALID - pattern is well formed
* PATTERN_RANGE - [..] construct has a no end range in a '-' pair (ie [a-])
* PATTERN_CLOSE - [..] construct has no end bracket (ie [abc-g )
* PATTERN_EMPTY - [..] construct is empty (ie [])
* --------------------------------------------------------------------------
**/
bool
is_valid_pattern (const char *pattern, int *error_type);
//****************************************************************************
//****************************************************************************
bool
ProcessMask(const std::string & rString, const std::string & rWildcard,
std::string & rSubstr);
}
#endif
|