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_isword (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 730 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 790 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 cclasscvec().

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

◆ 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:1156
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:698
#define OidIsValid(objectId)
Definition: c.h:710
#define ERROR
Definition: elog.h:46
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1468
int GetDatabaseEncoding(void)
Definition: mbutils.c:1210
bool deterministic
Definition: pg_locale.h:85
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1371

◆ 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_column_index(), cclasscvec(), and pg_wc_isword().

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 }
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:410
#define PG_ISALNUM
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
union pg_locale_struct::@142 info
#define iswalnum_l
Definition: win32_port.h:411

◆ 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_column_index(), and cclasscvec().

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
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:408
#define iswalpha_l
Definition: win32_port.h:409
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
union pg_locale_struct::@142 info

◆ 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_column_index(), and cclasscvec().

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 }
#define isdigit_l
Definition: win32_port.h:406
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:407
#define PG_ISDIGIT
union pg_locale_struct::@142 info

◆ pg_wc_isgraph()

static int pg_wc_isgraph ( pg_wchar  c)
static

Definition at line 485 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_column_index(), and cclasscvec().

486 {
487  switch (pg_regex_strategy)
488  {
489  case PG_REGEX_LOCALE_C:
490  return (c <= (pg_wchar) 127 &&
493  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
494  return iswgraph((wint_t) c);
495  /* FALL THRU */
497  return (c <= (pg_wchar) UCHAR_MAX &&
498  isgraph((unsigned char) c));
500 #ifdef HAVE_LOCALE_T
501  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
502  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
503 #endif
504  /* FALL THRU */
506 #ifdef HAVE_LOCALE_T
507  return (c <= (pg_wchar) UCHAR_MAX &&
508  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
509 #endif
510  break;
511  case PG_REGEX_LOCALE_ICU:
512 #ifdef USE_ICU
513  return u_isgraph(c);
514 #endif
515  break;
516  }
517  return 0; /* can't get here, but keep compiler quiet */
518 }
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:416
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswgraph_l
Definition: win32_port.h:417
union pg_locale_struct::@142 info

◆ pg_wc_islower()

static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 449 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_column_index(), and cclasscvec().

450 {
451  switch (pg_regex_strategy)
452  {
453  case PG_REGEX_LOCALE_C:
454  return (c <= (pg_wchar) 127 &&
457  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
458  return iswlower((wint_t) c);
459  /* FALL THRU */
461  return (c <= (pg_wchar) UCHAR_MAX &&
462  islower((unsigned char) c));
464 #ifdef HAVE_LOCALE_T
465  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
466  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
467 #endif
468  /* FALL THRU */
470 #ifdef HAVE_LOCALE_T
471  return (c <= (pg_wchar) UCHAR_MAX &&
472  islower_l((unsigned char) c, pg_regex_locale->info.lt));
473 #endif
474  break;
475  case PG_REGEX_LOCALE_ICU:
476 #ifdef USE_ICU
477  return u_islower(c);
478 #endif
479  break;
480  }
481  return 0; /* can't get here, but keep compiler quiet */
482 }
static const unsigned char pg_char_properties[128]
#define islower_l
Definition: win32_port.h:414
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define iswlower_l
Definition: win32_port.h:415
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define PG_ISLOWER
union pg_locale_struct::@142 info

◆ pg_wc_isprint()

static int pg_wc_isprint ( pg_wchar  c)
static

Definition at line 521 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_column_index(), and cclasscvec().

522 {
523  switch (pg_regex_strategy)
524  {
525  case PG_REGEX_LOCALE_C:
526  return (c <= (pg_wchar) 127 &&
529  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
530  return iswprint((wint_t) c);
531  /* FALL THRU */
533  return (c <= (pg_wchar) UCHAR_MAX &&
534  isprint((unsigned char) c));
536 #ifdef HAVE_LOCALE_T
537  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
538  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
539 #endif
540  /* FALL THRU */
542 #ifdef HAVE_LOCALE_T
543  return (c <= (pg_wchar) UCHAR_MAX &&
544  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
545 #endif
546  break;
547  case PG_REGEX_LOCALE_ICU:
548 #ifdef USE_ICU
549  return u_isprint(c);
550 #endif
551  break;
552  }
553  return 0; /* can't get here, but keep compiler quiet */
554 }
#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:418
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswprint_l
Definition: win32_port.h:419
union pg_locale_struct::@142 info

◆ pg_wc_ispunct()

static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 557 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_column_index(), and cclasscvec().

558 {
559  switch (pg_regex_strategy)
560  {
561  case PG_REGEX_LOCALE_C:
562  return (c <= (pg_wchar) 127 &&
565  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
566  return iswpunct((wint_t) c);
567  /* FALL THRU */
569  return (c <= (pg_wchar) UCHAR_MAX &&
570  ispunct((unsigned char) c));
572 #ifdef HAVE_LOCALE_T
573  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
574  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
575 #endif
576  /* FALL THRU */
578 #ifdef HAVE_LOCALE_T
579  return (c <= (pg_wchar) UCHAR_MAX &&
580  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
581 #endif
582  break;
583  case PG_REGEX_LOCALE_ICU:
584 #ifdef USE_ICU
585  return u_ispunct(c);
586 #endif
587  break;
588  }
589  return 0; /* can't get here, but keep compiler quiet */
590 }
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:420
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswpunct_l
Definition: win32_port.h:421
#define PG_ISPUNCT
union pg_locale_struct::@142 info

◆ pg_wc_isspace()

static int pg_wc_isspace ( pg_wchar  c)
static

Definition at line 593 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_column_index(), and cclasscvec().

594 {
595  switch (pg_regex_strategy)
596  {
597  case PG_REGEX_LOCALE_C:
598  return (c <= (pg_wchar) 127 &&
601  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
602  return iswspace((wint_t) c);
603  /* FALL THRU */
605  return (c <= (pg_wchar) UCHAR_MAX &&
606  isspace((unsigned char) c));
608 #ifdef HAVE_LOCALE_T
609  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
610  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
611 #endif
612  /* FALL THRU */
614 #ifdef HAVE_LOCALE_T
615  return (c <= (pg_wchar) UCHAR_MAX &&
616  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
617 #endif
618  break;
619  case PG_REGEX_LOCALE_ICU:
620 #ifdef USE_ICU
621  return u_isspace(c);
622 #endif
623  break;
624  }
625  return 0; /* can't get here, but keep compiler quiet */
626 }
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:423
#define PG_ISSPACE
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define isspace_l
Definition: win32_port.h:422
union pg_locale_struct::@142 info

◆ pg_wc_isupper()

static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 413 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_column_index(), and cclasscvec().

414 {
415  switch (pg_regex_strategy)
416  {
417  case PG_REGEX_LOCALE_C:
418  return (c <= (pg_wchar) 127 &&
421  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
422  return iswupper((wint_t) c);
423  /* FALL THRU */
425  return (c <= (pg_wchar) UCHAR_MAX &&
426  isupper((unsigned char) c));
428 #ifdef HAVE_LOCALE_T
429  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
430  return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
431 #endif
432  /* FALL THRU */
434 #ifdef HAVE_LOCALE_T
435  return (c <= (pg_wchar) UCHAR_MAX &&
436  isupper_l((unsigned char) c, pg_regex_locale->info.lt));
437 #endif
438  break;
439  case PG_REGEX_LOCALE_ICU:
440 #ifdef USE_ICU
441  return u_isupper(c);
442 #endif
443  break;
444  }
445  return 0; /* can't get here, but keep compiler quiet */
446 }
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:412
union pg_locale_struct::@142 info
#define iswupper_l
Definition: win32_port.h:413

◆ pg_wc_isword()

static int pg_wc_isword ( pg_wchar  c)
static

Definition at line 404 of file regc_pg_locale.c.

References CHR, and pg_wc_isalnum().

Referenced by cclass_column_index(), and cclasscvec().

405 {
406  /* We define word characters as alnum class plus underscore */
407  if (c == CHR('_'))
408  return 1;
409  return pg_wc_isalnum(c);
410 }
char * c
static int pg_wc_isalnum(pg_wchar c)
#define CHR(c)
Definition: regcustom.h:69

◆ pg_wc_tolower()

static pg_wchar pg_wc_tolower ( pg_wchar  c)
static

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

674 {
675  switch (pg_regex_strategy)
676  {
677  case PG_REGEX_LOCALE_C:
678  if (c <= (pg_wchar) 127)
679  return pg_ascii_tolower((unsigned char) c);
680  return c;
682  /* force C behavior for ASCII characters, per comments above */
683  if (c <= (pg_wchar) 127)
684  return pg_ascii_tolower((unsigned char) c);
685  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
686  return towlower((wint_t) c);
687  /* FALL THRU */
689  /* force C behavior for ASCII characters, per comments above */
690  if (c <= (pg_wchar) 127)
691  return pg_ascii_tolower((unsigned char) c);
692  if (c <= (pg_wchar) UCHAR_MAX)
693  return tolower((unsigned char) c);
694  return c;
696 #ifdef HAVE_LOCALE_T
697  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
698  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
699 #endif
700  /* FALL THRU */
702 #ifdef HAVE_LOCALE_T
703  if (c <= (pg_wchar) UCHAR_MAX)
704  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
705 #endif
706  return c;
707  case PG_REGEX_LOCALE_ICU:
708 #ifdef USE_ICU
709  return u_tolower(c);
710 #endif
711  break;
712  }
713  return 0; /* can't get here, but keep compiler quiet */
714 }
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:404
#define tolower_l
Definition: win32_port.h:402
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
union pg_locale_struct::@142 info

◆ pg_wc_toupper()

static pg_wchar pg_wc_toupper ( pg_wchar  c)
static

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

630 {
631  switch (pg_regex_strategy)
632  {
633  case PG_REGEX_LOCALE_C:
634  if (c <= (pg_wchar) 127)
635  return pg_ascii_toupper((unsigned char) c);
636  return c;
638  /* force C behavior for ASCII characters, per comments above */
639  if (c <= (pg_wchar) 127)
640  return pg_ascii_toupper((unsigned char) c);
641  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
642  return towupper((wint_t) c);
643  /* FALL THRU */
645  /* force C behavior for ASCII characters, per comments above */
646  if (c <= (pg_wchar) 127)
647  return pg_ascii_toupper((unsigned char) c);
648  if (c <= (pg_wchar) UCHAR_MAX)
649  return toupper((unsigned char) c);
650  return c;
652 #ifdef HAVE_LOCALE_T
653  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
654  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
655 #endif
656  /* FALL THRU */
658 #ifdef HAVE_LOCALE_T
659  if (c <= (pg_wchar) UCHAR_MAX)
660  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
661 #endif
662  return c;
663  case PG_REGEX_LOCALE_ICU:
664 #ifdef USE_ICU
665  return u_toupper(c);
666 #endif
667  break;
668  }
669  return 0; /* can't get here, but keep compiler quiet */
670 }
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:405
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define toupper_l
Definition: win32_port.h:403
union pg_locale_struct::@142 info

◆ store_match()

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

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

747 {
748  chr *newchrs;
749 
750  if (nchrs > 1)
751  {
752  if (pcc->cv.nranges >= pcc->cv.rangespace)
753  {
754  pcc->cv.rangespace *= 2;
755  newchrs = (chr *) realloc(pcc->cv.ranges,
756  pcc->cv.rangespace * sizeof(chr) * 2);
757  if (newchrs == NULL)
758  return false;
759  pcc->cv.ranges = newchrs;
760  }
761  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
762  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
763  pcc->cv.nranges++;
764  }
765  else
766  {
767  assert(nchrs == 1);
768  if (pcc->cv.nchrs >= pcc->cv.chrspace)
769  {
770  pcc->cv.chrspace *= 2;
771  newchrs = (chr *) realloc(pcc->cv.chrs,
772  pcc->cv.chrspace * sizeof(chr));
773  if (newchrs == NULL)
774  return false;
775  pcc->cv.chrs = newchrs;
776  }
777  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
778  }
779  return true;
780 }
struct cvec cv
int chrspace
Definition: regguts.h:276
pg_wchar chr
Definition: regcustom.h:66
chr * ranges
Definition: regguts.h:280
int nchrs
Definition: regguts.h:275
#define assert(TEST)
Definition: imath.c:73
chr * chrs
Definition: regguts.h:277
int rangespace
Definition: regguts.h:279
#define realloc(a, b)
Definition: header.h:60
int nranges
Definition: regguts.h:278

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 740 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