PostgreSQL Source Code git master
Loading...
Searching...
No Matches
regis.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RegisNode
 
struct  Regis
 

Macros

#define RNHDRSZ   (offsetof(RegisNode,data))
 
#define RSF_ONEOF   1
 
#define RSF_NONEOF   2
 

Typedefs

typedef struct RegisNode RegisNode
 
typedef struct Regis Regis
 

Functions

bool RS_isRegis (const char *str)
 
void RS_compile (Regis *r, bool issuffix, const char *str)
 
void RS_free (Regis *r)
 
bool RS_execute (Regis *r, char *str)
 

Macro Definition Documentation

◆ RNHDRSZ

#define RNHDRSZ   (offsetof(RegisNode,data))

Definition at line 27 of file regis.h.

◆ RSF_NONEOF

#define RSF_NONEOF   2

Definition at line 30 of file regis.h.

◆ RSF_ONEOF

#define RSF_ONEOF   1

Definition at line 29 of file regis.h.

Typedef Documentation

◆ Regis

◆ RegisNode

Function Documentation

◆ RS_compile()

void RS_compile ( Regis r,
bool  issuffix,
const char str 
)
extern

Definition at line 85 of file regis.c.

86{
87 int len = strlen(str);
88 int state = RS_IN_WAIT;
89 const char *c = str;
90 RegisNode *ptr = NULL;
91
92 memset(r, 0, sizeof(Regis));
93 r->issuffix = (issuffix) ? 1 : 0;
94
95 while (*c)
96 {
97 if (state == RS_IN_WAIT)
98 {
99 if (t_isalpha_cstr(c))
100 {
101 if (ptr)
102 ptr = newRegisNode(ptr, len);
103 else
104 ptr = r->node = newRegisNode(NULL, len);
105 ptr->type = RSF_ONEOF;
106 ptr->len = ts_copychar_cstr(ptr->data, c);
107 }
108 else if (t_iseq(c, '['))
109 {
110 if (ptr)
111 ptr = newRegisNode(ptr, len);
112 else
113 ptr = r->node = newRegisNode(NULL, len);
114 ptr->type = RSF_ONEOF;
116 }
117 else /* shouldn't get here */
118 elog(ERROR, "invalid regis pattern: \"%s\"", str);
119 }
120 else if (state == RS_IN_ONEOF)
121 {
122 if (t_iseq(c, '^'))
123 {
124 ptr->type = RSF_NONEOF;
126 }
127 else if (t_isalpha_cstr(c))
128 {
129 ptr->len = ts_copychar_cstr(ptr->data, c);
131 }
132 else /* shouldn't get here */
133 elog(ERROR, "invalid regis pattern: \"%s\"", str);
134 }
135 else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
136 {
137 if (t_isalpha_cstr(c))
138 ptr->len += ts_copychar_cstr(ptr->data + ptr->len, c);
139 else if (t_iseq(c, ']'))
141 else /* shouldn't get here */
142 elog(ERROR, "invalid regis pattern: \"%s\"", str);
143 }
144 else
145 elog(ERROR, "internal error in RS_compile: state %d", state);
146 c += pg_mblen_cstr(c);
147 }
148
149 if (state != RS_IN_WAIT) /* shouldn't get here */
150 elog(ERROR, "invalid regis pattern: \"%s\"", str);
151
152 ptr = r->node;
153 while (ptr)
154 {
155 r->nchar++;
156 ptr = ptr->next;
157 }
158}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
const char * str
int pg_mblen_cstr(const char *mbstr)
Definition mbutils.c:1045
const void size_t len
char * c
static int fb(int x)
static RegisNode * newRegisNode(RegisNode *prev, int len)
Definition regis.c:74
#define RS_IN_WAIT
Definition regis.c:23
#define RS_IN_ONEOF_IN
Definition regis.c:21
#define RS_IN_ONEOF
Definition regis.c:20
#define RS_IN_NONEOF
Definition regis.c:22
#define RSF_ONEOF
Definition regis.h:29
#define RSF_NONEOF
Definition regis.h:30
unsigned char data[FLEXIBLE_ARRAY_MEMBER]
Definition regis.h:24
uint32 len
Definition regis.h:21
struct RegisNode * next
Definition regis.h:23
uint32 type
Definition regis.h:20
Definition regis.h:33
uint32 issuffix
Definition regis.h:36
RegisNode * node
Definition regis.h:34
uint32 nchar
Definition regis.h:37
static int ts_copychar_cstr(void *dest, const void *src)
Definition ts_locale.h:50
#define t_iseq(x, c)
Definition ts_locale.h:38

References RegisNode::data, elog, ERROR, fb(), Regis::issuffix, RegisNode::len, len, Regis::nchar, newRegisNode(), RegisNode::next, Regis::node, pg_mblen_cstr(), RS_IN_NONEOF, RS_IN_ONEOF, RS_IN_ONEOF_IN, RS_IN_WAIT, RSF_NONEOF, RSF_ONEOF, str, t_iseq, ts_copychar_cstr(), and RegisNode::type.

Referenced by NIAddAffix().

◆ RS_execute()

bool RS_execute ( Regis r,
char str 
)
extern

Definition at line 208 of file regis.c.

209{
210 RegisNode *ptr = r->node;
211 char *c = str;
212 int len = 0;
213
214 while (*c)
215 {
216 len++;
217 c += pg_mblen_cstr(c);
218 }
219
220 if (len < r->nchar)
221 return 0;
222
223 c = str;
224 if (r->issuffix)
225 {
226 len -= r->nchar;
227 while (len-- > 0)
228 c += pg_mblen_cstr(c);
229 }
230
231
232 while (ptr)
233 {
234 switch (ptr->type)
235 {
236 case RSF_ONEOF:
237 if (!mb_strchr((char *) ptr->data, c))
238 return false;
239 break;
240 case RSF_NONEOF:
241 if (mb_strchr((char *) ptr->data, c))
242 return false;
243 break;
244 default:
245 elog(ERROR, "unrecognized regis node type: %d", ptr->type);
246 }
247 ptr = ptr->next;
248 c += pg_mblen_cstr(c);
249 }
250
251 return true;
252}
static bool mb_strchr(char *str, char *c)
Definition regis.c:177

References RegisNode::data, elog, ERROR, fb(), Regis::issuffix, len, mb_strchr(), Regis::nchar, RegisNode::next, Regis::node, pg_mblen_cstr(), RSF_NONEOF, RSF_ONEOF, str, and RegisNode::type.

Referenced by CheckAffix().

◆ RS_free()

void RS_free ( Regis r)
extern

Definition at line 161 of file regis.c.

162{
163 RegisNode *ptr = r->node,
164 *tmp;
165
166 while (ptr)
167 {
168 tmp = ptr->next;
169 pfree(ptr);
170 ptr = tmp;
171 }
172
173 r->node = NULL;
174}
void pfree(void *pointer)
Definition mcxt.c:1616

References fb(), RegisNode::next, Regis::node, and pfree().

◆ RS_isRegis()

bool RS_isRegis ( const char str)
extern

Definition at line 31 of file regis.c.

32{
33 int state = RS_IN_WAIT;
34 const char *c = str;
35
36 while (*c)
37 {
38 if (state == RS_IN_WAIT)
39 {
40 if (t_isalpha_cstr(c))
41 /* okay */ ;
42 else if (t_iseq(c, '['))
44 else
45 return false;
46 }
47 else if (state == RS_IN_ONEOF)
48 {
49 if (t_iseq(c, '^'))
51 else if (t_isalpha_cstr(c))
53 else
54 return false;
55 }
56 else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
57 {
58 if (t_isalpha_cstr(c))
59 /* okay */ ;
60 else if (t_iseq(c, ']'))
62 else
63 return false;
64 }
65 else
66 elog(ERROR, "internal error in RS_isRegis: state %d", state);
67 c += pg_mblen_cstr(c);
68 }
69
70 return (state == RS_IN_WAIT);
71}

References elog, ERROR, fb(), pg_mblen_cstr(), RS_IN_NONEOF, RS_IN_ONEOF, RS_IN_ONEOF_IN, RS_IN_WAIT, str, and t_iseq.

Referenced by NIAddAffix().