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 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 87 of file regguts.h.

◆ ARCBATCHSIZE

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

Definition at line 317 of file regguts.h.

◆ BACKR

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

Definition at line 484 of file regguts.h.

◆ BRUSE

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

Definition at line 485 of file regguts.h.

◆ BSET

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

Definition at line 131 of file regguts.h.

◆ CAP

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

Definition at line 483 of file regguts.h.

◆ CDEND

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

Definition at line 237 of file regguts.h.

◆ CMMAGIC

#define CMMAGIC   0x876

Definition at line 231 of file regguts.h.

◆ CNFA_NOPROGRESS

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

Definition at line 418 of file regguts.h.

◆ COLMARK

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

Definition at line 187 of file regguts.h.

◆ COLORLESS

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

Definition at line 158 of file regguts.h.

◆ COMBINE

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

Definition at line 494 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 99 of file regguts.h.

◆ DUPMAX

#define DUPMAX   _POSIX2_RE_DUP_MAX

Definition at line 98 of file regguts.h.

◆ FDEBUG

#define FDEBUG (   arglist)    {}

Definition at line 121 of file regguts.h.

◆ FIRSTABSIZE

#define FIRSTABSIZE   64

Definition at line 319 of file regguts.h.

◆ FIRSTSBSIZE

#define FIRSTSBSIZE   32

Definition at line 345 of file regguts.h.

◆ freechain

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

Definition at line 303 of file regguts.h.

◆ FREECOL

#define FREECOL   01 /* currently free */

Definition at line 185 of file regguts.h.

◆ FREESTATE

#define FREESTATE   (-1)

Definition at line 325 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 257 of file regguts.h.

◆ GUTSMAGIC

#define GUTSMAGIC   0xfed9

Definition at line 531 of file regguts.h.

◆ HASLACONS

#define HASLACONS   01 /* uses lookaround constraints */

Definition at line 411 of file regguts.h.

◆ INUSE

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

Definition at line 486 of file regguts.h.

◆ ISBSET

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

Definition at line 132 of file regguts.h.

◆ LATYPE_AHEAD_NEG

#define LATYPE_AHEAD_NEG   02 /* negative lookahead */

Definition at line 105 of file regguts.h.

◆ LATYPE_AHEAD_POS

#define LATYPE_AHEAD_POS   03 /* positive lookahead */

Definition at line 104 of file regguts.h.

◆ LATYPE_BEHIND_NEG

#define LATYPE_BEHIND_NEG   00 /* negative lookbehind */

Definition at line 107 of file regguts.h.

◆ LATYPE_BEHIND_POS

#define LATYPE_BEHIND_POS   01 /* positive lookbehind */

Definition at line 106 of file regguts.h.

◆ LATYPE_IS_AHEAD

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

Definition at line 109 of file regguts.h.

◆ LATYPE_IS_POS

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

Definition at line 108 of file regguts.h.

◆ LMIX

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

Definition at line 488 of file regguts.h.

◆ LONGER

#define LONGER   01 /* prefers longer match */

Definition at line 480 of file regguts.h.

◆ MATCHALL

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

Definition at line 412 of file regguts.h.

◆ MAX_COLOR

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

Definition at line 157 of file regguts.h.

◆ MAXABSIZE

#define MAXABSIZE   1024

Definition at line 320 of file regguts.h.

◆ MAXSBSIZE

#define MAXSBSIZE   1024

Definition at line 346 of file regguts.h.

◆ MDEBUG

#define MDEBUG (   arglist)    {}

Definition at line 122 of file regguts.h.

◆ MESSY

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

Definition at line 491 of file regguts.h.

◆ MIXED

#define MIXED   04 /* mixed preference below */

Definition at line 482 of file regguts.h.

◆ NINLINECDS

#define NINLINECDS   ((size_t) 10)

Definition at line 252 of file regguts.h.

◆ NOSUB

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

Definition at line 181 of file regguts.h.

◆ NOTREACHED

#define NOTREACHED   0

Definition at line 96 of file regguts.h.

◆ NULLCNFA

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

Definition at line 436 of file regguts.h.

◆ NUM_CCLASSES

#define NUM_CCLASSES   14

Definition at line 144 of file regguts.h.

◆ PREF

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

Definition at line 492 of file regguts.h.

◆ PREF2

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

Definition at line 493 of file regguts.h.

◆ PSEUDO

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

Definition at line 186 of file regguts.h.

◆ RAINBOW

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

Definition at line 159 of file regguts.h.

◆ REG_MAX_COMPILE_SPACE

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

Definition at line 449 of file regguts.h.

◆ REMAGIC

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

Definition at line 101 of file regguts.h.

◆ SHORTER

#define SHORTER   02 /* prefers shorter match */

Definition at line 481 of file regguts.h.

◆ SMIX

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

Definition at line 489 of file regguts.h.

◆ STACK_TOO_DEEP

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

Definition at line 521 of file regguts.h.

◆ STATEBATCHSIZE

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

Definition at line 343 of file regguts.h.

◆ UBITS

#define UBITS   (CHAR_BIT * sizeof(unsigned))

Definition at line 130 of file regguts.h.

◆ UNUSEDCOLOR

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

Definition at line 190 of file regguts.h.

◆ UP

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

Definition at line 490 of file regguts.h.

◆ UPPROP

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

Definition at line 487 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 160 of file regguts.h.

◆ ZAPCNFA

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

Definition at line 434 of file regguts.h.

Typedef Documentation

◆ color

typedef short color

Definition at line 155 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 138 of file regguts.h.

139 {
142 };
@ CC_UPPER
Definition: regguts.h:141
@ CC_WORD
Definition: regguts.h:141
@ CC_LOWER
Definition: regguts.h:141
@ CC_ASCII
Definition: regguts.h:140
@ CC_ALNUM
Definition: regguts.h:140
@ CC_XDIGIT
Definition: regguts.h:141
@ CC_PRINT
Definition: regguts.h:141
@ CC_BLANK
Definition: regguts.h:140
@ CC_GRAPH
Definition: regguts.h:140
@ CC_CNTRL
Definition: regguts.h:140
@ CC_SPACE
Definition: regguts.h:141
@ CC_DIGIT
Definition: regguts.h:140
@ CC_ALPHA
Definition: regguts.h:140
@ CC_PUNCT
Definition: regguts.h:141

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:671
#define MAX_SIMPLE_CHR
Definition: regcustom.h:87
#define assert(x)
Definition: regcustom.h:56
int hiarraycols
Definition: regguts.h:249
int numcmranges
Definition: regguts.h:244
color * hicolormap
Definition: regguts.h:246
colormaprange * cmranges
Definition: regguts.h:245

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 231 of file regc_pg_locale.c.

232 {
233  if (!OidIsValid(collation))
234  {
235  /*
236  * This typically means that the parser could not resolve a conflict
237  * of implicit collations, so report it that way.
238  */
239  ereport(ERROR,
240  (errcode(ERRCODE_INDETERMINATE_COLLATION),
241  errmsg("could not determine which collation to use for regular expression"),
242  errhint("Use the COLLATE clause to set the collation explicitly.")));
243  }
244 
245  if (lc_ctype_is_c(collation))
246  {
247  /* C/POSIX collations use this path regardless of database encoding */
249  pg_regex_locale = 0;
250  pg_regex_collation = C_COLLATION_OID;
251  }
252  else
253  {
255 
257  ereport(ERROR,
258  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
259  errmsg("nondeterministic collations are not supported for regular expressions")));
260 
261 #ifdef USE_ICU
262  if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
264  else
265 #endif
266  if (GetDatabaseEncoding() == PG_UTF8)
267  {
268  if (pg_regex_locale)
270  else
272  }
273  else
274  {
275  if (pg_regex_locale)
277  else
279  }
280 
281  pg_regex_collation = collation;
282  }
283 }
#define OidIsValid(objectId)
Definition: c.h:762
int errhint(const char *fmt,...)
Definition: elog.c:1319
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int GetDatabaseEncoding(void)
Definition: mbutils.c:1261
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1545
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1378
bool pg_locale_deterministic(pg_locale_t locale)
Definition: pg_locale.c:1525
@ PG_UTF8
Definition: pg_wchar.h:232
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

References ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), lc_ctype_is_c(), OidIsValid, pg_locale_deterministic(), 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().