64 bool use_subpatterns);
187 pg_regerror(regcomp_result, result_re, errMsg,
sizeof(errMsg));
189 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
190 errmsg(
"invalid regular expression: %s", errMsg)));
213 for (
int i = 0;
i < nmatch;
i++)
215 pmatch[
i].rm_so = -1;
216 pmatch[
i].rm_eo = -1;
232 pg_regerror(regexec_result, re, errMsg,
sizeof(errMsg));
234 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
235 errmsg(
"regular expression failed: %s", errMsg)));
238 return (regexec_result ==
REG_OKAY);
266 for (
i = 0;
i < opt_len;
i++)
414 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
415 errmsg(
"invalid regular expression test option: \"%.*s\"",
437 bool use_subpatterns)
464 if (use_subpatterns && cpattern->re_nsub > 0)
466 matchctx->
npatterns = cpattern->re_nsub + 1;
467 pmatch_len = cpattern->re_nsub + 1;
471 use_subpatterns =
false;
485 array_len = re_flags->
glob ? 255 : 31;
499 while (array_idx + matchctx->
npatterns * 2 + 1 > array_len)
501 array_len += array_len + 1;
504 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
505 errmsg(
"too many regular expression matches")));
507 sizeof(
int) * array_len);
513 int so = pmatch[
i].rm_so;
514 int eo = pmatch[
i].rm_eo;
518 if (so >= 0 && eo >= 0 && (eo - so) > maxlen)
522 prev_match_end = pmatch[0].rm_eo;
534 start_search = prev_match_end;
535 if (pmatch[0].rm_so == pmatch[0].rm_eo)
537 if (start_search > wide_len)
548 while (array_idx + matchctx->
npatterns * 2 + 1 > array_len)
550 array_len += array_len + 1;
553 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
554 errmsg(
"too many regular expression matches")));
556 sizeof(
int) * array_len);
570 Assert(array_idx <= array_len);
574 int64 maxsiz = eml * (int64) maxlen;
587 if (maxsiz > orig_len)
588 conv_bufsiz = orig_len + 1;
590 conv_bufsiz = maxsiz + 1;
625 static const struct infoname infonames[] = {
642 const struct infoname *inf;
654 for (inf = infonames; inf->bit != 0; inf++)
656 if (cpattern->re_info & inf->bit)
658 if (flags->
info & inf->bit)
668 if (flags->
info & inf->bit)
681 TEXTOID, -1,
false, TYPALIGN_INT);
695 bool *nulls = matchctx->
nulls;
713 snprintf(bufstr,
sizeof(bufstr),
"%d %d",
714 so, so < 0 ? eo : eo - 1);
718 else if (so < 0 || eo < 0)
729 Assert(len < matchctx->conv_bufsiz);
749 snprintf(bufstr,
sizeof(bufstr),
"%d %d",
750 so, so < 0 ? eo : eo - 1);
761 TEXTOID, -1,
false, TYPALIGN_INT);
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
#define Assert(condition)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_GETARG_TEXT_PP(n)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_GET_COLLATION()
#define PG_GETARG_TEXT_P_COPY(n)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
#define SRF_RETURN_DONE(_funcctx)
if(TABLE==NULL||TABLE_index==NULL)
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 pfree(void *pointer)
void * palloc0(Size size)
void * repalloc(void *pointer, Size size)
static AmcheckOptions opts
static Datum PointerGetDatum(const void *X)
static Datum Int32GetDatum(int32 X)
MemoryContextSwitchTo(old_ctx)
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)
void pg_regfree(regex_t *re)
MemoryContext multi_call_memory_ctx
PG_FUNCTION_INFO_V1(test_regex)
struct test_re_flags test_re_flags
static test_regex_ctx * setup_test_matches(text *orig_str, regex_t *cpattern, test_re_flags *re_flags, Oid collation, bool use_subpatterns)
static void test_re_compile(text *text_re, int cflags, Oid collation, regex_t *result_re)
struct test_regex_ctx test_regex_ctx
static ArrayType * build_test_match_result(test_regex_ctx *matchctx)
static bool test_re_execute(regex_t *re, pg_wchar *data, int data_len, int start_search, rm_detail_t *details, int nmatch, regmatch_t *pmatch, int eflags)
Datum test_regex(PG_FUNCTION_ARGS)
static void parse_test_flags(test_re_flags *flags, text *opts)
static ArrayType * build_test_info_result(regex_t *cpattern, test_re_flags *flags)
#define VARSIZE_ANY_EXHDR(PTR)
Datum bit(PG_FUNCTION_ARGS)
Datum text_substr(PG_FUNCTION_ARGS)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)