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

Go to the source code of this file.

Data Structures

struct  colordesc
 
struct  colormaprange
 
struct  colormap
 
struct  cvec
 
struct  arc
 
struct  arcbatch
 
struct  state
 
struct  statebatch
 
struct  nfa
 
struct  carc
 
struct  cnfa
 
struct  subre
 
struct  fns
 
struct  guts
 

Macros

#define DISCARD   void /* for throwing values away */
 
#define VS(x)   ((void *)(x)) /* cast something to generic ptr */
 
#define _POSIX2_RE_DUP_MAX   255 /* normally from <limits.h> */
 
#define NOTREACHED   0
 
#define DUPMAX   _POSIX2_RE_DUP_MAX
 
#define DUPINF   (DUPMAX+1)
 
#define REMAGIC   0xfed7 /* magic number for main struct */
 
#define LATYPE_AHEAD_POS   03 /* positive lookahead */
 
#define LATYPE_AHEAD_NEG   02 /* negative lookahead */
 
#define LATYPE_BEHIND_POS   01 /* positive lookbehind */
 
#define LATYPE_BEHIND_NEG   00 /* negative lookbehind */
 
#define LATYPE_IS_POS(la)   ((la) & 01)
 
#define LATYPE_IS_AHEAD(la)   ((la) & 02)
 
#define FDEBUG(arglist)   {}
 
#define MDEBUG(arglist)   {}
 
#define UBITS   (CHAR_BIT * sizeof(unsigned))
 
#define BSET(uv, sn)   ((uv)[(sn)/UBITS] |= (unsigned)1 << ((sn)%UBITS))
 
#define ISBSET(uv, sn)   ((uv)[(sn)/UBITS] & ((unsigned)1 << ((sn)%UBITS)))
 
#define NUM_CCLASSES   14
 
#define MAX_COLOR   32767 /* max color (must fit in 'color' datatype) */
 
#define COLORLESS   (-1) /* impossible color */
 
#define RAINBOW   (-2) /* represents all colors except pseudocolors */
 
#define WHITE   0 /* default color, parent of all others */
 
#define NOSUB   COLORLESS /* value of "sub" when no open subcolor */
 
#define FREECOL   01 /* currently free */
 
#define PSEUDO   02 /* pseudocolor, no real chars */
 
#define COLMARK   04 /* temporary marker used in some functions */
 
#define UNUSEDCOLOR(cd)   ((cd)->flags & FREECOL)
 
#define CMMAGIC   0x876
 
#define CDEND(cm)   (&(cm)->cd[(cm)->max + 1])
 
#define NINLINECDS   ((size_t) 10)
 
#define GETCOLOR(cm, c)    ((c) <= MAX_SIMPLE_CHR ? (cm)->locolormap[(c) - CHR_MIN] : pg_reg_getcolor(cm, c))
 
#define freechain   outchain /* we do not maintain "freechainRev" */
 
#define ARCBATCHSIZE(n)   ((n) * sizeof(struct arc) + offsetof(struct arcbatch, a))
 
#define FIRSTABSIZE   64
 
#define MAXABSIZE   1024
 
#define FREESTATE   (-1)
 
#define STATEBATCHSIZE(n)   ((n) * sizeof(struct state) + offsetof(struct statebatch, s))
 
#define FIRSTSBSIZE   32
 
#define MAXSBSIZE   1024
 
#define HASLACONS   01 /* uses lookaround constraints */
 
#define MATCHALL   02 /* matches all strings of a range of lengths */
 
#define CNFA_NOPROGRESS   01 /* flag bit for a no-progress state */
 
#define ZAPCNFA(cnfa)   ((cnfa).nstates = 0)
 
#define NULLCNFA(cnfa)   ((cnfa).nstates == 0)
 
#define REG_MAX_COMPILE_SPACE    (500000 * (sizeof(struct state) + 4 * sizeof(struct arc)))
 
#define LONGER   01 /* prefers longer match */
 
#define SHORTER   02 /* prefers shorter match */
 
#define MIXED   04 /* mixed preference below */
 
#define CAP   010 /* capturing parens here or below */
 
#define BACKR   020 /* back reference here or below */
 
#define BRUSE   040 /* is referenced by a back reference */
 
#define INUSE   0100 /* in use in final tree */
 
#define UPPROP   (MIXED|CAP|BACKR) /* flags which should propagate up */
 
#define LMIX(f)   ((f)<<2) /* LONGER -> MIXED */
 
#define SMIX(f)   ((f)<<1) /* SHORTER -> MIXED */
 
#define UP(f)   (((f)&UPPROP) | (LMIX(f) & SMIX(f) & MIXED))
 
#define MESSY(f)   ((f)&(MIXED|CAP|BACKR))
 
#define PREF(f)   ((f)&(LONGER|SHORTER))
 
#define PREF2(f1, f2)   ((PREF(f1) != 0) ? PREF(f1) : PREF(f2))
 
#define COMBINE(f1, f2)   (UP((f1)|(f2)) | PREF2(f1, f2))
 
#define CANCEL_REQUESTED(re)    ((*((struct fns *) (re)->re_fns)->cancel_requested) ())
 
#define STACK_TOO_DEEP(re)    ((*((struct fns *) (re)->re_fns)->stack_too_deep) ())
 
#define GUTSMAGIC   0xfed9
 

Typedefs

typedef short color
 
typedef struct colormaprange colormaprange
 

Enumerations

enum  char_classes {
  CC_ALNUM , CC_ALPHA , CC_ASCII , CC_BLANK ,
  CC_CNTRL , CC_DIGIT , CC_GRAPH , CC_LOWER ,
  CC_PRINT , CC_PUNCT , CC_SPACE , CC_UPPER ,
  CC_XDIGIT , CC_WORD
}
 

Functions

void pg_set_regex_collation (Oid collation)
 
color pg_reg_getcolor (struct colormap *cm, chr c)
 

Macro Definition Documentation

◆ _POSIX2_RE_DUP_MAX

#define _POSIX2_RE_DUP_MAX   255 /* normally from <limits.h> */

Definition at line 82 of file regguts.h.

◆ ARCBATCHSIZE

#define ARCBATCHSIZE (   n)    ((n) * sizeof(struct arc) + offsetof(struct arcbatch, a))

Definition at line 312 of file regguts.h.

◆ BACKR

#define BACKR   020 /* back reference here or below */

Definition at line 479 of file regguts.h.

◆ BRUSE

#define BRUSE   040 /* is referenced by a back reference */

Definition at line 480 of file regguts.h.

◆ BSET

#define BSET (   uv,
  sn 
)    ((uv)[(sn)/UBITS] |= (unsigned)1 << ((sn)%UBITS))

Definition at line 126 of file regguts.h.

◆ CANCEL_REQUESTED

#define CANCEL_REQUESTED (   re)     ((*((struct fns *) (re)->re_fns)->cancel_requested) ())

Definition at line 517 of file regguts.h.

◆ CAP

#define CAP   010 /* capturing parens here or below */

Definition at line 478 of file regguts.h.

◆ CDEND

#define CDEND (   cm)    (&(cm)->cd[(cm)->max + 1])

Definition at line 232 of file regguts.h.

◆ CMMAGIC

#define CMMAGIC   0x876

Definition at line 226 of file regguts.h.

◆ CNFA_NOPROGRESS

#define CNFA_NOPROGRESS   01 /* flag bit for a no-progress state */

Definition at line 413 of file regguts.h.

◆ COLMARK

#define COLMARK   04 /* temporary marker used in some functions */

Definition at line 182 of file regguts.h.

◆ COLORLESS

#define COLORLESS   (-1) /* impossible color */

Definition at line 153 of file regguts.h.

◆ COMBINE

#define COMBINE (   f1,
  f2 
)    (UP((f1)|(f2)) | PREF2(f1, f2))

Definition at line 489 of file regguts.h.

◆ DISCARD

#define DISCARD   void /* for throwing values away */

Definition at line 58 of file regguts.h.

◆ DUPINF

#define DUPINF   (DUPMAX+1)

Definition at line 94 of file regguts.h.

◆ DUPMAX

#define DUPMAX   _POSIX2_RE_DUP_MAX

Definition at line 93 of file regguts.h.

◆ FDEBUG

#define FDEBUG (   arglist)    {}

Definition at line 116 of file regguts.h.

◆ FIRSTABSIZE

#define FIRSTABSIZE   64

Definition at line 314 of file regguts.h.

◆ FIRSTSBSIZE

#define FIRSTSBSIZE   32

Definition at line 340 of file regguts.h.

◆ freechain

#define freechain   outchain /* we do not maintain "freechainRev" */

Definition at line 298 of file regguts.h.

◆ FREECOL

#define FREECOL   01 /* currently free */

Definition at line 180 of file regguts.h.

◆ FREESTATE

#define FREESTATE   (-1)

Definition at line 320 of file regguts.h.

◆ GETCOLOR

#define GETCOLOR (   cm,
  c 
)     ((c) <= MAX_SIMPLE_CHR ? (cm)->locolormap[(c) - CHR_MIN] : pg_reg_getcolor(cm, c))

Definition at line 252 of file regguts.h.

◆ GUTSMAGIC

#define GUTSMAGIC   0xfed9

Definition at line 530 of file regguts.h.

◆ HASLACONS

#define HASLACONS   01 /* uses lookaround constraints */

Definition at line 406 of file regguts.h.

◆ INUSE

#define INUSE   0100 /* in use in final tree */

Definition at line 481 of file regguts.h.

◆ ISBSET

#define ISBSET (   uv,
  sn 
)    ((uv)[(sn)/UBITS] & ((unsigned)1 << ((sn)%UBITS)))

Definition at line 127 of file regguts.h.

◆ LATYPE_AHEAD_NEG

#define LATYPE_AHEAD_NEG   02 /* negative lookahead */

Definition at line 100 of file regguts.h.

◆ LATYPE_AHEAD_POS

#define LATYPE_AHEAD_POS   03 /* positive lookahead */

Definition at line 99 of file regguts.h.

◆ LATYPE_BEHIND_NEG

#define LATYPE_BEHIND_NEG   00 /* negative lookbehind */

Definition at line 102 of file regguts.h.

◆ LATYPE_BEHIND_POS

#define LATYPE_BEHIND_POS   01 /* positive lookbehind */

Definition at line 101 of file regguts.h.

◆ LATYPE_IS_AHEAD

#define LATYPE_IS_AHEAD (   la)    ((la) & 02)

Definition at line 104 of file regguts.h.

◆ LATYPE_IS_POS

#define LATYPE_IS_POS (   la)    ((la) & 01)

Definition at line 103 of file regguts.h.

◆ LMIX

#define LMIX (   f)    ((f)<<2) /* LONGER -> MIXED */

Definition at line 483 of file regguts.h.

◆ LONGER

#define LONGER   01 /* prefers longer match */

Definition at line 475 of file regguts.h.

◆ MATCHALL

#define MATCHALL   02 /* matches all strings of a range of lengths */

Definition at line 407 of file regguts.h.

◆ MAX_COLOR

#define MAX_COLOR   32767 /* max color (must fit in 'color' datatype) */

Definition at line 152 of file regguts.h.

◆ MAXABSIZE

#define MAXABSIZE   1024

Definition at line 315 of file regguts.h.

◆ MAXSBSIZE

#define MAXSBSIZE   1024

Definition at line 341 of file regguts.h.

◆ MDEBUG

#define MDEBUG (   arglist)    {}

Definition at line 117 of file regguts.h.

◆ MESSY

#define MESSY (   f)    ((f)&(MIXED|CAP|BACKR))

Definition at line 486 of file regguts.h.

◆ MIXED

#define MIXED   04 /* mixed preference below */

Definition at line 477 of file regguts.h.

◆ NINLINECDS

#define NINLINECDS   ((size_t) 10)

Definition at line 247 of file regguts.h.

◆ NOSUB

#define NOSUB   COLORLESS /* value of "sub" when no open subcolor */

Definition at line 176 of file regguts.h.

◆ NOTREACHED

#define NOTREACHED   0

Definition at line 91 of file regguts.h.

◆ NULLCNFA

#define NULLCNFA (   cnfa)    ((cnfa).nstates == 0)

Definition at line 431 of file regguts.h.

◆ NUM_CCLASSES

#define NUM_CCLASSES   14

Definition at line 139 of file regguts.h.

◆ PREF

#define PREF (   f)    ((f)&(LONGER|SHORTER))

Definition at line 487 of file regguts.h.

◆ PREF2

#define PREF2 (   f1,
  f2 
)    ((PREF(f1) != 0) ? PREF(f1) : PREF(f2))

Definition at line 488 of file regguts.h.

◆ PSEUDO

#define PSEUDO   02 /* pseudocolor, no real chars */

Definition at line 181 of file regguts.h.

◆ RAINBOW

#define RAINBOW   (-2) /* represents all colors except pseudocolors */

Definition at line 154 of file regguts.h.

◆ REG_MAX_COMPILE_SPACE

#define REG_MAX_COMPILE_SPACE    (500000 * (sizeof(struct state) + 4 * sizeof(struct arc)))

Definition at line 444 of file regguts.h.

◆ REMAGIC

#define REMAGIC   0xfed7 /* magic number for main struct */

Definition at line 96 of file regguts.h.

◆ SHORTER

#define SHORTER   02 /* prefers shorter match */

Definition at line 476 of file regguts.h.

◆ SMIX

#define SMIX (   f)    ((f)<<1) /* SHORTER -> MIXED */

Definition at line 484 of file regguts.h.

◆ STACK_TOO_DEEP

#define STACK_TOO_DEEP (   re)     ((*((struct fns *) (re)->re_fns)->stack_too_deep) ())

Definition at line 520 of file regguts.h.

◆ STATEBATCHSIZE

#define STATEBATCHSIZE (   n)    ((n) * sizeof(struct state) + offsetof(struct statebatch, s))

Definition at line 338 of file regguts.h.

◆ UBITS

#define UBITS   (CHAR_BIT * sizeof(unsigned))

Definition at line 125 of file regguts.h.

◆ UNUSEDCOLOR

#define UNUSEDCOLOR (   cd)    ((cd)->flags & FREECOL)

Definition at line 185 of file regguts.h.

◆ UP

#define UP (   f)    (((f)&UPPROP) | (LMIX(f) & SMIX(f) & MIXED))

Definition at line 485 of file regguts.h.

◆ UPPROP

#define UPPROP   (MIXED|CAP|BACKR) /* flags which should propagate up */

Definition at line 482 of file regguts.h.

◆ VS

#define VS (   x)    ((void *)(x)) /* cast something to generic ptr */

Definition at line 61 of file regguts.h.

◆ WHITE

#define WHITE   0 /* default color, parent of all others */

Definition at line 155 of file regguts.h.

◆ ZAPCNFA

#define ZAPCNFA (   cnfa)    ((cnfa).nstates = 0)

Definition at line 429 of file regguts.h.

Typedef Documentation

◆ color

typedef short color

Definition at line 150 of file regguts.h.

◆ colormaprange

typedef struct colormaprange colormaprange

Enumeration Type Documentation

◆ char_classes

Enumerator
CC_ALNUM 
CC_ALPHA 
CC_ASCII 
CC_BLANK 
CC_CNTRL 
CC_DIGIT 
CC_GRAPH 
CC_LOWER 
CC_PRINT 
CC_PUNCT 
CC_SPACE 
CC_UPPER 
CC_XDIGIT 
CC_WORD 

Definition at line 133 of file regguts.h.

134 {
137 };
@ CC_UPPER
Definition: regguts.h:136
@ CC_WORD
Definition: regguts.h:136
@ CC_LOWER
Definition: regguts.h:136
@ CC_ASCII
Definition: regguts.h:135
@ CC_ALNUM
Definition: regguts.h:135
@ CC_XDIGIT
Definition: regguts.h:136
@ CC_PRINT
Definition: regguts.h:136
@ CC_BLANK
Definition: regguts.h:135
@ CC_GRAPH
Definition: regguts.h:135
@ CC_CNTRL
Definition: regguts.h:135
@ CC_SPACE
Definition: regguts.h:136
@ CC_DIGIT
Definition: regguts.h:135
@ CC_ALPHA
Definition: regguts.h:135
@ CC_PUNCT
Definition: regguts.h:136

Function Documentation

◆ pg_reg_getcolor()

color pg_reg_getcolor ( struct colormap cm,
chr  c 
)

Definition at line 120 of file regc_color.c.

121 {
122  int rownum,
123  colnum,
124  low,
125  high;
126 
127  /* Should not be used for chrs in the locolormap */
129 
130  /*
131  * Find which row it's in. The colormapranges are in order, so we can use
132  * binary search.
133  */
134  rownum = 0; /* if no match, use array row zero */
135  low = 0;
136  high = cm->numcmranges;
137  while (low < high)
138  {
139  int middle = low + (high - low) / 2;
140  const colormaprange *cmr = &cm->cmranges[middle];
141 
142  if (c < cmr->cmin)
143  high = middle;
144  else if (c > cmr->cmax)
145  low = middle + 1;
146  else
147  {
148  rownum = cmr->rownum; /* found a match */
149  break;
150  }
151  }
152 
153  /*
154  * Find which column it's in --- this is all locale-dependent.
155  */
156  if (cm->hiarraycols > 1)
157  {
158  colnum = cclass_column_index(cm, c);
159  return cm->hicolormap[rownum * cm->hiarraycols + colnum];
160  }
161  else
162  {
163  /* fast path if no relevant cclasses */
164  return cm->hicolormap[rownum];
165  }
166 }
char * c
static int cclass_column_index(struct colormap *cm, chr c)
Definition: regc_locale.c:675
#define MAX_SIMPLE_CHR
Definition: regcustom.h:94
#define assert(x)
Definition: regcustom.h:63
int hiarraycols
Definition: regguts.h:244
int numcmranges
Definition: regguts.h:239
color * hicolormap
Definition: regguts.h:241
colormaprange * cmranges
Definition: regguts.h:240

References assert, cclass_column_index(), colormap::cmranges, colormap::hiarraycols, colormap::hicolormap, MAX_SIMPLE_CHR, colormap::numcmranges, and colormaprange::rownum.

◆ pg_set_regex_collation()

void pg_set_regex_collation ( Oid  collation)

Definition at line 232 of file regc_pg_locale.c.

233 {
234  if (!OidIsValid(collation))
235  {
236  /*
237  * This typically means that the parser could not resolve a
238  * conflict of implicit collations, so report it that way.
239  */
240  ereport(ERROR,
241  (errcode(ERRCODE_INDETERMINATE_COLLATION),
242  errmsg("could not determine which collation to use for regular expression"),
243  errhint("Use the COLLATE clause to set the collation explicitly.")));
244  }
245 
246  if (lc_ctype_is_c(collation))
247  {
248  /* C/POSIX collations use this path regardless of database encoding */
250  pg_regex_locale = 0;
251  pg_regex_collation = C_COLLATION_OID;
252  }
253  else
254  {
255  /*
256  * NB: pg_newlocale_from_collation will fail if not HAVE_LOCALE_T;
257  * the case of pg_regex_locale != 0 but not HAVE_LOCALE_T does not
258  * have to be considered below.
259  */
261 
263  ereport(ERROR,
264  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
265  errmsg("nondeterministic collations are not supported for regular expressions")));
266 
267 #ifdef USE_ICU
268  if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
270  else
271 #endif
272  if (GetDatabaseEncoding() == PG_UTF8)
273  {
274  if (pg_regex_locale)
276  else
278  }
279  else
280  {
281  if (pg_regex_locale)
283  else
285  }
286 
287  pg_regex_collation = collation;
288  }
289 }
#define OidIsValid(objectId)
Definition: c.h:710
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
int GetDatabaseEncoding(void)
Definition: mbutils.c:1210
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1466
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1371
@ PG_UTF8
Definition: pg_wchar.h:230
static PG_Locale_Strategy pg_regex_strategy
@ PG_REGEX_LOCALE_1BYTE
@ PG_REGEX_LOCALE_WIDE
@ PG_REGEX_LOCALE_1BYTE_L
@ PG_REGEX_LOCALE_ICU
@ PG_REGEX_LOCALE_WIDE_L
@ PG_REGEX_LOCALE_C
static Oid pg_regex_collation
static pg_locale_t pg_regex_locale
bool deterministic
Definition: pg_locale.h:85

References pg_locale_struct::deterministic, ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), lc_ctype_is_c(), OidIsValid, pg_newlocale_from_collation(), pg_regex_collation, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, pg_regex_strategy, PG_UTF8, and pg_locale_struct::provider.

Referenced by pg_regcomp(), pg_regexec(), and pg_regprefix().