*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tsearch/regis.c,v 1.3 2008/01/01 19:45:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tsearch/regis.c,v 1.4 2008/01/21 02:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "tsearch/dicts/regis.h"
#include "tsearch/ts_locale.h"
+#define RS_IN_ONEOF 1
+#define RS_IN_ONEOF_IN 2
+#define RS_IN_NONEOF 3
+#define RS_IN_WAIT 4
+
+
+/*
+ * Test whether a regex is of the subset supported here.
+ * Keep this in sync with RS_compile!
+ */
bool
RS_isRegis(const char *str)
{
- while (str && *str)
+ int state = RS_IN_WAIT;
+ const char *c = str;
+
+ while (*c)
{
- if (t_isalpha(str) ||
- t_iseq(str, '[') ||
- t_iseq(str, ']') ||
- t_iseq(str, '^'))
- str += pg_mblen(str);
+ if (state == RS_IN_WAIT)
+ {
+ if (t_isalpha(c))
+ /* okay */ ;
+ else if (t_iseq(c, '['))
+ state = RS_IN_ONEOF;
+ else
+ return false;
+ }
+ else if (state == RS_IN_ONEOF)
+ {
+ if (t_iseq(c, '^'))
+ state = RS_IN_NONEOF;
+ else if (t_isalpha(c))
+ state = RS_IN_ONEOF_IN;
+ else
+ return false;
+ }
+ else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
+ {
+ if (t_isalpha(c))
+ /* okay */ ;
+ else if (t_iseq(c, ']'))
+ state = RS_IN_WAIT;
+ else
+ return false;
+ }
else
- return false;
+ elog(ERROR, "internal error in RS_isRegis: state %d", state);
+ c += pg_mblen(c);
}
- return true;
-}
-#define RS_IN_ONEOF 1
-#define RS_IN_ONEOF_IN 2
-#define RS_IN_NONEOF 3
-#define RS_IN_WAIT 4
+ return (state == RS_IN_WAIT);
+}
static RegisNode *
newRegisNode(RegisNode *prev, int len)
}
void
-RS_compile(Regis *r, bool issuffix, char *str)
+RS_compile(Regis *r, bool issuffix, const char *str)
{
int len = strlen(str);
int state = RS_IN_WAIT;
- char *c = (char *) str;
+ const char *c = str;
RegisNode *ptr = NULL;
memset(r, 0, sizeof(Regis));
ptr->type = RSF_ONEOF;
state = RS_IN_ONEOF;
}
- else
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
- errmsg("invalid regis pattern: \"%s\"",
- str)));
+ else /* shouldn't get here */
+ elog(ERROR, "invalid regis pattern: \"%s\"", str);
}
else if (state == RS_IN_ONEOF)
{
ptr->len = pg_mblen(c);
state = RS_IN_ONEOF_IN;
}
- else
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
- errmsg("invalid regis pattern: \"%s\"",
- str)));
+ else /* shouldn't get here */
+ elog(ERROR, "invalid regis pattern: \"%s\"", str);
}
else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
{
}
else if (t_iseq(c, ']'))
state = RS_IN_WAIT;
- else
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
- errmsg("invalid regis pattern: \"%s\"",
- str)));
+ else /* shouldn't get here */
+ elog(ERROR, "invalid regis pattern: \"%s\"", str);
}
else
elog(ERROR, "internal error in RS_compile: state %d", state);
c += pg_mblen(c);
}
+ if (state != RS_IN_WAIT) /* shouldn't get here */
+ elog(ERROR, "invalid regis pattern: \"%s\"", str);
+
ptr = r->node;
while (ptr)
{
*
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/include/tsearch/dicts/regis.h,v 1.4 2008/01/01 19:45:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/tsearch/dicts/regis.h,v 1.5 2008/01/21 02:46:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool RS_isRegis(const char *str);
-void RS_compile(Regis *r, bool issuffix, char *str);
+void RS_compile(Regis *r, bool issuffix, const char *str);
void RS_free(Regis *r);
/*returns true if matches */