40#define PG_GETARG_TEXT_PP_IF_EXISTS(_n) \
41 (PG_NARGS() > (_n) ? PG_GETARG_TEXT_PP(_n) : NULL)
95#define MAX_CACHED_RES 32
162 re_array[
i].cre_collation == collation &&
183 "RegexpCacheMemoryContext",
205 "RegexpMemoryContext",
223 errmsg(
"invalid regular expression: %s", errMsg)));
239 re_temp.cre_collation = collation;
304 errmsg(
"regular expression failed: %s", errMsg)));
359 int cflags,
Oid collation,
445 errmsg(
"invalid regular expression option: \"%.*s\"",
609 so = pmatch[1].rm_so;
610 eo = pmatch[1].rm_eo;
615 so = pmatch[0].rm_so;
616 eo = pmatch[0].rm_eo;
625 if (
so < 0 ||
eo < 0)
680 errmsg(
"invalid regular expression option: \"%.*s\"",
682 errhint(
"If you meant to use regexp_replace() with a start parameter, cast the fourth argument to integer explicitly.")));
689 0, flags.
glob ? 0 : 1));
716 errmsg(
"invalid value for parameter \"%s\": %d",
725 errmsg(
"invalid value for parameter \"%s\": %d",
734 n = re_flags.
glob ? 0 : 1;
801 errmsg(
"invalid escape string"),
802 errhint(
"Escape string must be empty or one character.")));
893 else if (
e &&
elen == mblen &&
memcmp(
e, p, mblen) == 0)
948 errmsg(
"SQL regular expression may not contain more than two escape-double-quote separators")));
996 else if (
pchar ==
'[')
1008 else if (
pchar ==
'^')
1031 else if (
pchar ==
'[')
1038 else if (
pchar ==
'%')
1043 else if (
pchar ==
'_')
1045 else if (
pchar ==
'(')
1151 errmsg(
"invalid value for parameter \"%s\": %d",
1162 errmsg(
"%s does not support the \"global\" option",
1163 "regexp_count()")));
1165 re_flags.
glob =
true;
1215 errmsg(
"invalid value for parameter \"%s\": %d",
1224 errmsg(
"invalid value for parameter \"%s\": %d",
1233 errmsg(
"invalid value for parameter \"%s\": %d",
1242 errmsg(
"invalid value for parameter \"%s\": %d",
1253 errmsg(
"%s does not support the \"global\" option",
1254 "regexp_instr()")));
1256 re_flags.
glob =
true;
1273 pos = (n - 1) *
matchctx->npatterns;
1280 if (
matchctx->match_locs[pos] >= 0)
1340 errmsg(
"%s does not support the \"global\" option",
1379 errmsg(
"%s does not support the \"global\" option",
1381 errhint(
"Use the regexp_matches function instead.")));
1432 true,
false,
false);
1516 cflags = re_flags->
cflags;
1543 array_len = re_flags->
glob ? 255 : 31;
1565 array_len += array_len + 1;
1569 errmsg(
"too many regular expression matches")));
1571 sizeof(
int) * array_len);
1581 int so = pmatch[
i].rm_so;
1582 int eo = pmatch[
i].rm_eo;
1586 if (
so >= 0 &&
eo >= 0 && (
eo -
so) > maxlen)
1592 int so = pmatch[0].rm_so;
1593 int eo = pmatch[0].rm_eo;
1597 if (
so >= 0 &&
eo >= 0 && (
eo -
so) > maxlen)
1608 pmatch[0].rm_so >= 0 &&
1616 if (!re_flags->
glob)
1626 if (pmatch[0].rm_so == pmatch[0].rm_eo)
1664 conv_bufsiz =
maxsiz + 1;
1667 matchctx->conv_bufsiz = conv_bufsiz;
1706 if (
so < 0 ||
eo < 0)
1767 errmsg(
"%s does not support the \"global\" option",
1768 "regexp_split_to_table()")));
1770 re_flags.
glob =
true;
1822 errmsg(
"%s does not support the \"global\" option",
1823 "regexp_split_to_array()")));
1825 re_flags.
glob =
true;
1871 elog(
ERROR,
"invalid match ending position");
1875 elog(
ERROR,
"invalid match starting position");
1922 errmsg(
"invalid value for parameter \"%s\": %d",
1931 errmsg(
"invalid value for parameter \"%s\": %d",
1940 errmsg(
"invalid value for parameter \"%s\": %d",
1951 errmsg(
"%s does not support the \"global\" option",
1952 "regexp_substr()")));
1954 re_flags.
glob =
true;
1971 pos = (n - 1) *
matchctx->npatterns;
1978 if (
so < 0 ||
eo < 0)
2065 errmsg(
"regular expression failed: %s", errMsg)));
2071 result = (
char *)
palloc(maxlen);
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
#define Assert(condition)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_array(type, count)
#define palloc0_object(type)
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_NAME(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_GET_COLLATION()
#define PG_GETARG_TEXT_P_COPY(n)
#define PG_RETURN_BOOL(x)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
#define SRF_RETURN_DONE(_funcctx)
int pg_mbstrlen_with_len(const char *mbstr, int limit)
int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len)
int pg_database_encoding_max_length(void)
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
int pg_mblen(const char *mbstr)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
#define AllocSetContextCreate
#define ALLOCSET_SMALL_SIZES
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static AmcheckOptions opts
static XLogRecPtr startpos
static char buf[DEFAULT_XLOG_SEG_SIZE]
static Datum PointerGetDatum(const void *X)
static Datum Int32GetDatum(int32 X)
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
int pg_regexec(regex_t *re, const chr *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
static MemoryContext RegexpCacheMemoryContext
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
Datum regexp_match_no_flags(PG_FUNCTION_ARGS)
Datum textregexreplace(PG_FUNCTION_ARGS)
Datum texticregexne(PG_FUNCTION_ARGS)
Datum regexp_substr_no_start(PG_FUNCTION_ARGS)
Datum regexp_split_to_array(PG_FUNCTION_ARGS)
Datum texticregexeq(PG_FUNCTION_ARGS)
Datum regexp_substr_no_n(PG_FUNCTION_ARGS)
Datum regexp_instr_no_subexpr(PG_FUNCTION_ARGS)
Datum similar_to_escape_2(PG_FUNCTION_ARGS)
bool RE_compile_and_execute(text *text_re, char *dat, int dat_len, int cflags, Oid collation, int nmatch, regmatch_t *pmatch)
char * regexp_fixed_prefix(text *text_re, bool case_insensitive, Oid collation, bool *exact)
static bool RE_wchar_execute(regex_t *re, pg_wchar *data, int data_len, int start_search, int nmatch, regmatch_t *pmatch)
Datum regexp_substr(PG_FUNCTION_ARGS)
Datum nameicregexne(PG_FUNCTION_ARGS)
Datum textregexsubstr(PG_FUNCTION_ARGS)
static Datum build_regexp_split_result(regexp_matches_ctx *splitctx)
Datum regexp_split_to_array_no_flags(PG_FUNCTION_ARGS)
Datum textregexreplace_extended_no_n(PG_FUNCTION_ARGS)
static regexp_matches_ctx * setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags, int start_search, Oid collation, bool use_subpatterns, bool ignore_degenerate, bool fetching_unmatched)
Datum nameregexne(PG_FUNCTION_ARGS)
Datum regexp_instr(PG_FUNCTION_ARGS)
static ArrayType * build_regexp_match_result(regexp_matches_ctx *matchctx)
Datum similar_to_escape_1(PG_FUNCTION_ARGS)
Datum regexp_substr_no_flags(PG_FUNCTION_ARGS)
Datum regexp_matches(PG_FUNCTION_ARGS)
#define PG_GETARG_TEXT_PP_IF_EXISTS(_n)
Datum nameicregexeq(PG_FUNCTION_ARGS)
Datum regexp_matches_no_flags(PG_FUNCTION_ARGS)
Datum regexp_split_to_table_no_flags(PG_FUNCTION_ARGS)
Datum regexp_match(PG_FUNCTION_ARGS)
Datum textregexreplace_extended(PG_FUNCTION_ARGS)
Datum nameregexeq(PG_FUNCTION_ARGS)
Datum regexp_instr_no_n(PG_FUNCTION_ARGS)
Datum regexp_count_no_start(PG_FUNCTION_ARGS)
static cached_re_str re_array[MAX_CACHED_RES]
static bool RE_execute(regex_t *re, char *dat, int dat_len, int nmatch, regmatch_t *pmatch)
static void parse_re_flags(pg_re_flags *flags, text *opts)
Datum regexp_split_to_table(PG_FUNCTION_ARGS)
Datum textregexreplace_noopt(PG_FUNCTION_ARGS)
Datum regexp_like_no_flags(PG_FUNCTION_ARGS)
Datum regexp_instr_no_flags(PG_FUNCTION_ARGS)
Datum textregexeq(PG_FUNCTION_ARGS)
Datum textregexne(PG_FUNCTION_ARGS)
Datum regexp_count_no_flags(PG_FUNCTION_ARGS)
Datum similar_escape(PG_FUNCTION_ARGS)
Datum regexp_instr_no_start(PG_FUNCTION_ARGS)
Datum regexp_instr_no_endoption(PG_FUNCTION_ARGS)
Datum textregexreplace_extended_no_flags(PG_FUNCTION_ARGS)
Datum regexp_like(PG_FUNCTION_ARGS)
Datum regexp_substr_no_subexpr(PG_FUNCTION_ARGS)
static text * similar_escape_internal(text *pat_text, text *esc_text)
Datum regexp_count(PG_FUNCTION_ARGS)
int pg_regprefix(regex_t *re, chr **string, size_t *slength)
MemoryContext cre_context
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
Datum text_substr(PG_FUNCTION_ARGS)
text * cstring_to_text_with_len(const char *s, int len)
text * replace_text_regexp(text *src_text, text *pattern_text, text *replace_text, int cflags, Oid collation, int search_start, int n)