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)
681 errmsg(
"invalid regular expression option: \"%.*s\"",
683 errhint(
"If you meant to use regexp_replace() with a start parameter, cast the fourth argument to integer explicitly.")));
690 0, flags.
glob ? 0 : 1));
717 errmsg(
"invalid value for parameter \"%s\": %d",
726 errmsg(
"invalid value for parameter \"%s\": %d",
735 n = re_flags.
glob ? 0 : 1;
804 errmsg(
"invalid escape string"),
805 errhint(
"Escape string must be empty or one character.")));
896 else if (
e &&
elen == mblen &&
memcmp(
e, p, mblen) == 0)
951 errmsg(
"SQL regular expression may not contain more than two escape-double-quote separators")));
999 else if (
pchar ==
'[')
1011 else if (
pchar ==
'^')
1034 else if (
pchar ==
'[')
1041 else if (
pchar ==
'%')
1046 else if (
pchar ==
'_')
1048 else if (
pchar ==
'(')
1154 errmsg(
"invalid value for parameter \"%s\": %d",
1165 errmsg(
"%s does not support the \"global\" option",
1166 "regexp_count()")));
1168 re_flags.
glob =
true;
1218 errmsg(
"invalid value for parameter \"%s\": %d",
1227 errmsg(
"invalid value for parameter \"%s\": %d",
1236 errmsg(
"invalid value for parameter \"%s\": %d",
1245 errmsg(
"invalid value for parameter \"%s\": %d",
1256 errmsg(
"%s does not support the \"global\" option",
1257 "regexp_instr()")));
1259 re_flags.
glob =
true;
1276 pos = (n - 1) *
matchctx->npatterns;
1283 if (
matchctx->match_locs[pos] >= 0)
1343 errmsg(
"%s does not support the \"global\" option",
1382 errmsg(
"%s does not support the \"global\" option",
1384 errhint(
"Use the regexp_matches function instead.")));
1435 true,
false,
false);
1519 cflags = re_flags->
cflags;
1546 array_len = re_flags->
glob ? 255 : 31;
1568 array_len += array_len + 1;
1572 errmsg(
"too many regular expression matches")));
1574 sizeof(
int) * array_len);
1584 int so = pmatch[
i].rm_so;
1585 int eo = pmatch[
i].rm_eo;
1589 if (
so >= 0 &&
eo >= 0 && (
eo -
so) > maxlen)
1595 int so = pmatch[0].rm_so;
1596 int eo = pmatch[0].rm_eo;
1600 if (
so >= 0 &&
eo >= 0 && (
eo -
so) > maxlen)
1611 pmatch[0].rm_so >= 0 &&
1619 if (!re_flags->
glob)
1629 if (pmatch[0].rm_so == pmatch[0].rm_eo)
1667 conv_bufsiz =
maxsiz + 1;
1670 matchctx->conv_bufsiz = conv_bufsiz;
1709 if (
so < 0 ||
eo < 0)
1770 errmsg(
"%s does not support the \"global\" option",
1771 "regexp_split_to_table()")));
1773 re_flags.
glob =
true;
1825 errmsg(
"%s does not support the \"global\" option",
1826 "regexp_split_to_array()")));
1828 re_flags.
glob =
true;
1874 elog(
ERROR,
"invalid match ending position");
1878 elog(
ERROR,
"invalid match starting position");
1925 errmsg(
"invalid value for parameter \"%s\": %d",
1934 errmsg(
"invalid value for parameter \"%s\": %d",
1943 errmsg(
"invalid value for parameter \"%s\": %d",
1954 errmsg(
"%s does not support the \"global\" option",
1955 "regexp_substr()")));
1957 re_flags.
glob =
true;
1974 pos = (n - 1) *
matchctx->npatterns;
1981 if (
so < 0 ||
eo < 0)
2068 errmsg(
"regular expression failed: %s", errMsg)));
2074 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_mblen_range(const char *mbstr, const char *end)
int pg_database_encoding_max_length(void)
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
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
const unsigned char * pend
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)