7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $PostgreSQL: pgsql/src/backend/tsearch/regis.c,v 1.3 2008/01/01 19:45:52 momjian Exp $
10
+ * $PostgreSQL: pgsql/src/backend/tsearch/regis.c,v 1.4 2008/01/21 02:46:10 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
17
17
#include "tsearch/dicts/regis.h"
18
18
#include "tsearch/ts_locale.h"
19
19
20
+ #define RS_IN_ONEOF 1
21
+ #define RS_IN_ONEOF_IN 2
22
+ #define RS_IN_NONEOF 3
23
+ #define RS_IN_WAIT 4
24
+
25
+
26
+ /*
27
+ * Test whether a regex is of the subset supported here.
28
+ * Keep this in sync with RS_compile!
29
+ */
20
30
bool
21
31
RS_isRegis (const char * str )
22
32
{
23
- while (str && * str )
33
+ int state = RS_IN_WAIT ;
34
+ const char * c = str ;
35
+
36
+ while (* c )
24
37
{
25
- if (t_isalpha (str ) ||
26
- t_iseq (str , '[' ) ||
27
- t_iseq (str , ']' ) ||
28
- t_iseq (str , '^' ))
29
- str += pg_mblen (str );
38
+ if (state == RS_IN_WAIT )
39
+ {
40
+ if (t_isalpha (c ))
41
+ /* okay */ ;
42
+ else if (t_iseq (c , '[' ))
43
+ state = RS_IN_ONEOF ;
44
+ else
45
+ return false;
46
+ }
47
+ else if (state == RS_IN_ONEOF )
48
+ {
49
+ if (t_iseq (c , '^' ))
50
+ state = RS_IN_NONEOF ;
51
+ else if (t_isalpha (c ))
52
+ state = RS_IN_ONEOF_IN ;
53
+ else
54
+ return false;
55
+ }
56
+ else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF )
57
+ {
58
+ if (t_isalpha (c ))
59
+ /* okay */ ;
60
+ else if (t_iseq (c , ']' ))
61
+ state = RS_IN_WAIT ;
62
+ else
63
+ return false;
64
+ }
30
65
else
31
- return false;
66
+ elog (ERROR , "internal error in RS_isRegis: state %d" , state );
67
+ c += pg_mblen (c );
32
68
}
33
- return true;
34
- }
35
69
36
- #define RS_IN_ONEOF 1
37
- #define RS_IN_ONEOF_IN 2
38
- #define RS_IN_NONEOF 3
39
- #define RS_IN_WAIT 4
70
+ return (state == RS_IN_WAIT );
71
+ }
40
72
41
73
static RegisNode *
42
74
newRegisNode (RegisNode * prev , int len )
@@ -50,11 +82,11 @@ newRegisNode(RegisNode *prev, int len)
50
82
}
51
83
52
84
void
53
- RS_compile (Regis * r , bool issuffix , char * str )
85
+ RS_compile (Regis * r , bool issuffix , const char * str )
54
86
{
55
87
int len = strlen (str );
56
88
int state = RS_IN_WAIT ;
57
- char * c = ( char * ) str ;
89
+ const char * c = str ;
58
90
RegisNode * ptr = NULL ;
59
91
60
92
memset (r , 0 , sizeof (Regis ));
@@ -83,11 +115,8 @@ RS_compile(Regis *r, bool issuffix, char *str)
83
115
ptr -> type = RSF_ONEOF ;
84
116
state = RS_IN_ONEOF ;
85
117
}
86
- else
87
- ereport (ERROR ,
88
- (errcode (ERRCODE_INVALID_REGULAR_EXPRESSION ),
89
- errmsg ("invalid regis pattern: \"%s\"" ,
90
- str )));
118
+ else /* shouldn't get here */
119
+ elog (ERROR , "invalid regis pattern: \"%s\"" , str );
91
120
}
92
121
else if (state == RS_IN_ONEOF )
93
122
{
@@ -102,11 +131,8 @@ RS_compile(Regis *r, bool issuffix, char *str)
102
131
ptr -> len = pg_mblen (c );
103
132
state = RS_IN_ONEOF_IN ;
104
133
}
105
- else
106
- ereport (ERROR ,
107
- (errcode (ERRCODE_INVALID_REGULAR_EXPRESSION ),
108
- errmsg ("invalid regis pattern: \"%s\"" ,
109
- str )));
134
+ else /* shouldn't get here */
135
+ elog (ERROR , "invalid regis pattern: \"%s\"" , str );
110
136
}
111
137
else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF )
112
138
{
@@ -117,17 +143,17 @@ RS_compile(Regis *r, bool issuffix, char *str)
117
143
}
118
144
else if (t_iseq (c , ']' ))
119
145
state = RS_IN_WAIT ;
120
- else
121
- ereport (ERROR ,
122
- (errcode (ERRCODE_INVALID_REGULAR_EXPRESSION ),
123
- errmsg ("invalid regis pattern: \"%s\"" ,
124
- str )));
146
+ else /* shouldn't get here */
147
+ elog (ERROR , "invalid regis pattern: \"%s\"" , str );
125
148
}
126
149
else
127
150
elog (ERROR , "internal error in RS_compile: state %d" , state );
128
151
c += pg_mblen (c );
129
152
}
130
153
154
+ if (state != RS_IN_WAIT ) /* shouldn't get here */
155
+ elog (ERROR , "invalid regis pattern: \"%s\"" , str );
156
+
131
157
ptr = r -> node ;
132
158
while (ptr )
133
159
{
0 commit comments