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 721 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 781 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().

782 {
783  pg_ctype_cache *pcc;
784  pg_wchar max_chr;
785  pg_wchar cur_chr;
786  int nmatches;
787  chr *newchrs;
788 
789  /*
790  * Do we already have the answer cached?
791  */
792  for (pcc = pg_ctype_cache_list; pcc != NULL; pcc = pcc->next)
793  {
794  if (pcc->probefunc == probefunc &&
796  return &pcc->cv;
797  }
798 
799  /*
800  * Nope, so initialize some workspace ...
801  */
802  pcc = (pg_ctype_cache *) malloc(sizeof(pg_ctype_cache));
803  if (pcc == NULL)
804  return NULL;
805  pcc->probefunc = probefunc;
807  pcc->cv.nchrs = 0;
808  pcc->cv.chrspace = 128;
809  pcc->cv.chrs = (chr *) malloc(pcc->cv.chrspace * sizeof(chr));
810  pcc->cv.nranges = 0;
811  pcc->cv.rangespace = 64;
812  pcc->cv.ranges = (chr *) malloc(pcc->cv.rangespace * sizeof(chr) * 2);
813  if (pcc->cv.chrs == NULL || pcc->cv.ranges == NULL)
814  goto out_of_memory;
815  pcc->cv.cclasscode = cclasscode;
816 
817  /*
818  * Decide how many character codes we ought to look through. In general
819  * we don't go past MAX_SIMPLE_CHR; chr codes above that are handled at
820  * runtime using the "high colormap" mechanism. However, in C locale
821  * there's no need to go further than 127, and if we only have a 1-byte
822  * <ctype.h> API there's no need to go further than that can handle.
823  *
824  * If it's not MAX_SIMPLE_CHR that's constraining the search, mark the
825  * output cvec as not having any locale-dependent behavior, since there
826  * will be no need to do any run-time locale checks. (The #if's here
827  * would always be true for production values of MAX_SIMPLE_CHR, but it's
828  * useful to allow it to be small for testing purposes.)
829  */
830  switch (pg_regex_strategy)
831  {
832  case PG_REGEX_LOCALE_C:
833 #if MAX_SIMPLE_CHR >= 127
834  max_chr = (pg_wchar) 127;
835  pcc->cv.cclasscode = -1;
836 #else
837  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
838 #endif
839  break;
842  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
843  break;
846 #if MAX_SIMPLE_CHR >= UCHAR_MAX
847  max_chr = (pg_wchar) UCHAR_MAX;
848  pcc->cv.cclasscode = -1;
849 #else
850  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
851 #endif
852  break;
853  case PG_REGEX_LOCALE_ICU:
854  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
855  break;
856  default:
857  max_chr = 0; /* can't get here, but keep compiler quiet */
858  break;
859  }
860 
861  /*
862  * And scan 'em ...
863  */
864  nmatches = 0; /* number of consecutive matches */
865 
866  for (cur_chr = 0; cur_chr <= max_chr; cur_chr++)
867  {
868  if ((*probefunc) (cur_chr))
869  nmatches++;
870  else if (nmatches > 0)
871  {
872  if (!store_match(pcc, cur_chr - nmatches, nmatches))
873  goto out_of_memory;
874  nmatches = 0;
875  }
876  }
877 
878  if (nmatches > 0)
879  if (!store_match(pcc, cur_chr - nmatches, nmatches))
880  goto out_of_memory;
881 
882  /*
883  * We might have allocated more memory than needed, if so free it
884  */
885  if (pcc->cv.nchrs == 0)
886  {
887  free(pcc->cv.chrs);
888  pcc->cv.chrs = NULL;
889  pcc->cv.chrspace = 0;
890  }
891  else if (pcc->cv.nchrs < pcc->cv.chrspace)
892  {
893  newchrs = (chr *) realloc(pcc->cv.chrs,
894  pcc->cv.nchrs * sizeof(chr));
895  if (newchrs == NULL)
896  goto out_of_memory;
897  pcc->cv.chrs = newchrs;
898  pcc->cv.chrspace = pcc->cv.nchrs;
899  }
900  if (pcc->cv.nranges == 0)
901  {
902  free(pcc->cv.ranges);
903  pcc->cv.ranges = NULL;
904  pcc->cv.rangespace = 0;
905  }
906  else if (pcc->cv.nranges < pcc->cv.rangespace)
907  {
908  newchrs = (chr *) realloc(pcc->cv.ranges,
909  pcc->cv.nranges * sizeof(chr) * 2);
910  if (newchrs == NULL)
911  goto out_of_memory;
912  pcc->cv.ranges = newchrs;
913  pcc->cv.rangespace = pcc->cv.nranges;
914  }
915 
916  /*
917  * Success, link it into cache chain
918  */
919  pcc->next = pg_ctype_cache_list;
920  pg_ctype_cache_list = pcc;
921 
922  return &pcc->cv;
923 
924  /*
925  * Failure, clean up
926  */
927 out_of_memory:
928  if (pcc->cv.chrs)
929  free(pcc->cv.chrs);
930  if (pcc->cv.ranges)
931  free(pcc->cv.ranges);
932  free(pcc);
933 
934  return NULL;
935 }
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 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_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;
239  pg_regex_collation = C_COLLATION_OID;
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 
267  ereport(ERROR,
268  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
269  errmsg("nondeterministic collations are not supported for regular expressions")));
270 
271 #ifdef USE_ICU
272  if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
274  else
275 #endif
276  if (GetDatabaseEncoding() == PG_UTF8)
277  {
278  if (pg_regex_locale)
280  else
282  }
283  else
284  {
285  if (pg_regex_locale)
287  else
289  }
290 
291  pg_regex_collation = collation;
292  }
293 }
int errhint(const char *fmt,...)
Definition: elog.c:1069
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:608
#define OidIsValid(objectId)
Definition: c.h:645
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1323
int GetDatabaseEncoding(void)
Definition: mbutils.c:1046
bool deterministic
Definition: pg_locale.h:85
int errmsg(const char *fmt,...)
Definition: elog.c:822
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1226

◆ pg_wc_isalnum()

static int pg_wc_isalnum ( pg_wchar  c)
static

Definition at line 368 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().

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

◆ pg_wc_isalpha()

static int pg_wc_isalpha ( pg_wchar  c)
static

Definition at line 332 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().

333 {
334  switch (pg_regex_strategy)
335  {
336  case PG_REGEX_LOCALE_C:
337  return (c <= (pg_wchar) 127 &&
340  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
341  return iswalpha((wint_t) c);
342  /* FALL THRU */
344  return (c <= (pg_wchar) UCHAR_MAX &&
345  isalpha((unsigned char) c));
347 #ifdef HAVE_LOCALE_T
348  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
349  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
350 #endif
351  /* FALL THRU */
353 #ifdef HAVE_LOCALE_T
354  return (c <= (pg_wchar) UCHAR_MAX &&
355  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
356 #endif
357  break;
358  case PG_REGEX_LOCALE_ICU:
359 #ifdef USE_ICU
360  return u_isalpha(c);
361 #endif
362  break;
363  }
364  return 0; /* can't get here, but keep compiler quiet */
365 }
#define PG_ISALPHA
union pg_locale_struct::@144 info
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define isalpha_l
Definition: win32_port.h:370
#define iswalpha_l
Definition: win32_port.h:371
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 296 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().

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

◆ pg_wc_isgraph()

static int pg_wc_isgraph ( pg_wchar  c)
static

Definition at line 476 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().

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

◆ pg_wc_islower()

static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 440 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().

441 {
442  switch (pg_regex_strategy)
443  {
444  case PG_REGEX_LOCALE_C:
445  return (c <= (pg_wchar) 127 &&
448  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
449  return iswlower((wint_t) c);
450  /* FALL THRU */
452  return (c <= (pg_wchar) UCHAR_MAX &&
453  islower((unsigned char) c));
455 #ifdef HAVE_LOCALE_T
456  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
457  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
458 #endif
459  /* FALL THRU */
461 #ifdef HAVE_LOCALE_T
462  return (c <= (pg_wchar) UCHAR_MAX &&
463  islower_l((unsigned char) c, pg_regex_locale->info.lt));
464 #endif
465  break;
466  case PG_REGEX_LOCALE_ICU:
467 #ifdef USE_ICU
468  return u_islower(c);
469 #endif
470  break;
471  }
472  return 0; /* can't get here, but keep compiler quiet */
473 }
union pg_locale_struct::@144 info
static const unsigned char pg_char_properties[128]
#define islower_l
Definition: win32_port.h:376
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define iswlower_l
Definition: win32_port.h:377
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 512 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().

513 {
514  switch (pg_regex_strategy)
515  {
516  case PG_REGEX_LOCALE_C:
517  return (c <= (pg_wchar) 127 &&
520  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
521  return iswprint((wint_t) c);
522  /* FALL THRU */
524  return (c <= (pg_wchar) UCHAR_MAX &&
525  isprint((unsigned char) c));
527 #ifdef HAVE_LOCALE_T
528  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
529  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
530 #endif
531  /* FALL THRU */
533 #ifdef HAVE_LOCALE_T
534  return (c <= (pg_wchar) UCHAR_MAX &&
535  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
536 #endif
537  break;
538  case PG_REGEX_LOCALE_ICU:
539 #ifdef USE_ICU
540  return u_isprint(c);
541 #endif
542  break;
543  }
544  return 0; /* can't get here, but keep compiler quiet */
545 }
union pg_locale_struct::@144 info
#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
#define isprint_l
Definition: win32_port.h:380
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswprint_l
Definition: win32_port.h:381

◆ pg_wc_ispunct()

static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 548 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().

549 {
550  switch (pg_regex_strategy)
551  {
552  case PG_REGEX_LOCALE_C:
553  return (c <= (pg_wchar) 127 &&
556  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
557  return iswpunct((wint_t) c);
558  /* FALL THRU */
560  return (c <= (pg_wchar) UCHAR_MAX &&
561  ispunct((unsigned char) c));
563 #ifdef HAVE_LOCALE_T
564  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
565  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
566 #endif
567  /* FALL THRU */
569 #ifdef HAVE_LOCALE_T
570  return (c <= (pg_wchar) UCHAR_MAX &&
571  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
572 #endif
573  break;
574  case PG_REGEX_LOCALE_ICU:
575 #ifdef USE_ICU
576  return u_ispunct(c);
577 #endif
578  break;
579  }
580  return 0; /* can't get here, but keep compiler quiet */
581 }
union pg_locale_struct::@144 info
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:382
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswpunct_l
Definition: win32_port.h:383
#define PG_ISPUNCT

◆ pg_wc_isspace()

static int pg_wc_isspace ( pg_wchar  c)
static

Definition at line 584 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().

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

◆ pg_wc_isupper()

static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 404 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().

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

◆ pg_wc_tolower()

static pg_wchar pg_wc_tolower ( pg_wchar  c)
static

Definition at line 664 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().

665 {
666  switch (pg_regex_strategy)
667  {
668  case PG_REGEX_LOCALE_C:
669  if (c <= (pg_wchar) 127)
670  return pg_ascii_tolower((unsigned char) c);
671  return c;
673  /* force C behavior for ASCII characters, per comments above */
674  if (c <= (pg_wchar) 127)
675  return pg_ascii_tolower((unsigned char) c);
676  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
677  return towlower((wint_t) c);
678  /* FALL THRU */
680  /* force C behavior for ASCII characters, per comments above */
681  if (c <= (pg_wchar) 127)
682  return pg_ascii_tolower((unsigned char) c);
683  if (c <= (pg_wchar) UCHAR_MAX)
684  return tolower((unsigned char) c);
685  return c;
687 #ifdef HAVE_LOCALE_T
688  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
689  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
690 #endif
691  /* FALL THRU */
693 #ifdef HAVE_LOCALE_T
694  if (c <= (pg_wchar) UCHAR_MAX)
695  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
696 #endif
697  return c;
698  case PG_REGEX_LOCALE_ICU:
699 #ifdef USE_ICU
700  return u_tolower(c);
701 #endif
702  break;
703  }
704  return 0; /* can't get here, but keep compiler quiet */
705 }
union pg_locale_struct::@144 info
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
#define towlower_l
Definition: win32_port.h:366
#define tolower_l
Definition: win32_port.h:364
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 620 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().

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

◆ store_match()

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

Definition at line 737 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().

738 {
739  chr *newchrs;
740 
741  if (nchrs > 1)
742  {
743  if (pcc->cv.nranges >= pcc->cv.rangespace)
744  {
745  pcc->cv.rangespace *= 2;
746  newchrs = (chr *) realloc(pcc->cv.ranges,
747  pcc->cv.rangespace * sizeof(chr) * 2);
748  if (newchrs == NULL)
749  return false;
750  pcc->cv.ranges = newchrs;
751  }
752  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
753  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
754  pcc->cv.nranges++;
755  }
756  else
757  {
758  assert(nchrs == 1);
759  if (pcc->cv.nchrs >= pcc->cv.chrspace)
760  {
761  pcc->cv.chrspace *= 2;
762  newchrs = (chr *) realloc(pcc->cv.chrs,
763  pcc->cv.chrspace * sizeof(chr));
764  if (newchrs == NULL)
765  return false;
766  pcc->cv.chrs = newchrs;
767  }
768  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
769  }
770  return true;
771 }
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:73
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 731 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