PostgreSQL Source Code  git master
regc_pg_locale.c File Reference
Include dependency graph for regc_pg_locale.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pg_ctype_cache
 

Macros

#define PG_ISDIGIT   0x01
 
#define PG_ISALPHA   0x02
 
#define PG_ISALNUM   (PG_ISDIGIT | PG_ISALPHA)
 
#define PG_ISUPPER   0x04
 
#define PG_ISLOWER   0x08
 
#define PG_ISGRAPH   0x10
 
#define PG_ISPRINT   0x20
 
#define PG_ISPUNCT   0x40
 
#define PG_ISSPACE   0x80
 

Typedefs

typedef int(* pg_wc_probefunc) (pg_wchar c)
 
typedef struct pg_ctype_cache pg_ctype_cache
 

Enumerations

enum  PG_Locale_Strategy {
  PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_WIDE_L,
  PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_ICU
}
 

Functions

void pg_set_regex_collation (Oid collation)
 
static int pg_wc_isdigit (pg_wchar c)
 
static int pg_wc_isalpha (pg_wchar c)
 
static int pg_wc_isalnum (pg_wchar c)
 
static int pg_wc_isupper (pg_wchar c)
 
static int pg_wc_islower (pg_wchar c)
 
static int pg_wc_isgraph (pg_wchar c)
 
static int pg_wc_isprint (pg_wchar c)
 
static int pg_wc_ispunct (pg_wchar c)
 
static int pg_wc_isspace (pg_wchar c)
 
static pg_wchar pg_wc_toupper (pg_wchar c)
 
static pg_wchar pg_wc_tolower (pg_wchar c)
 
static bool store_match (pg_ctype_cache *pcc, pg_wchar chr1, int nchrs)
 
static struct cvecpg_ctype_get_cache (pg_wc_probefunc probefunc, int cclasscode)
 

Variables

static PG_Locale_Strategy pg_regex_strategy
 
static pg_locale_t pg_regex_locale
 
static Oid pg_regex_collation
 
static const unsigned char pg_char_properties [128]
 
static pg_ctype_cachepg_ctype_cache_list = NULL
 

Macro Definition Documentation

◆ PG_ISALNUM

#define PG_ISALNUM   (PG_ISDIGIT | PG_ISALPHA)

Definition at line 84 of file regc_pg_locale.c.

Referenced by pg_wc_isalnum().

◆ PG_ISALPHA

#define PG_ISALPHA   0x02

Definition at line 83 of file regc_pg_locale.c.

Referenced by pg_wc_isalpha().

◆ PG_ISDIGIT

#define PG_ISDIGIT   0x01

Definition at line 82 of file regc_pg_locale.c.

Referenced by pg_wc_isdigit().

◆ PG_ISGRAPH

#define PG_ISGRAPH   0x10

Definition at line 87 of file regc_pg_locale.c.

Referenced by pg_wc_isgraph().

◆ PG_ISLOWER

#define PG_ISLOWER   0x08

Definition at line 86 of file regc_pg_locale.c.

Referenced by pg_wc_islower().

◆ PG_ISPRINT

#define PG_ISPRINT   0x20

Definition at line 88 of file regc_pg_locale.c.

Referenced by pg_wc_isprint().

◆ PG_ISPUNCT

#define PG_ISPUNCT   0x40

Definition at line 89 of file regc_pg_locale.c.

Referenced by pg_wc_ispunct().

◆ PG_ISSPACE

#define PG_ISSPACE   0x80

Definition at line 90 of file regc_pg_locale.c.

Referenced by pg_wc_isspace().

◆ PG_ISUPPER

#define PG_ISUPPER   0x04

Definition at line 85 of file regc_pg_locale.c.

Referenced by pg_wc_isupper().

Typedef Documentation

◆ pg_ctype_cache

◆ pg_wc_probefunc

typedef int(* pg_wc_probefunc) (pg_wchar c)

Definition at line 716 of file regc_pg_locale.c.

Enumeration Type Documentation

◆ PG_Locale_Strategy

Enumerator
PG_REGEX_LOCALE_C 
PG_REGEX_LOCALE_WIDE 
PG_REGEX_LOCALE_1BYTE 
PG_REGEX_LOCALE_WIDE_L 
PG_REGEX_LOCALE_1BYTE_L 
PG_REGEX_LOCALE_ICU 

Definition at line 65 of file regc_pg_locale.c.

66 {
67  PG_REGEX_LOCALE_C, /* C locale (encoding independent) */
68  PG_REGEX_LOCALE_WIDE, /* Use <wctype.h> functions */
69  PG_REGEX_LOCALE_1BYTE, /* Use <ctype.h> functions */
70  PG_REGEX_LOCALE_WIDE_L, /* Use locale_t <wctype.h> functions */
71  PG_REGEX_LOCALE_1BYTE_L, /* Use locale_t <ctype.h> functions */
72  PG_REGEX_LOCALE_ICU /* Use ICU uchar.h functions */
PG_Locale_Strategy

Function Documentation

◆ pg_ctype_get_cache()

static struct cvec* pg_ctype_get_cache ( pg_wc_probefunc  probefunc,
int  cclasscode 
)
static

Definition at line 776 of file regc_pg_locale.c.

References cvec::cclasscode, cvec::chrs, cvec::chrspace, pg_ctype_cache::collation, pg_ctype_cache::cv, free, malloc, MAX_SIMPLE_CHR, cvec::nchrs, pg_ctype_cache::next, cvec::nranges, pg_ctype_cache_list, pg_regex_collation, 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_ctype_cache::probefunc, cvec::ranges, cvec::rangespace, realloc, and store_match().

Referenced by cclass().

777 {
778  pg_ctype_cache *pcc;
779  pg_wchar max_chr;
780  pg_wchar cur_chr;
781  int nmatches;
782  chr *newchrs;
783 
784  /*
785  * Do we already have the answer cached?
786  */
787  for (pcc = pg_ctype_cache_list; pcc != NULL; pcc = pcc->next)
788  {
789  if (pcc->probefunc == probefunc &&
791  return &pcc->cv;
792  }
793 
794  /*
795  * Nope, so initialize some workspace ...
796  */
797  pcc = (pg_ctype_cache *) malloc(sizeof(pg_ctype_cache));
798  if (pcc == NULL)
799  return NULL;
800  pcc->probefunc = probefunc;
802  pcc->cv.nchrs = 0;
803  pcc->cv.chrspace = 128;
804  pcc->cv.chrs = (chr *) malloc(pcc->cv.chrspace * sizeof(chr));
805  pcc->cv.nranges = 0;
806  pcc->cv.rangespace = 64;
807  pcc->cv.ranges = (chr *) malloc(pcc->cv.rangespace * sizeof(chr) * 2);
808  if (pcc->cv.chrs == NULL || pcc->cv.ranges == NULL)
809  goto out_of_memory;
810  pcc->cv.cclasscode = cclasscode;
811 
812  /*
813  * Decide how many character codes we ought to look through. In general
814  * we don't go past MAX_SIMPLE_CHR; chr codes above that are handled at
815  * runtime using the "high colormap" mechanism. However, in C locale
816  * there's no need to go further than 127, and if we only have a 1-byte
817  * <ctype.h> API there's no need to go further than that can handle.
818  *
819  * If it's not MAX_SIMPLE_CHR that's constraining the search, mark the
820  * output cvec as not having any locale-dependent behavior, since there
821  * will be no need to do any run-time locale checks. (The #if's here
822  * would always be true for production values of MAX_SIMPLE_CHR, but it's
823  * useful to allow it to be small for testing purposes.)
824  */
825  switch (pg_regex_strategy)
826  {
827  case PG_REGEX_LOCALE_C:
828 #if MAX_SIMPLE_CHR >= 127
829  max_chr = (pg_wchar) 127;
830  pcc->cv.cclasscode = -1;
831 #else
832  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
833 #endif
834  break;
837  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
838  break;
841 #if MAX_SIMPLE_CHR >= UCHAR_MAX
842  max_chr = (pg_wchar) UCHAR_MAX;
843  pcc->cv.cclasscode = -1;
844 #else
845  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
846 #endif
847  break;
848  case PG_REGEX_LOCALE_ICU:
849  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
850  break;
851  default:
852  max_chr = 0; /* can't get here, but keep compiler quiet */
853  break;
854  }
855 
856  /*
857  * And scan 'em ...
858  */
859  nmatches = 0; /* number of consecutive matches */
860 
861  for (cur_chr = 0; cur_chr <= max_chr; cur_chr++)
862  {
863  if ((*probefunc) (cur_chr))
864  nmatches++;
865  else if (nmatches > 0)
866  {
867  if (!store_match(pcc, cur_chr - nmatches, nmatches))
868  goto out_of_memory;
869  nmatches = 0;
870  }
871  }
872 
873  if (nmatches > 0)
874  if (!store_match(pcc, cur_chr - nmatches, nmatches))
875  goto out_of_memory;
876 
877  /*
878  * We might have allocated more memory than needed, if so free it
879  */
880  if (pcc->cv.nchrs == 0)
881  {
882  free(pcc->cv.chrs);
883  pcc->cv.chrs = NULL;
884  pcc->cv.chrspace = 0;
885  }
886  else if (pcc->cv.nchrs < pcc->cv.chrspace)
887  {
888  newchrs = (chr *) realloc(pcc->cv.chrs,
889  pcc->cv.nchrs * sizeof(chr));
890  if (newchrs == NULL)
891  goto out_of_memory;
892  pcc->cv.chrs = newchrs;
893  pcc->cv.chrspace = pcc->cv.nchrs;
894  }
895  if (pcc->cv.nranges == 0)
896  {
897  free(pcc->cv.ranges);
898  pcc->cv.ranges = NULL;
899  pcc->cv.rangespace = 0;
900  }
901  else if (pcc->cv.nranges < pcc->cv.rangespace)
902  {
903  newchrs = (chr *) realloc(pcc->cv.ranges,
904  pcc->cv.nranges * sizeof(chr) * 2);
905  if (newchrs == NULL)
906  goto out_of_memory;
907  pcc->cv.ranges = newchrs;
908  pcc->cv.rangespace = pcc->cv.nranges;
909  }
910 
911  /*
912  * Success, link it into cache chain
913  */
914  pcc->next = pg_ctype_cache_list;
915  pg_ctype_cache_list = pcc;
916 
917  return &pcc->cv;
918 
919  /*
920  * Failure, clean up
921  */
922 out_of_memory:
923  if (pcc->cv.chrs)
924  free(pcc->cv.chrs);
925  if (pcc->cv.ranges)
926  free(pcc->cv.ranges);
927  free(pcc);
928 
929  return NULL;
930 }
struct cvec cv
pg_wc_probefunc probefunc
static Oid pg_regex_collation
static PG_Locale_Strategy pg_regex_strategy
int chrspace
Definition: regguts.h:259
#define malloc(a)
Definition: header.h:50
pg_wchar chr
Definition: regcustom.h:68
chr * ranges
Definition: regguts.h:263
int nchrs
Definition: regguts.h:258
int cclasscode
Definition: regguts.h:264
struct pg_ctype_cache * next
unsigned int pg_wchar
Definition: mbprint.c:31
static pg_ctype_cache * pg_ctype_cache_list
#define free(a)
Definition: header.h:65
chr * chrs
Definition: regguts.h:260
int rangespace
Definition: regguts.h:262
static bool store_match(pg_ctype_cache *pcc, pg_wchar chr1, int nchrs)
#define realloc(a, b)
Definition: header.h:60
int nranges
Definition: regguts.h:261
#define MAX_SIMPLE_CHR
Definition: regcustom.h:97

◆ pg_set_regex_collation()

void pg_set_regex_collation ( Oid  collation)

Definition at line 232 of file regc_pg_locale.c.

References C_COLLATION_OID, COLLPROVIDER_ICU, DEFAULT_COLLATION_OID, ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), lc_ctype_is_c(), OidIsValid, pg_newlocale_from_collation(), pg_regex_collation, 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().

233 {
234  if (lc_ctype_is_c(collation))
235  {
236  /* C/POSIX collations use this path regardless of database encoding */
238  pg_regex_locale = 0;
240  }
241  else
242  {
243  if (collation == DEFAULT_COLLATION_OID)
244  pg_regex_locale = 0;
245  else if (OidIsValid(collation))
246  {
247  /*
248  * NB: pg_newlocale_from_collation will fail if not HAVE_LOCALE_T;
249  * the case of pg_regex_locale != 0 but not HAVE_LOCALE_T does not
250  * have to be considered below.
251  */
253  }
254  else
255  {
256  /*
257  * This typically means that the parser could not resolve a
258  * conflict of implicit collations, so report it that way.
259  */
260  ereport(ERROR,
261  (errcode(ERRCODE_INDETERMINATE_COLLATION),
262  errmsg("could not determine which collation to use for regular expression"),
263  errhint("Use the COLLATE clause to set the collation explicitly.")));
264  }
265 
266 #ifdef USE_ICU
269  else
270 #endif
271  if (GetDatabaseEncoding() == PG_UTF8)
272  {
273  if (pg_regex_locale)
275  else
277  }
278  else
279  {
280  if (pg_regex_locale)
282  else
284  }
285 
286  pg_regex_collation = collation;
287  }
288 }
#define COLLPROVIDER_ICU
Definition: pg_collation.h:85
int errhint(const char *fmt,...)
Definition: elog.c:987
static pg_locale_t pg_regex_locale
static Oid pg_regex_collation
static PG_Locale_Strategy pg_regex_strategy
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:576
#define ERROR
Definition: elog.h:43
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
#define ereport(elevel, rest)
Definition: elog.h:122
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1275
int GetDatabaseEncoding(void)
Definition: mbutils.c:1004
#define C_COLLATION_OID
Definition: pg_collation.h:78
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1178

◆ pg_wc_isalnum()

static int pg_wc_isalnum ( pg_wchar  c)
static

Definition at line 363 of file regc_pg_locale.c.

References pg_locale_struct::info, isalnum_l, iswalnum_l, pg_char_properties, PG_ISALNUM, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

364 {
365  switch (pg_regex_strategy)
366  {
367  case PG_REGEX_LOCALE_C:
368  return (c <= (pg_wchar) 127 &&
371  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
372  return iswalnum((wint_t) c);
373  /* FALL THRU */
375  return (c <= (pg_wchar) UCHAR_MAX &&
376  isalnum((unsigned char) c));
378 #ifdef HAVE_LOCALE_T
379  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
380  return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
381 #endif
382  /* FALL THRU */
384 #ifdef HAVE_LOCALE_T
385  return (c <= (pg_wchar) UCHAR_MAX &&
386  isalnum_l((unsigned char) c, pg_regex_locale->info.lt));
387 #endif
388  break;
389  case PG_REGEX_LOCALE_ICU:
390 #ifdef USE_ICU
391  return u_isalnum(c);
392 #endif
393  break;
394  }
395  return 0; /* can't get here, but keep compiler quiet */
396 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define isalnum_l
Definition: win32_port.h:383
#define PG_ISALNUM
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswalnum_l
Definition: win32_port.h:384

◆ pg_wc_isalpha()

static int pg_wc_isalpha ( pg_wchar  c)
static

Definition at line 327 of file regc_pg_locale.c.

References pg_locale_struct::info, isalpha_l, iswalpha_l, pg_char_properties, PG_ISALPHA, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

328 {
329  switch (pg_regex_strategy)
330  {
331  case PG_REGEX_LOCALE_C:
332  return (c <= (pg_wchar) 127 &&
335  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
336  return iswalpha((wint_t) c);
337  /* FALL THRU */
339  return (c <= (pg_wchar) UCHAR_MAX &&
340  isalpha((unsigned char) c));
342 #ifdef HAVE_LOCALE_T
343  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
344  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
345 #endif
346  /* FALL THRU */
348 #ifdef HAVE_LOCALE_T
349  return (c <= (pg_wchar) UCHAR_MAX &&
350  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
351 #endif
352  break;
353  case PG_REGEX_LOCALE_ICU:
354 #ifdef USE_ICU
355  return u_isalpha(c);
356 #endif
357  break;
358  }
359  return 0; /* can't get here, but keep compiler quiet */
360 }
#define PG_ISALPHA
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define isalpha_l
Definition: win32_port.h:381
#define iswalpha_l
Definition: win32_port.h:382
char * c
unsigned int pg_wchar
Definition: mbprint.c:31

◆ pg_wc_isdigit()

static int pg_wc_isdigit ( pg_wchar  c)
static

Definition at line 291 of file regc_pg_locale.c.

References pg_locale_struct::info, isdigit_l, iswdigit_l, pg_char_properties, PG_ISDIGIT, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

292 {
293  switch (pg_regex_strategy)
294  {
295  case PG_REGEX_LOCALE_C:
296  return (c <= (pg_wchar) 127 &&
299  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
300  return iswdigit((wint_t) c);
301  /* FALL THRU */
303  return (c <= (pg_wchar) UCHAR_MAX &&
304  isdigit((unsigned char) c));
306 #ifdef HAVE_LOCALE_T
307  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
308  return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
309 #endif
310  /* FALL THRU */
312 #ifdef HAVE_LOCALE_T
313  return (c <= (pg_wchar) UCHAR_MAX &&
314  isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
315 #endif
316  break;
317  case PG_REGEX_LOCALE_ICU:
318 #ifdef USE_ICU
319  return u_isdigit(c);
320 #endif
321  break;
322  }
323  return 0; /* can't get here, but keep compiler quiet */
324 }
#define isdigit_l
Definition: win32_port.h:379
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswdigit_l
Definition: win32_port.h:380
#define PG_ISDIGIT

◆ pg_wc_isgraph()

static int pg_wc_isgraph ( pg_wchar  c)
static

Definition at line 471 of file regc_pg_locale.c.

References pg_locale_struct::info, isgraph_l, iswgraph_l, pg_char_properties, PG_ISGRAPH, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

472 {
473  switch (pg_regex_strategy)
474  {
475  case PG_REGEX_LOCALE_C:
476  return (c <= (pg_wchar) 127 &&
479  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
480  return iswgraph((wint_t) c);
481  /* FALL THRU */
483  return (c <= (pg_wchar) UCHAR_MAX &&
484  isgraph((unsigned char) c));
486 #ifdef HAVE_LOCALE_T
487  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
488  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
489 #endif
490  /* FALL THRU */
492 #ifdef HAVE_LOCALE_T
493  return (c <= (pg_wchar) UCHAR_MAX &&
494  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
495 #endif
496  break;
497  case PG_REGEX_LOCALE_ICU:
498 #ifdef USE_ICU
499  return u_isgraph(c);
500 #endif
501  break;
502  }
503  return 0; /* can't get here, but keep compiler quiet */
504 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define PG_ISGRAPH
char * c
#define isgraph_l
Definition: win32_port.h:389
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswgraph_l
Definition: win32_port.h:390

◆ pg_wc_islower()

static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 435 of file regc_pg_locale.c.

References pg_locale_struct::info, islower_l, iswlower_l, pg_char_properties, PG_ISLOWER, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

436 {
437  switch (pg_regex_strategy)
438  {
439  case PG_REGEX_LOCALE_C:
440  return (c <= (pg_wchar) 127 &&
443  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
444  return iswlower((wint_t) c);
445  /* FALL THRU */
447  return (c <= (pg_wchar) UCHAR_MAX &&
448  islower((unsigned char) c));
450 #ifdef HAVE_LOCALE_T
451  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
452  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
453 #endif
454  /* FALL THRU */
456 #ifdef HAVE_LOCALE_T
457  return (c <= (pg_wchar) UCHAR_MAX &&
458  islower_l((unsigned char) c, pg_regex_locale->info.lt));
459 #endif
460  break;
461  case PG_REGEX_LOCALE_ICU:
462 #ifdef USE_ICU
463  return u_islower(c);
464 #endif
465  break;
466  }
467  return 0; /* can't get here, but keep compiler quiet */
468 }
static const unsigned char pg_char_properties[128]
#define islower_l
Definition: win32_port.h:387
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define iswlower_l
Definition: win32_port.h:388
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define PG_ISLOWER

◆ pg_wc_isprint()

static int pg_wc_isprint ( pg_wchar  c)
static

Definition at line 507 of file regc_pg_locale.c.

References pg_locale_struct::info, isprint_l, iswprint_l, pg_char_properties, PG_ISPRINT, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

508 {
509  switch (pg_regex_strategy)
510  {
511  case PG_REGEX_LOCALE_C:
512  return (c <= (pg_wchar) 127 &&
515  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
516  return iswprint((wint_t) c);
517  /* FALL THRU */
519  return (c <= (pg_wchar) UCHAR_MAX &&
520  isprint((unsigned char) c));
522 #ifdef HAVE_LOCALE_T
523  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
524  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
525 #endif
526  /* FALL THRU */
528 #ifdef HAVE_LOCALE_T
529  return (c <= (pg_wchar) UCHAR_MAX &&
530  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
531 #endif
532  break;
533  case PG_REGEX_LOCALE_ICU:
534 #ifdef USE_ICU
535  return u_isprint(c);
536 #endif
537  break;
538  }
539  return 0; /* can't get here, but keep compiler quiet */
540 }
#define PG_ISPRINT
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define isprint_l
Definition: win32_port.h:391
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswprint_l
Definition: win32_port.h:392

◆ pg_wc_ispunct()

static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 543 of file regc_pg_locale.c.

References pg_locale_struct::info, ispunct_l, iswpunct_l, pg_char_properties, PG_ISPUNCT, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

544 {
545  switch (pg_regex_strategy)
546  {
547  case PG_REGEX_LOCALE_C:
548  return (c <= (pg_wchar) 127 &&
551  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
552  return iswpunct((wint_t) c);
553  /* FALL THRU */
555  return (c <= (pg_wchar) UCHAR_MAX &&
556  ispunct((unsigned char) c));
558 #ifdef HAVE_LOCALE_T
559  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
560  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
561 #endif
562  /* FALL THRU */
564 #ifdef HAVE_LOCALE_T
565  return (c <= (pg_wchar) UCHAR_MAX &&
566  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
567 #endif
568  break;
569  case PG_REGEX_LOCALE_ICU:
570 #ifdef USE_ICU
571  return u_ispunct(c);
572 #endif
573  break;
574  }
575  return 0; /* can't get here, but keep compiler quiet */
576 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define ispunct_l
Definition: win32_port.h:393
union pg_locale_struct::@120 info
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswpunct_l
Definition: win32_port.h:394
#define PG_ISPUNCT

◆ pg_wc_isspace()

static int pg_wc_isspace ( pg_wchar  c)
static

Definition at line 579 of file regc_pg_locale.c.

References pg_locale_struct::info, isspace_l, iswspace_l, pg_char_properties, PG_ISSPACE, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

580 {
581  switch (pg_regex_strategy)
582  {
583  case PG_REGEX_LOCALE_C:
584  return (c <= (pg_wchar) 127 &&
587  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
588  return iswspace((wint_t) c);
589  /* FALL THRU */
591  return (c <= (pg_wchar) UCHAR_MAX &&
592  isspace((unsigned char) c));
594 #ifdef HAVE_LOCALE_T
595  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
596  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
597 #endif
598  /* FALL THRU */
600 #ifdef HAVE_LOCALE_T
601  return (c <= (pg_wchar) UCHAR_MAX &&
602  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
603 #endif
604  break;
605  case PG_REGEX_LOCALE_ICU:
606 #ifdef USE_ICU
607  return u_isspace(c);
608 #endif
609  break;
610  }
611  return 0; /* can't get here, but keep compiler quiet */
612 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define iswspace_l
Definition: win32_port.h:396
#define PG_ISSPACE
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define isspace_l
Definition: win32_port.h:395

◆ pg_wc_isupper()

static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 399 of file regc_pg_locale.c.

References pg_locale_struct::info, isupper_l, iswupper_l, pg_char_properties, PG_ISUPPER, 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, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

400 {
401  switch (pg_regex_strategy)
402  {
403  case PG_REGEX_LOCALE_C:
404  return (c <= (pg_wchar) 127 &&
407  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
408  return iswupper((wint_t) c);
409  /* FALL THRU */
411  return (c <= (pg_wchar) UCHAR_MAX &&
412  isupper((unsigned char) c));
414 #ifdef HAVE_LOCALE_T
415  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
416  return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
417 #endif
418  /* FALL THRU */
420 #ifdef HAVE_LOCALE_T
421  return (c <= (pg_wchar) UCHAR_MAX &&
422  isupper_l((unsigned char) c, pg_regex_locale->info.lt));
423 #endif
424  break;
425  case PG_REGEX_LOCALE_ICU:
426 #ifdef USE_ICU
427  return u_isupper(c);
428 #endif
429  break;
430  }
431  return 0; /* can't get here, but keep compiler quiet */
432 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define PG_ISUPPER
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define isupper_l
Definition: win32_port.h:385
#define iswupper_l
Definition: win32_port.h:386

◆ pg_wc_tolower()

static pg_wchar pg_wc_tolower ( pg_wchar  c)
static

Definition at line 659 of file regc_pg_locale.c.

References pg_locale_struct::info, pg_ascii_tolower(), 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, tolower_l, and towlower_l.

Referenced by allcases(), casecmp(), and range().

660 {
661  switch (pg_regex_strategy)
662  {
663  case PG_REGEX_LOCALE_C:
664  if (c <= (pg_wchar) 127)
665  return pg_ascii_tolower((unsigned char) c);
666  return c;
668  /* force C behavior for ASCII characters, per comments above */
669  if (c <= (pg_wchar) 127)
670  return pg_ascii_tolower((unsigned char) c);
671  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
672  return towlower((wint_t) c);
673  /* FALL THRU */
675  /* force C behavior for ASCII characters, per comments above */
676  if (c <= (pg_wchar) 127)
677  return pg_ascii_tolower((unsigned char) c);
678  if (c <= (pg_wchar) UCHAR_MAX)
679  return tolower((unsigned char) c);
680  return c;
682 #ifdef HAVE_LOCALE_T
683  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
684  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
685 #endif
686  /* FALL THRU */
688 #ifdef HAVE_LOCALE_T
689  if (c <= (pg_wchar) UCHAR_MAX)
690  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
691 #endif
692  return c;
693  case PG_REGEX_LOCALE_ICU:
694 #ifdef USE_ICU
695  return u_tolower(c);
696 #endif
697  break;
698  }
699  return 0; /* can't get here, but keep compiler quiet */
700 }
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
unsigned char pg_ascii_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:146
union pg_locale_struct::@120 info
#define towlower_l
Definition: win32_port.h:377
#define tolower_l
Definition: win32_port.h:375
char * c
unsigned int pg_wchar
Definition: mbprint.c:31

◆ pg_wc_toupper()

static pg_wchar pg_wc_toupper ( pg_wchar  c)
static

Definition at line 615 of file regc_pg_locale.c.

References pg_locale_struct::info, pg_ascii_toupper(), 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, toupper_l, and towupper_l.

Referenced by allcases(), and range().

616 {
617  switch (pg_regex_strategy)
618  {
619  case PG_REGEX_LOCALE_C:
620  if (c <= (pg_wchar) 127)
621  return pg_ascii_toupper((unsigned char) c);
622  return c;
624  /* force C behavior for ASCII characters, per comments above */
625  if (c <= (pg_wchar) 127)
626  return pg_ascii_toupper((unsigned char) c);
627  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
628  return towupper((wint_t) c);
629  /* FALL THRU */
631  /* force C behavior for ASCII characters, per comments above */
632  if (c <= (pg_wchar) 127)
633  return pg_ascii_toupper((unsigned char) c);
634  if (c <= (pg_wchar) UCHAR_MAX)
635  return toupper((unsigned char) c);
636  return c;
638 #ifdef HAVE_LOCALE_T
639  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
640  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
641 #endif
642  /* FALL THRU */
644 #ifdef HAVE_LOCALE_T
645  if (c <= (pg_wchar) UCHAR_MAX)
646  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
647 #endif
648  return c;
649  case PG_REGEX_LOCALE_ICU:
650 #ifdef USE_ICU
651  return u_toupper(c);
652 #endif
653  break;
654  }
655  return 0; /* can't get here, but keep compiler quiet */
656 }
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
#define towupper_l
Definition: win32_port.h:378
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define toupper_l
Definition: win32_port.h:376

◆ store_match()

static bool store_match ( pg_ctype_cache pcc,
pg_wchar  chr1,
int  nchrs 
)
static

Definition at line 732 of file regc_pg_locale.c.

References assert, cvec::chrs, cvec::chrspace, pg_ctype_cache::cv, cvec::nchrs, cvec::nranges, cvec::ranges, cvec::rangespace, and realloc.

Referenced by pg_ctype_get_cache().

733 {
734  chr *newchrs;
735 
736  if (nchrs > 1)
737  {
738  if (pcc->cv.nranges >= pcc->cv.rangespace)
739  {
740  pcc->cv.rangespace *= 2;
741  newchrs = (chr *) realloc(pcc->cv.ranges,
742  pcc->cv.rangespace * sizeof(chr) * 2);
743  if (newchrs == NULL)
744  return false;
745  pcc->cv.ranges = newchrs;
746  }
747  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
748  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
749  pcc->cv.nranges++;
750  }
751  else
752  {
753  assert(nchrs == 1);
754  if (pcc->cv.nchrs >= pcc->cv.chrspace)
755  {
756  pcc->cv.chrspace *= 2;
757  newchrs = (chr *) realloc(pcc->cv.chrs,
758  pcc->cv.chrspace * sizeof(chr));
759  if (newchrs == NULL)
760  return false;
761  pcc->cv.chrs = newchrs;
762  }
763  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
764  }
765  return true;
766 }
struct cvec cv
int chrspace
Definition: regguts.h:259
pg_wchar chr
Definition: regcustom.h:68
chr * ranges
Definition: regguts.h:263
int nchrs
Definition: regguts.h:258
#define assert(TEST)
Definition: imath.c:37
chr * chrs
Definition: regguts.h:260
int rangespace
Definition: regguts.h:262
#define realloc(a, b)
Definition: header.h:60
int nranges
Definition: regguts.h:261

Variable Documentation

◆ pg_char_properties

const unsigned char pg_char_properties[128]
static

◆ pg_ctype_cache_list

pg_ctype_cache* pg_ctype_cache_list = NULL
static

Definition at line 726 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache().

◆ pg_regex_collation

Oid pg_regex_collation
static

Definition at line 77 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache(), and pg_set_regex_collation().

◆ pg_regex_locale

pg_locale_t pg_regex_locale
static

Definition at line 76 of file regc_pg_locale.c.

◆ pg_regex_strategy