PostgreSQL Source Code  git master
regex.h File Reference
#include "mb/pg_wchar.h"
Include dependency graph for regex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  regex_t
 
struct  regmatch_t
 
struct  rm_detail_t
 

Macros

#define _REGEX_H_   /* never again */
 
#define REG_UBACKREF   000001 /* has back-reference (\n) */
 
#define REG_ULOOKAROUND   000002 /* has lookahead/lookbehind constraint */
 
#define REG_UBOUNDS   000004 /* has bounded quantifier ({m,n}) */
 
#define REG_UBRACES   000010 /* has { that doesn't begin a quantifier */
 
#define REG_UBSALNUM   000020 /* has backslash-alphanumeric in non-ARE */
 
#define REG_UPBOTCH
 
#define REG_UBBS   000100 /* has backslash within bracket expr */
 
#define REG_UNONPOSIX   000200 /* has any construct that extends POSIX */
 
#define REG_UUNSPEC
 
#define REG_UUNPORT   001000 /* has numeric character code dependency */
 
#define REG_ULOCALE   002000 /* has locale dependency */
 
#define REG_UEMPTYMATCH   004000 /* can match a zero-length string */
 
#define REG_UIMPOSSIBLE   010000 /* provably cannot match anything */
 
#define REG_USHORTEST   020000 /* has non-greedy quantifier */
 
#define REG_BASIC   000000 /* BREs (convenience) */
 
#define REG_EXTENDED   000001 /* EREs */
 
#define REG_ADVF   000002 /* advanced features in EREs */
 
#define REG_ADVANCED   000003 /* AREs (which are also EREs) */
 
#define REG_QUOTE   000004 /* no special characters, none */
 
#define REG_NOSPEC   REG_QUOTE /* historical synonym */
 
#define REG_ICASE   000010 /* ignore case */
 
#define REG_NOSUB   000020 /* caller doesn't need subexpr match data */
 
#define REG_EXPANDED   000040 /* expanded format, white space & comments */
 
#define REG_NLSTOP   000100 /* \n doesn't match . or [^ ] */
 
#define REG_NLANCH   000200 /* ^ matches after \n, $ before */
 
#define REG_NEWLINE   000300 /* newlines are line terminators */
 
#define REG_PEND   000400 /* ugh -- backward-compatibility hack */
 
#define REG_EXPECT   001000 /* report details on partial/limited matches */
 
#define REG_BOSONLY   002000 /* temporary kludge for BOS-only matches */
 
#define REG_DUMP   004000 /* none of your business :-) */
 
#define REG_FAKE   010000 /* none of your business :-) */
 
#define REG_PROGRESS   020000 /* none of your business :-) */
 
#define REG_NOTBOL   0001 /* BOS is not BOL */
 
#define REG_NOTEOL   0002 /* EOS is not EOL */
 
#define REG_STARTEND   0004 /* backward compatibility kludge */
 
#define REG_FTRACE   0010 /* none of your business */
 
#define REG_MTRACE   0020 /* none of your business */
 
#define REG_SMALL   0040 /* none of your business */
 
#define REG_OKAY   0 /* no errors detected */
 
#define REG_NOMATCH   1 /* failed to match */
 
#define REG_BADPAT   2 /* invalid regexp */
 
#define REG_ECOLLATE   3 /* invalid collating element */
 
#define REG_ECTYPE   4 /* invalid character class */
 
#define REG_EESCAPE   5 /* invalid escape \ sequence */
 
#define REG_ESUBREG   6 /* invalid backreference number */
 
#define REG_EBRACK   7 /* brackets [] not balanced */
 
#define REG_EPAREN   8 /* parentheses () not balanced */
 
#define REG_EBRACE   9 /* braces {} not balanced */
 
#define REG_BADBR   10 /* invalid repetition count(s) */
 
#define REG_ERANGE   11 /* invalid character range */
 
#define REG_ESPACE   12 /* out of memory */
 
#define REG_BADRPT   13 /* quantifier operand invalid */
 
#define REG_ASSERT   15 /* "can't happen" -- you found a bug */
 
#define REG_INVARG   16 /* invalid argument to regex function */
 
#define REG_MIXED   17 /* character widths of regex and string differ */
 
#define REG_BADOPT   18 /* invalid embedded option */
 
#define REG_ETOOBIG   19 /* regular expression is too complex */
 
#define REG_ECOLORS   20 /* too many colors */
 
#define REG_ATOI   101 /* convert error-code name to number */
 
#define REG_ITOA   102 /* convert error-code number to name */
 
#define REG_PREFIX   (-1) /* identified a common prefix */
 
#define REG_EXACT   (-2) /* identified an exact match */
 

Typedefs

typedef long regoff_t
 

Functions

int pg_regcomp (regex_t *re, const pg_wchar *string, size_t len, int flags, Oid collation)
 
int pg_regexec (regex_t *re, const pg_wchar *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
 
int pg_regprefix (regex_t *re, pg_wchar **string, size_t *slength)
 
void pg_regfree (regex_t *re)
 
size_t pg_regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
 
regex_tRE_compile_and_cache (text *text_re, int cflags, Oid collation)
 
bool RE_compile_and_execute (text *text_re, char *dat, int dat_len, int cflags, Oid collation, int nmatch, regmatch_t *pmatch)
 

Macro Definition Documentation

◆ _REGEX_H_

#define _REGEX_H_   /* never again */

Definition at line 2 of file regex.h.

◆ REG_ADVANCED

#define REG_ADVANCED   000003 /* AREs (which are also EREs) */

Definition at line 103 of file regex.h.

◆ REG_ADVF

#define REG_ADVF   000002 /* advanced features in EREs */

Definition at line 102 of file regex.h.

◆ REG_ASSERT

#define REG_ASSERT   15 /* "can't happen" -- you found a bug */

Definition at line 151 of file regex.h.

◆ REG_ATOI

#define REG_ATOI   101 /* convert error-code name to number */

Definition at line 158 of file regex.h.

◆ REG_BADBR

#define REG_BADBR   10 /* invalid repetition count(s) */

Definition at line 147 of file regex.h.

◆ REG_BADOPT

#define REG_BADOPT   18 /* invalid embedded option */

Definition at line 154 of file regex.h.

◆ REG_BADPAT

#define REG_BADPAT   2 /* invalid regexp */

Definition at line 139 of file regex.h.

◆ REG_BADRPT

#define REG_BADRPT   13 /* quantifier operand invalid */

Definition at line 150 of file regex.h.

◆ REG_BASIC

#define REG_BASIC   000000 /* BREs (convenience) */

Definition at line 100 of file regex.h.

◆ REG_BOSONLY

#define REG_BOSONLY   002000 /* temporary kludge for BOS-only matches */

Definition at line 114 of file regex.h.

◆ REG_DUMP

#define REG_DUMP   004000 /* none of your business :-) */

Definition at line 115 of file regex.h.

◆ REG_EBRACE

#define REG_EBRACE   9 /* braces {} not balanced */

Definition at line 146 of file regex.h.

◆ REG_EBRACK

#define REG_EBRACK   7 /* brackets [] not balanced */

Definition at line 144 of file regex.h.

◆ REG_ECOLLATE

#define REG_ECOLLATE   3 /* invalid collating element */

Definition at line 140 of file regex.h.

◆ REG_ECOLORS

#define REG_ECOLORS   20 /* too many colors */

Definition at line 156 of file regex.h.

◆ REG_ECTYPE

#define REG_ECTYPE   4 /* invalid character class */

Definition at line 141 of file regex.h.

◆ REG_EESCAPE

#define REG_EESCAPE   5 /* invalid escape \ sequence */

Definition at line 142 of file regex.h.

◆ REG_EPAREN

#define REG_EPAREN   8 /* parentheses () not balanced */

Definition at line 145 of file regex.h.

◆ REG_ERANGE

#define REG_ERANGE   11 /* invalid character range */

Definition at line 148 of file regex.h.

◆ REG_ESPACE

#define REG_ESPACE   12 /* out of memory */

Definition at line 149 of file regex.h.

◆ REG_ESUBREG

#define REG_ESUBREG   6 /* invalid backreference number */

Definition at line 143 of file regex.h.

◆ REG_ETOOBIG

#define REG_ETOOBIG   19 /* regular expression is too complex */

Definition at line 155 of file regex.h.

◆ REG_EXACT

#define REG_EXACT   (-2) /* identified an exact match */

Definition at line 162 of file regex.h.

◆ REG_EXPANDED

#define REG_EXPANDED   000040 /* expanded format, white space & comments */

Definition at line 108 of file regex.h.

◆ REG_EXPECT

#define REG_EXPECT   001000 /* report details on partial/limited matches */

Definition at line 113 of file regex.h.

◆ REG_EXTENDED

#define REG_EXTENDED   000001 /* EREs */

Definition at line 101 of file regex.h.

◆ REG_FAKE

#define REG_FAKE   010000 /* none of your business :-) */

Definition at line 116 of file regex.h.

◆ REG_FTRACE

#define REG_FTRACE   0010 /* none of your business */

Definition at line 127 of file regex.h.

◆ REG_ICASE

#define REG_ICASE   000010 /* ignore case */

Definition at line 106 of file regex.h.

◆ REG_INVARG

#define REG_INVARG   16 /* invalid argument to regex function */

Definition at line 152 of file regex.h.

◆ REG_ITOA

#define REG_ITOA   102 /* convert error-code number to name */

Definition at line 159 of file regex.h.

◆ REG_MIXED

#define REG_MIXED   17 /* character widths of regex and string differ */

Definition at line 153 of file regex.h.

◆ REG_MTRACE

#define REG_MTRACE   0020 /* none of your business */

Definition at line 128 of file regex.h.

◆ REG_NEWLINE

#define REG_NEWLINE   000300 /* newlines are line terminators */

Definition at line 111 of file regex.h.

◆ REG_NLANCH

#define REG_NLANCH   000200 /* ^ matches after \n, $ before */

Definition at line 110 of file regex.h.

◆ REG_NLSTOP

#define REG_NLSTOP   000100 /* \n doesn't match . or [^ ] */

Definition at line 109 of file regex.h.

◆ REG_NOMATCH

#define REG_NOMATCH   1 /* failed to match */

Definition at line 138 of file regex.h.

◆ REG_NOSPEC

#define REG_NOSPEC   REG_QUOTE /* historical synonym */

Definition at line 105 of file regex.h.

◆ REG_NOSUB

#define REG_NOSUB   000020 /* caller doesn't need subexpr match data */

Definition at line 107 of file regex.h.

◆ REG_NOTBOL

#define REG_NOTBOL   0001 /* BOS is not BOL */

Definition at line 124 of file regex.h.

◆ REG_NOTEOL

#define REG_NOTEOL   0002 /* EOS is not EOL */

Definition at line 125 of file regex.h.

◆ REG_OKAY

#define REG_OKAY   0 /* no errors detected */

Definition at line 137 of file regex.h.

◆ REG_PEND

#define REG_PEND   000400 /* ugh -- backward-compatibility hack */

Definition at line 112 of file regex.h.

◆ REG_PREFIX

#define REG_PREFIX   (-1) /* identified a common prefix */

Definition at line 161 of file regex.h.

◆ REG_PROGRESS

#define REG_PROGRESS   020000 /* none of your business :-) */

Definition at line 117 of file regex.h.

◆ REG_QUOTE

#define REG_QUOTE   000004 /* no special characters, none */

Definition at line 104 of file regex.h.

◆ REG_SMALL

#define REG_SMALL   0040 /* none of your business */

Definition at line 129 of file regex.h.

◆ REG_STARTEND

#define REG_STARTEND   0004 /* backward compatibility kludge */

Definition at line 126 of file regex.h.

◆ REG_UBACKREF

#define REG_UBACKREF   000001 /* has back-reference (\n) */

Definition at line 60 of file regex.h.

◆ REG_UBBS

#define REG_UBBS   000100 /* has backslash within bracket expr */

Definition at line 66 of file regex.h.

◆ REG_UBOUNDS

#define REG_UBOUNDS   000004 /* has bounded quantifier ({m,n}) */

Definition at line 62 of file regex.h.

◆ REG_UBRACES

#define REG_UBRACES   000010 /* has { that doesn't begin a quantifier */

Definition at line 63 of file regex.h.

◆ REG_UBSALNUM

#define REG_UBSALNUM   000020 /* has backslash-alphanumeric in non-ARE */

Definition at line 64 of file regex.h.

◆ REG_UEMPTYMATCH

#define REG_UEMPTYMATCH   004000 /* can match a zero-length string */

Definition at line 71 of file regex.h.

◆ REG_UIMPOSSIBLE

#define REG_UIMPOSSIBLE   010000 /* provably cannot match anything */

Definition at line 72 of file regex.h.

◆ REG_ULOCALE

#define REG_ULOCALE   002000 /* has locale dependency */

Definition at line 70 of file regex.h.

◆ REG_ULOOKAROUND

#define REG_ULOOKAROUND   000002 /* has lookahead/lookbehind constraint */

Definition at line 61 of file regex.h.

◆ REG_UNONPOSIX

#define REG_UNONPOSIX   000200 /* has any construct that extends POSIX */

Definition at line 67 of file regex.h.

◆ REG_UPBOTCH

#define REG_UPBOTCH
Value:
000040 /* has unmatched right paren in ERE (legal
* per spec, but that was a mistake) */

Definition at line 65 of file regex.h.

◆ REG_USHORTEST

#define REG_USHORTEST   020000 /* has non-greedy quantifier */

Definition at line 73 of file regex.h.

◆ REG_UUNPORT

#define REG_UUNPORT   001000 /* has numeric character code dependency */

Definition at line 69 of file regex.h.

◆ REG_UUNSPEC

#define REG_UUNSPEC
Value:
000400 /* has any case disallowed by POSIX, e.g.
* an empty branch */

Definition at line 68 of file regex.h.

Typedef Documentation

◆ regoff_t

typedef long regoff_t

Definition at line 48 of file regex.h.

Function Documentation

◆ pg_regcomp()

int pg_regcomp ( regex_t re,
const pg_wchar string,
size_t  len,
int  flags,
Oid  collation 
)

Definition at line 370 of file regcomp.c.

375 {
376  struct vars var;
377  struct vars *v = &var;
378  struct guts *g;
379  int i;
380  size_t j;
381 
382 #ifdef REG_DEBUG
383  FILE *debug = (flags & REG_PROGRESS) ? stdout : (FILE *) NULL;
384 #else
385  FILE *debug = (FILE *) NULL;
386 #endif
387 
388 #define CNOERR() { if (ISERR()) return freev(v, v->err); }
389 
390  /* sanity checks */
391 
392  if (re == NULL || string == NULL)
393  return REG_INVARG;
394  if ((flags & REG_QUOTE) &&
395  (flags & (REG_ADVANCED | REG_EXPANDED | REG_NEWLINE)))
396  return REG_INVARG;
397  if (!(flags & REG_EXTENDED) && (flags & REG_ADVF))
398  return REG_INVARG;
399 
400  /* Initialize locale-dependent support */
401  pg_set_regex_collation(collation);
402 
403  /* initial setup (after which freev() is callable) */
404  v->re = re;
405  v->now = string;
406  v->stop = v->now + len;
407  v->err = 0;
408  v->cflags = flags;
409  v->nsubexp = 0;
410  v->subs = v->sub10;
411  v->nsubs = 10;
412  for (j = 0; j < v->nsubs; j++)
413  v->subs[j] = NULL;
414  v->nfa = NULL;
415  v->cm = NULL;
416  v->nlcolor = COLORLESS;
417  v->wordchrs = NULL;
418  v->tree = NULL;
419  v->treechain = NULL;
420  v->treefree = NULL;
421  v->cv = NULL;
422  v->cv2 = NULL;
423  v->lacons = NULL;
424  v->nlacons = 0;
425  v->spaceused = 0;
426  re->re_magic = REMAGIC;
427  re->re_info = 0; /* bits get set during parse */
428  re->re_csize = sizeof(chr);
429  re->re_collation = collation;
430  re->re_guts = NULL;
431  re->re_fns = VS(&functions);
432 
433  /* more complex setup, malloced things */
434  re->re_guts = VS(MALLOC(sizeof(struct guts)));
435  if (re->re_guts == NULL)
436  return freev(v, REG_ESPACE);
437  g = (struct guts *) re->re_guts;
438  g->tree = NULL;
439  initcm(v, &g->cmap);
440  v->cm = &g->cmap;
441  g->lacons = NULL;
442  g->nlacons = 0;
443  ZAPCNFA(g->search);
444  v->nfa = newnfa(v, v->cm, (struct nfa *) NULL);
445  CNOERR();
446  /* set up a reasonably-sized transient cvec for getcvec usage */
447  v->cv = newcvec(100, 20);
448  if (v->cv == NULL)
449  return freev(v, REG_ESPACE);
450 
451  /* parsing */
452  lexstart(v); /* also handles prefixes */
453  if ((v->cflags & REG_NLSTOP) || (v->cflags & REG_NLANCH))
454  {
455  /* assign newline a unique color */
456  v->nlcolor = subcolor(v->cm, newline());
457  okcolors(v->nfa, v->cm);
458  }
459  CNOERR();
460  v->tree = parse(v, EOS, PLAIN, v->nfa->init, v->nfa->final);
461  assert(SEE(EOS)); /* even if error; ISERR() => SEE(EOS) */
462  CNOERR();
463  assert(v->tree != NULL);
464 
465  /* finish setup of nfa and its subre tree */
466  specialcolors(v->nfa);
467  CNOERR();
468 #ifdef REG_DEBUG
469  if (debug != NULL)
470  {
471  fprintf(debug, "\n\n\n========= RAW ==========\n");
472  dumpnfa(v->nfa, debug);
473  dumpst(v->tree, debug, 1);
474  }
475 #endif
476  if (v->cflags & REG_NOSUB)
477  removecaptures(v, v->tree);
478  v->ntree = numst(v->tree, 1);
479  markst(v->tree);
480  cleanst(v);
481 #ifdef REG_DEBUG
482  if (debug != NULL)
483  {
484  fprintf(debug, "\n\n\n========= TREE FIXED ==========\n");
485  dumpst(v->tree, debug, 1);
486  }
487 #endif
488 
489  /* build compacted NFAs for tree and lacons */
490  re->re_info |= nfatree(v, v->tree, debug);
491  CNOERR();
492  assert(v->nlacons == 0 || v->lacons != NULL);
493  for (i = 1; i < v->nlacons; i++)
494  {
495  struct subre *lasub = &v->lacons[i];
496 
497 #ifdef REG_DEBUG
498  if (debug != NULL)
499  fprintf(debug, "\n\n\n========= LA%d ==========\n", i);
500 #endif
501 
502  /* Prepend .* to pattern if it's a lookbehind LACON */
503  nfanode(v, lasub, !LATYPE_IS_AHEAD(lasub->latype), debug);
504  }
505  CNOERR();
506  if (v->tree->flags & SHORTER)
508 
509  /* build compacted NFAs for tree, lacons, fast search */
510 #ifdef REG_DEBUG
511  if (debug != NULL)
512  fprintf(debug, "\n\n\n========= SEARCH ==========\n");
513 #endif
514  /* can sacrifice main NFA now, so use it as work area */
515  (DISCARD) optimize(v->nfa, debug);
516  CNOERR();
517  makesearch(v, v->nfa);
518  CNOERR();
519  compact(v->nfa, &g->search);
520  CNOERR();
521 
522  /* looks okay, package it up */
523  re->re_nsub = v->nsubexp;
524  v->re = NULL; /* freev no longer frees re */
525  g->magic = GUTSMAGIC;
526  g->cflags = v->cflags;
527  g->info = re->re_info;
528  g->nsub = re->re_nsub;
529  g->tree = v->tree;
530  v->tree = NULL;
531  g->ntree = v->ntree;
532  g->compare = (v->cflags & REG_ICASE) ? casecmp : cmp;
533  g->lacons = v->lacons;
534  v->lacons = NULL;
535  g->nlacons = v->nlacons;
536 
537 #ifdef REG_DEBUG
538  if (flags & REG_DUMP)
539  {
540  dump(re, stdout);
541  fflush(stdout);
542  }
543 #endif
544 
545  assert(v->err == 0);
546  return freev(v, 0);
547 }
static bool debug
Definition: initdb.c:161
int j
Definition: isn.c:74
int i
Definition: isn.c:73
static void const char fflush(stdout)
const void size_t len
#define fprintf
Definition: port.h:242
char string[11]
Definition: preproc-type.c:52
void pg_set_regex_collation(Oid collation)
#define NOTE(b)
Definition: regcomp.c:324
static void compact(struct nfa *nfa, struct cnfa *cnfa)
static void specialcolors(struct nfa *nfa)
static void makesearch(struct vars *v, struct nfa *nfa)
Definition: regcomp.c:619
static int casecmp(const chr *x, const chr *y, size_t len)
static const struct fns functions
Definition: regcomp.c:356
static void cleanst(struct vars *v)
Definition: regcomp.c:2310
#define SEE(t)
Definition: regcomp.c:313
static struct nfa * newnfa(struct vars *v, struct colormap *cm, struct nfa *parent)
static long optimize(struct nfa *nfa, FILE *f)
#define CNOERR()
static void okcolors(struct nfa *nfa, struct colormap *cm)
static void initcm(struct vars *v, struct colormap *cm)
static chr newline(void)
static int cmp(const chr *x, const chr *y, size_t len)
static long nfanode(struct vars *v, struct subre *t, int converttosearch, FILE *f)
Definition: regcomp.c:2349
static void removecaptures(struct vars *v, struct subre *t)
Definition: regcomp.c:2216
#define EOS
Definition: regcomp.c:329
static void lexstart(struct vars *v)
#define PLAIN
Definition: regcomp.c:330
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:715
static color subcolor(struct colormap *cm, chr c)
static void dumpnfa(struct nfa *nfa, FILE *f)
static int numst(struct subre *t, int start)
Definition: regcomp.c:2262
static int freev(struct vars *v, int err)
Definition: regcomp.c:590
static long nfatree(struct vars *v, struct subre *t, FILE *f)
Definition: regcomp.c:2329
static void markst(struct subre *t)
Definition: regcomp.c:2295
static struct cvec * newcvec(int nchrs, int nranges)
#define MALLOC(n)
Definition: regcustom.h:52
pg_wchar chr
Definition: regcustom.h:59
#define assert(x)
Definition: regcustom.h:56
#define REG_ICASE
Definition: regex.h:106
#define REG_DUMP
Definition: regex.h:115
#define REG_PROGRESS
Definition: regex.h:117
#define REG_ADVANCED
Definition: regex.h:103
#define REG_EXPANDED
Definition: regex.h:108
#define REG_NLANCH
Definition: regex.h:110
#define REG_INVARG
Definition: regex.h:152
#define REG_EXTENDED
Definition: regex.h:101
#define REG_NLSTOP
Definition: regex.h:109
#define REG_ADVF
Definition: regex.h:102
#define REG_NEWLINE
Definition: regex.h:111
#define REG_NOSUB
Definition: regex.h:107
#define REG_USHORTEST
Definition: regex.h:73
#define REG_ESPACE
Definition: regex.h:149
#define REG_QUOTE
Definition: regex.h:104
#define ZAPCNFA(cnfa)
Definition: regguts.h:434
#define REMAGIC
Definition: regguts.h:101
#define GUTSMAGIC
Definition: regguts.h:531
#define COLORLESS
Definition: regguts.h:158
#define LATYPE_IS_AHEAD(la)
Definition: regguts.h:109
#define DISCARD
Definition: regguts.h:58
#define VS(x)
Definition: regguts.h:61
#define SHORTER
Definition: regguts.h:481
Definition: regguts.h:529
struct subre * tree
Definition: regguts.h:535
struct subre * lacons
Definition: regguts.h:540
int magic
Definition: regguts.h:530
long info
Definition: regguts.h:533
struct cnfa search
Definition: regguts.h:536
int ntree
Definition: regguts.h:537
int cflags
Definition: regguts.h:532
size_t nsub
Definition: regguts.h:534
int nlacons
Definition: regguts.h:541
struct colormap cmap
Definition: regguts.h:538
Definition: regguts.h:349
struct state * final
Definition: regguts.h:352
struct state * init
Definition: regguts.h:351
char * re_guts
Definition: regex.h:78
long re_info
Definition: regex.h:59
int re_csize
Definition: regex.h:74
size_t re_nsub
Definition: regex.h:58
int re_magic
Definition: regex.h:57
Oid re_collation
Definition: regex.h:76
char * re_fns
Definition: regex.h:79
Definition: regguts.h:477
char flags
Definition: regguts.h:479
char latype
Definition: regguts.h:495
Definition: regcomp.c:281
const chr * now
Definition: regcomp.c:283
struct colormap * cm
Definition: regcomp.c:296
struct subre * tree
Definition: regcomp.c:299
struct subre ** subs
Definition: regcomp.c:292
int nlacons
Definition: regcomp.c:306
const chr * stop
Definition: regcomp.c:284
struct subre * lacons
Definition: regcomp.c:305
size_t spaceused
Definition: regcomp.c:308
int err
Definition: regcomp.c:285
int cflags
Definition: regcomp.c:286
struct subre * treechain
Definition: regcomp.c:300
int ntree
Definition: regcomp.c:302
regex_t * re
Definition: regcomp.c:282
struct subre * sub10[10]
Definition: regcomp.c:294
struct cvec * cv2
Definition: regcomp.c:304
struct subre * treefree
Definition: regcomp.c:301
struct nfa * nfa
Definition: regcomp.c:295
size_t nsubs
Definition: regcomp.c:293
struct state * wordchrs
Definition: regcomp.c:298
int nsubexp
Definition: regcomp.c:291
struct cvec * cv
Definition: regcomp.c:303
color nlcolor
Definition: regcomp.c:297

References assert, casecmp(), vars::cflags, guts::cflags, cleanst(), vars::cm, guts::cmap, cmp(), CNOERR, COLORLESS, compact(), vars::cv, vars::cv2, debug, DISCARD, dumpnfa(), EOS, vars::err, fflush(), nfa::final, subre::flags, fprintf, freev(), functions, GUTSMAGIC, i, guts::info, nfa::init, initcm(), j, vars::lacons, guts::lacons, subre::latype, LATYPE_IS_AHEAD, len, lexstart(), guts::magic, makesearch(), MALLOC, markst(), newcvec(), newline(), newnfa(), vars::nfa, nfanode(), nfatree(), vars::nlacons, guts::nlacons, vars::nlcolor, NOTE, vars::now, guts::nsub, vars::nsubexp, vars::nsubs, vars::ntree, guts::ntree, numst(), okcolors(), optimize(), parse(), pg_set_regex_collation(), PLAIN, vars::re, regex_t::re_collation, regex_t::re_csize, regex_t::re_fns, regex_t::re_guts, regex_t::re_info, regex_t::re_magic, regex_t::re_nsub, REG_ADVANCED, REG_ADVF, REG_DUMP, REG_ESPACE, REG_EXPANDED, REG_EXTENDED, REG_ICASE, REG_INVARG, REG_NEWLINE, REG_NLANCH, REG_NLSTOP, REG_NOSUB, REG_PROGRESS, REG_QUOTE, REG_USHORTEST, REMAGIC, removecaptures(), guts::search, SEE, SHORTER, vars::spaceused, specialcolors(), generate_unaccent_rules::stdout, vars::stop, vars::sub10, subcolor(), vars::subs, vars::tree, guts::tree, vars::treechain, vars::treefree, VS, vars::wordchrs, and ZAPCNFA.

Referenced by NIAddAffix(), RE_compile(), RE_compile_and_cache(), regcomp_auth_token(), and test_re_compile().

◆ pg_regerror()

size_t pg_regerror ( int  errcode,
const regex_t preg,
char *  errbuf,
size_t  errbuf_size 
)

Definition at line 60 of file regerror.c.

64 {
65  const struct rerr *r;
66  const char *msg;
67  char convbuf[sizeof(unk) + 50]; /* 50 = plenty for int */
68  size_t len;
69  int icode;
70 
71  switch (errcode)
72  {
73  case REG_ATOI: /* convert name to number */
74  for (r = rerrs; r->code >= 0; r++)
75  if (strcmp(r->name, errbuf) == 0)
76  break;
77  sprintf(convbuf, "%d", r->code); /* -1 for unknown */
78  msg = convbuf;
79  break;
80  case REG_ITOA: /* convert number to name */
81  icode = atoi(errbuf); /* not our problem if this fails */
82  for (r = rerrs; r->code >= 0; r++)
83  if (r->code == icode)
84  break;
85  if (r->code >= 0)
86  msg = r->name;
87  else
88  { /* unknown; tell him the number */
89  sprintf(convbuf, "REG_%u", (unsigned) icode);
90  msg = convbuf;
91  }
92  break;
93  default: /* a real, normal error code */
94  for (r = rerrs; r->code >= 0; r++)
95  if (r->code == errcode)
96  break;
97  if (r->code >= 0)
98  msg = r->explain;
99  else
100  { /* unknown; say so */
101  sprintf(convbuf, unk, errcode);
102  msg = convbuf;
103  }
104  break;
105  }
106 
107  len = strlen(msg) + 1; /* space needed, including NUL */
108  if (errbuf_size > 0)
109  {
110  if (errbuf_size > len)
111  strcpy(errbuf, msg);
112  else
113  { /* truncate to fit */
114  memcpy(errbuf, msg, errbuf_size - 1);
115  errbuf[errbuf_size - 1] = '\0';
116  }
117  }
118 
119  return len;
120 }
int errcode(int sqlerrcode)
Definition: elog.c:859
#define sprintf
Definition: port.h:240
static const struct rerr rerrs[]
static const char unk[]
Definition: regerror.c:37
#define REG_ITOA
Definition: regex.h:159
#define REG_ATOI
Definition: regex.h:158
Definition: regerror.c:41
const char * explain
Definition: regerror.c:44
int code
Definition: regerror.c:42
const char * name
Definition: regerror.c:43

References rerr::code, errcode(), rerr::explain, len, rerr::name, REG_ATOI, REG_ITOA, rerrs, sprintf, and unk.

Referenced by check_ident_usermap(), NIAddAffix(), RE_compile(), RE_compile_and_cache(), RE_wchar_execute(), regcomp_auth_token(), regexp_fixed_prefix(), replace_text_regexp(), test_re_compile(), and test_re_execute().

◆ pg_regexec()

int pg_regexec ( regex_t re,
const pg_wchar string,
size_t  len,
size_t  search_start,
rm_detail_t details,
size_t  nmatch,
regmatch_t  pmatch[],
int  flags 
)

Definition at line 185 of file regexec.c.

193 {
194  struct vars var;
195  struct vars *v = &var;
196  int st;
197  size_t n;
198  size_t i;
199  int backref;
200 
201 #define LOCALMAT 20
202  regmatch_t mat[LOCALMAT];
203 
204 #define LOCALDFAS 40
205  struct dfa *subdfas[LOCALDFAS];
206 
207  /* sanity checks */
208  if (re == NULL || string == NULL || re->re_magic != REMAGIC)
209  return REG_INVARG;
210  if (re->re_csize != sizeof(chr))
211  return REG_MIXED;
212  if (search_start > len)
213  return REG_NOMATCH;
214 
215  /* Initialize locale-dependent support */
217 
218  /* setup */
219  v->re = re;
220  v->g = (struct guts *) re->re_guts;
221  if ((v->g->cflags & REG_EXPECT) && details == NULL)
222  return REG_INVARG;
223  if (v->g->info & REG_UIMPOSSIBLE)
224  return REG_NOMATCH;
225  backref = (v->g->info & REG_UBACKREF) ? 1 : 0;
226  v->eflags = flags;
227  if (backref && nmatch <= v->g->nsub)
228  {
229  /* need larger work area */
230  v->nmatch = v->g->nsub + 1;
231  if (v->nmatch <= LOCALMAT)
232  v->pmatch = mat;
233  else
234  v->pmatch = (regmatch_t *) MALLOC(v->nmatch * sizeof(regmatch_t));
235  if (v->pmatch == NULL)
236  return REG_ESPACE;
237  zapallsubs(v->pmatch, v->nmatch);
238  }
239  else
240  {
241  /* we can store results directly in caller's array */
242  v->pmatch = pmatch;
243  /* ensure any extra entries in caller's array are filled with -1 */
244  if (nmatch > 0)
245  zapallsubs(pmatch, nmatch);
246  /* then forget about extra entries, to avoid useless work in find() */
247  if (nmatch > v->g->nsub + 1)
248  nmatch = v->g->nsub + 1;
249  v->nmatch = nmatch;
250  }
251  v->details = details;
252  v->start = (chr *) string;
253  v->search_start = (chr *) string + search_start;
254  v->stop = (chr *) string + len;
255  v->err = 0;
256  v->subdfas = NULL;
257  v->ladfas = NULL;
258  v->lblastcss = NULL;
259  v->lblastcp = NULL;
260  /* below this point, "goto cleanup" will behave sanely */
261 
262  assert(v->g->ntree >= 0);
263  n = (size_t) v->g->ntree;
264  if (n <= LOCALDFAS)
265  v->subdfas = subdfas;
266  else
267  {
268  v->subdfas = (struct dfa **) MALLOC(n * sizeof(struct dfa *));
269  if (v->subdfas == NULL)
270  {
271  st = REG_ESPACE;
272  goto cleanup;
273  }
274  }
275  for (i = 0; i < n; i++)
276  v->subdfas[i] = NULL;
277 
278  assert(v->g->nlacons >= 0);
279  n = (size_t) v->g->nlacons;
280  if (n > 0)
281  {
282  v->ladfas = (struct dfa **) MALLOC(n * sizeof(struct dfa *));
283  if (v->ladfas == NULL)
284  {
285  st = REG_ESPACE;
286  goto cleanup;
287  }
288  for (i = 0; i < n; i++)
289  v->ladfas[i] = NULL;
290  v->lblastcss = (struct sset **) MALLOC(n * sizeof(struct sset *));
291  v->lblastcp = (chr **) MALLOC(n * sizeof(chr *));
292  if (v->lblastcss == NULL || v->lblastcp == NULL)
293  {
294  st = REG_ESPACE;
295  goto cleanup;
296  }
297  for (i = 0; i < n; i++)
298  {
299  v->lblastcss[i] = NULL;
300  v->lblastcp[i] = NULL;
301  }
302  }
303 
304  /* do it */
305  assert(v->g->tree != NULL);
306  if (backref)
307  st = cfind(v, &v->g->tree->cnfa, &v->g->cmap);
308  else
309  st = find(v, &v->g->tree->cnfa, &v->g->cmap);
310 
311  /* on success, ensure caller's match vector is filled correctly */
312  if (st == REG_OKAY && nmatch > 0)
313  {
314  if (v->pmatch != pmatch)
315  {
316  /* copy portion of match vector over from (larger) work area */
317  assert(nmatch <= v->nmatch);
318  memcpy(VS(pmatch), VS(v->pmatch), nmatch * sizeof(regmatch_t));
319  }
320  if (v->g->cflags & REG_NOSUB)
321  {
322  /* don't expose possibly-partial sub-match results to caller */
323  zapallsubs(pmatch, nmatch);
324  }
325  }
326 
327  /* clean up */
328 cleanup:
329  if (v->pmatch != pmatch && v->pmatch != mat)
330  FREE(v->pmatch);
331  if (v->subdfas != NULL)
332  {
333  n = (size_t) v->g->ntree;
334  for (i = 0; i < n; i++)
335  {
336  if (v->subdfas[i] != NULL)
337  freedfa(v->subdfas[i]);
338  }
339  if (v->subdfas != subdfas)
340  FREE(v->subdfas);
341  }
342  if (v->ladfas != NULL)
343  {
344  n = (size_t) v->g->nlacons;
345  for (i = 0; i < n; i++)
346  {
347  if (v->ladfas[i] != NULL)
348  freedfa(v->ladfas[i]);
349  }
350  FREE(v->ladfas);
351  }
352  if (v->lblastcss != NULL)
353  FREE(v->lblastcss);
354  if (v->lblastcp != NULL)
355  FREE(v->lblastcp);
356 
357 #ifdef REG_DEBUG
358  if (v->eflags & (REG_FTRACE | REG_MTRACE))
359  fflush(stdout);
360 #endif
361 
362  return st;
363 }
static void cleanup(void)
Definition: bootstrap.c:682
#define FREE(ptr)
Definition: cryptohash.c:37
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
#define REG_NOMATCH
Definition: regex.h:138
#define REG_UIMPOSSIBLE
Definition: regex.h:72
#define REG_MTRACE
Definition: regex.h:128
#define REG_FTRACE
Definition: regex.h:127
#define REG_EXPECT
Definition: regex.h:113
#define REG_OKAY
Definition: regex.h:137
#define REG_MIXED
Definition: regex.h:153
#define REG_UBACKREF
Definition: regex.h:60
static int find(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
Definition: regexec.c:419
static void freedfa(struct dfa *d)
static void zapallsubs(regmatch_t *p, size_t n)
Definition: regexec.c:663
static int cfind(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
Definition: regexec.c:509
#define LOCALMAT
#define LOCALDFAS
Definition: regexec.c:64
Definition: regexec.c:46
struct cnfa cnfa
Definition: regguts.h:505
size_t nmatch
Definition: regexec.c:111
struct dfa ** ladfas
Definition: regexec.c:119
struct dfa ** subdfas
Definition: regexec.c:118
chr * search_start
Definition: regexec.c:115
struct sset ** lblastcss
Definition: regexec.c:120
struct guts * g
Definition: regexec.c:109
chr ** lblastcp
Definition: regexec.c:121
int eflags
Definition: regexec.c:110
chr * start
Definition: regexec.c:114
rm_detail_t * details
Definition: regexec.c:113
regmatch_t * pmatch
Definition: regexec.c:112

References assert, cfind(), guts::cflags, cleanup(), guts::cmap, subre::cnfa, vars::details, vars::eflags, vars::err, fflush(), find(), FREE, freedfa(), vars::g, i, if(), guts::info, vars::ladfas, vars::lblastcp, vars::lblastcss, len, LOCALDFAS, LOCALMAT, MALLOC, guts::nlacons, vars::nmatch, guts::nsub, guts::ntree, pg_set_regex_collation(), vars::pmatch, vars::re, regex_t::re_collation, regex_t::re_csize, regex_t::re_guts, regex_t::re_magic, REG_ESPACE, REG_EXPECT, REG_FTRACE, REG_INVARG, REG_MIXED, REG_MTRACE, REG_NOMATCH, REG_NOSUB, REG_OKAY, REG_UBACKREF, REG_UIMPOSSIBLE, REMAGIC, vars::search_start, vars::start, generate_unaccent_rules::stdout, vars::stop, vars::subdfas, guts::tree, VS, and zapallsubs().

Referenced by CheckAffix(), RE_wchar_execute(), regexec_auth_token(), replace_text_regexp(), and test_re_execute().

◆ pg_regfree()

void pg_regfree ( regex_t re)

Definition at line 49 of file regfree.c.

50 {
51  if (re == NULL)
52  return;
53  (*((struct fns *) re->re_fns)->free) (re);
54 }
Definition: regguts.h:516

References regex_t::re_fns.

Referenced by free_auth_token(), and test_regex().

◆ pg_regprefix()

int pg_regprefix ( regex_t re,
pg_wchar **  string,
size_t *  slength 
)

Definition at line 46 of file regprefix.c.

49 {
50  struct guts *g;
51  struct cnfa *cnfa;
52  int st;
53 
54  /* sanity checks */
55  if (string == NULL || slength == NULL)
56  return REG_INVARG;
57  *string = NULL; /* initialize for failure cases */
58  *slength = 0;
59  if (re == NULL || re->re_magic != REMAGIC)
60  return REG_INVARG;
61  if (re->re_csize != sizeof(chr))
62  return REG_MIXED;
63 
64  /* Initialize locale-dependent support */
66 
67  /* setup */
68  g = (struct guts *) re->re_guts;
69  if (g->info & REG_UIMPOSSIBLE)
70  return REG_NOMATCH;
71 
72  /*
73  * This implementation considers only the search NFA for the topmost regex
74  * tree node. Therefore, constraints such as backrefs are not fully
75  * applied, which is allowed per the function's API spec.
76  */
77  assert(g->tree != NULL);
78  cnfa = &g->tree->cnfa;
79 
80  /* matchall NFAs never have a fixed prefix */
81  if (cnfa->flags & MATCHALL)
82  return REG_NOMATCH;
83 
84  /*
85  * Since a correct NFA should never contain any exit-free loops, it should
86  * not be possible for our traversal to return to a previously visited NFA
87  * state. Hence we need at most nstates chrs in the output string.
88  */
89  *string = (chr *) MALLOC(cnfa->nstates * sizeof(chr));
90  if (*string == NULL)
91  return REG_ESPACE;
92 
93  /* do it */
94  st = findprefix(cnfa, &g->cmap, *string, slength);
95 
96  assert(*slength <= cnfa->nstates);
97 
98  /* clean up */
99  if (st != REG_PREFIX && st != REG_EXACT)
100  {
101  FREE(*string);
102  *string = NULL;
103  *slength = 0;
104  }
105 
106  return st;
107 }
#define REG_EXACT
Definition: regex.h:162
#define REG_PREFIX
Definition: regex.h:161
#define MATCHALL
Definition: regguts.h:412
static int findprefix(struct cnfa *cnfa, struct colormap *cm, chr *string, size_t *slength)
Definition: regprefix.c:116
Definition: regguts.h:407
int flags
Definition: regguts.h:410
int nstates
Definition: regguts.h:408

References assert, guts::cmap, subre::cnfa, findprefix(), cnfa::flags, FREE, if(), guts::info, MALLOC, MATCHALL, cnfa::nstates, pg_set_regex_collation(), regex_t::re_collation, regex_t::re_csize, regex_t::re_guts, regex_t::re_magic, REG_ESPACE, REG_EXACT, REG_INVARG, REG_MIXED, REG_NOMATCH, REG_PREFIX, REG_UIMPOSSIBLE, REMAGIC, and guts::tree.

Referenced by regexp_fixed_prefix().

◆ RE_compile_and_cache()

regex_t* RE_compile_and_cache ( text text_re,
int  cflags,
Oid  collation 
)

Definition at line 141 of file regexp.c.

142 {
143  int text_re_len = VARSIZE_ANY_EXHDR(text_re);
144  char *text_re_val = VARDATA_ANY(text_re);
145  pg_wchar *pattern;
146  int pattern_len;
147  int i;
148  int regcomp_result;
149  cached_re_str re_temp;
150  char errMsg[100];
151  MemoryContext oldcontext;
152 
153  /*
154  * Look for a match among previously compiled REs. Since the data
155  * structure is self-organizing with most-used entries at the front, our
156  * search strategy can just be to scan from the front.
157  */
158  for (i = 0; i < num_res; i++)
159  {
160  if (re_array[i].cre_pat_len == text_re_len &&
161  re_array[i].cre_flags == cflags &&
162  re_array[i].cre_collation == collation &&
163  memcmp(re_array[i].cre_pat, text_re_val, text_re_len) == 0)
164  {
165  /*
166  * Found a match; move it to front if not there already.
167  */
168  if (i > 0)
169  {
170  re_temp = re_array[i];
171  memmove(&re_array[1], &re_array[0], i * sizeof(cached_re_str));
172  re_array[0] = re_temp;
173  }
174 
175  return &re_array[0].cre_re;
176  }
177  }
178 
179  /* Set up the cache memory on first go through. */
180  if (unlikely(RegexpCacheMemoryContext == NULL))
183  "RegexpCacheMemoryContext",
185 
186  /*
187  * Couldn't find it, so try to compile the new RE. To avoid leaking
188  * resources on failure, we build into the re_temp local.
189  */
190 
191  /* Convert pattern string to wide characters */
192  pattern = (pg_wchar *) palloc((text_re_len + 1) * sizeof(pg_wchar));
193  pattern_len = pg_mb2wchar_with_len(text_re_val,
194  pattern,
195  text_re_len);
196 
197  /*
198  * Make a memory context for this compiled regexp. This is initially a
199  * child of the current memory context, so it will be cleaned up
200  * automatically if compilation is interrupted and throws an ERROR. We'll
201  * re-parent it under the longer lived cache context if we make it to the
202  * bottom of this function.
203  */
205  "RegexpMemoryContext",
207  oldcontext = MemoryContextSwitchTo(re_temp.cre_context);
208 
209  regcomp_result = pg_regcomp(&re_temp.cre_re,
210  pattern,
211  pattern_len,
212  cflags,
213  collation);
214 
215  pfree(pattern);
216 
217  if (regcomp_result != REG_OKAY)
218  {
219  /* re didn't compile (no need for pg_regfree, if so) */
220  pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
221  ereport(ERROR,
222  (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
223  errmsg("invalid regular expression: %s", errMsg)));
224  }
225 
226  /* Copy the pattern into the per-regexp memory context. */
227  re_temp.cre_pat = palloc(text_re_len + 1);
228  memcpy(re_temp.cre_pat, text_re_val, text_re_len);
229 
230  /*
231  * NUL-terminate it only for the benefit of the identifier used for the
232  * memory context, visible in the pg_backend_memory_contexts view.
233  */
234  re_temp.cre_pat[text_re_len] = 0;
236 
237  re_temp.cre_pat_len = text_re_len;
238  re_temp.cre_flags = cflags;
239  re_temp.cre_collation = collation;
240 
241  /*
242  * Okay, we have a valid new item in re_temp; insert it into the storage
243  * array. Discard last entry if needed.
244  */
245  if (num_res >= MAX_CACHED_RES)
246  {
247  --num_res;
249  /* Delete the memory context holding the regexp and pattern. */
250  MemoryContextDelete(re_array[num_res].cre_context);
251  }
252 
253  /* Re-parent the memory context to our long-lived cache context. */
255 
256  if (num_res > 0)
257  memmove(&re_array[1], &re_array[0], num_res * sizeof(cached_re_str));
258 
259  re_array[0] = re_temp;
260  num_res++;
261 
262  MemoryContextSwitchTo(oldcontext);
263 
264  return &re_array[0].cre_re;
265 }
#define unlikely(x)
Definition: c.h:298
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
Assert(fmt[strlen(fmt) - 1] !='\n')
unsigned int pg_wchar
Definition: mbprint.c:31
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
Definition: mbutils.c:986
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
Definition: mcxt.c:625
void pfree(void *pointer)
Definition: mcxt.c:1508
MemoryContext TopMemoryContext
Definition: mcxt.c:137
MemoryContext CurrentMemoryContext
Definition: mcxt.c:131
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:442
void * palloc(Size size)
Definition: mcxt.c:1304
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
Definition: mcxt.c:600
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_SMALL_SIZES
Definition: memutils.h:163
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
Definition: regcomp.c:370
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
Definition: regerror.c:60
static MemoryContext RegexpCacheMemoryContext
Definition: regexp.c:99
#define MAX_CACHED_RES
Definition: regexp.c:95
static int num_res
Definition: regexp.c:112
static cached_re_str re_array[MAX_CACHED_RES]
Definition: regexp.c:113
char * cre_pat
Definition: regexp.c:105
int cre_pat_len
Definition: regexp.c:106
regex_t cre_re
Definition: regexp.c:109
Oid cre_collation
Definition: regexp.c:108
int cre_flags
Definition: regexp.c:107
MemoryContext cre_context
Definition: regexp.c:104
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

References ALLOCSET_SMALL_SIZES, AllocSetContextCreate, Assert(), cached_re_str::cre_collation, cached_re_str::cre_context, cached_re_str::cre_flags, cached_re_str::cre_pat, cached_re_str::cre_pat_len, cached_re_str::cre_re, CurrentMemoryContext, ereport, errcode(), errmsg(), ERROR, i, MAX_CACHED_RES, MemoryContextDelete(), MemoryContextSetIdentifier(), MemoryContextSetParent(), MemoryContextSwitchTo(), num_res, palloc(), pfree(), pg_mb2wchar_with_len(), pg_regcomp(), pg_regerror(), re_array, REG_OKAY, RegexpCacheMemoryContext, TopMemoryContext, unlikely, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by RE_compile_and_execute(), regexp_fixed_prefix(), replace_text_regexp(), setup_regexp_matches(), and textregexsubstr().

◆ RE_compile_and_execute()

bool RE_compile_and_execute ( text text_re,
char *  dat,
int  dat_len,
int  cflags,
Oid  collation,
int  nmatch,
regmatch_t pmatch 
)

Definition at line 358 of file regexp.c.

361 {
362  regex_t *re;
363 
364  /* Use REG_NOSUB if caller does not want sub-match details */
365  if (nmatch < 2)
366  cflags |= REG_NOSUB;
367 
368  /* Compile RE */
369  re = RE_compile_and_cache(text_re, cflags, collation);
370 
371  return RE_execute(re, dat, dat_len, nmatch, pmatch);
372 }
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
Definition: regexp.c:141
static bool RE_execute(regex_t *re, char *dat, int dat_len, int nmatch, regmatch_t *pmatch)
Definition: regexp.c:324
Definition: regex.h:56

References RE_compile_and_cache(), RE_execute(), and REG_NOSUB.

Referenced by executeLikeRegex(), nameicregexeq(), nameicregexne(), nameregexeq(), nameregexne(), regexp_like(), texticregexeq(), texticregexne(), textregexeq(), and textregexne().