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.

◆ PG_ISALPHA

#define PG_ISALPHA   0x02

Definition at line 83 of file regc_pg_locale.c.

◆ PG_ISDIGIT

#define PG_ISDIGIT   0x01

Definition at line 82 of file regc_pg_locale.c.

◆ PG_ISGRAPH

#define PG_ISGRAPH   0x10

Definition at line 87 of file regc_pg_locale.c.

◆ PG_ISLOWER

#define PG_ISLOWER   0x08

Definition at line 86 of file regc_pg_locale.c.

◆ PG_ISPRINT

#define PG_ISPRINT   0x20

Definition at line 88 of file regc_pg_locale.c.

◆ PG_ISPUNCT

#define PG_ISPUNCT   0x40

Definition at line 89 of file regc_pg_locale.c.

◆ PG_ISSPACE

#define PG_ISSPACE   0x80

Definition at line 90 of file regc_pg_locale.c.

◆ PG_ISUPPER

#define PG_ISUPPER   0x04

Definition at line 85 of file regc_pg_locale.c.

Typedef Documentation

◆ pg_ctype_cache

◆ pg_wc_probefunc

typedef int(* pg_wc_probefunc) (pg_wchar c)

Definition at line 726 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
@ PG_REGEX_LOCALE_1BYTE
@ PG_REGEX_LOCALE_WIDE
@ PG_REGEX_LOCALE_1BYTE_L
@ PG_REGEX_LOCALE_ICU
@ PG_REGEX_LOCALE_WIDE_L
@ PG_REGEX_LOCALE_C

Function Documentation

◆ pg_ctype_get_cache()

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

Definition at line 786 of file regc_pg_locale.c.

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

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

◆ pg_set_regex_collation()

void pg_set_regex_collation ( Oid  collation)

Definition at line 232 of file regc_pg_locale.c.

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

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

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

◆ pg_wc_isalnum()

static int pg_wc_isalnum ( pg_wchar  c)
static

Definition at line 364 of file regc_pg_locale.c.

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

References pg_locale_struct::info, isalnum_l, iswalnum_l, pg_char_properties, PG_ISALNUM, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), cclasscvec(), and pg_wc_isword().

◆ pg_wc_isalpha()

static int pg_wc_isalpha ( pg_wchar  c)
static

Definition at line 328 of file regc_pg_locale.c.

329 {
330  switch (pg_regex_strategy)
331  {
332  case PG_REGEX_LOCALE_C:
333  return (c <= (pg_wchar) 127 &&
336  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
337  return iswalpha((wint_t) c);
338  /* FALL THRU */
340  return (c <= (pg_wchar) UCHAR_MAX &&
341  isalpha((unsigned char) c));
343 #ifdef HAVE_LOCALE_T
344  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
345  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
346 #endif
347  /* FALL THRU */
349 #ifdef HAVE_LOCALE_T
350  return (c <= (pg_wchar) UCHAR_MAX &&
351  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
352 #endif
353  break;
354  case PG_REGEX_LOCALE_ICU:
355 #ifdef USE_ICU
356  return u_isalpha(c);
357 #endif
358  break;
359  }
360  return 0; /* can't get here, but keep compiler quiet */
361 }
#define PG_ISALPHA
#define isalpha_l
Definition: win32_port.h:408
#define iswalpha_l
Definition: win32_port.h:409

References pg_locale_struct::info, isalpha_l, iswalpha_l, pg_char_properties, PG_ISALPHA, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isdigit()

static int pg_wc_isdigit ( pg_wchar  c)
static

Definition at line 292 of file regc_pg_locale.c.

293 {
294  switch (pg_regex_strategy)
295  {
296  case PG_REGEX_LOCALE_C:
297  return (c <= (pg_wchar) 127 &&
300  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
301  return iswdigit((wint_t) c);
302  /* FALL THRU */
304  return (c <= (pg_wchar) UCHAR_MAX &&
305  isdigit((unsigned char) c));
307 #ifdef HAVE_LOCALE_T
308  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
309  return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
310 #endif
311  /* FALL THRU */
313 #ifdef HAVE_LOCALE_T
314  return (c <= (pg_wchar) UCHAR_MAX &&
315  isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
316 #endif
317  break;
318  case PG_REGEX_LOCALE_ICU:
319 #ifdef USE_ICU
320  return u_isdigit(c);
321 #endif
322  break;
323  }
324  return 0; /* can't get here, but keep compiler quiet */
325 }
#define PG_ISDIGIT
#define isdigit_l
Definition: win32_port.h:406
#define iswdigit_l
Definition: win32_port.h:407

References pg_locale_struct::info, isdigit_l, iswdigit_l, pg_char_properties, PG_ISDIGIT, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isgraph()

static int pg_wc_isgraph ( pg_wchar  c)
static

Definition at line 481 of file regc_pg_locale.c.

482 {
483  switch (pg_regex_strategy)
484  {
485  case PG_REGEX_LOCALE_C:
486  return (c <= (pg_wchar) 127 &&
489  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
490  return iswgraph((wint_t) c);
491  /* FALL THRU */
493  return (c <= (pg_wchar) UCHAR_MAX &&
494  isgraph((unsigned char) c));
496 #ifdef HAVE_LOCALE_T
497  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
498  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
499 #endif
500  /* FALL THRU */
502 #ifdef HAVE_LOCALE_T
503  return (c <= (pg_wchar) UCHAR_MAX &&
504  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
505 #endif
506  break;
507  case PG_REGEX_LOCALE_ICU:
508 #ifdef USE_ICU
509  return u_isgraph(c);
510 #endif
511  break;
512  }
513  return 0; /* can't get here, but keep compiler quiet */
514 }
#define PG_ISGRAPH
#define isgraph_l
Definition: win32_port.h:416
#define iswgraph_l
Definition: win32_port.h:417

References pg_locale_struct::info, isgraph_l, iswgraph_l, pg_char_properties, PG_ISGRAPH, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_islower()

static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 445 of file regc_pg_locale.c.

446 {
447  switch (pg_regex_strategy)
448  {
449  case PG_REGEX_LOCALE_C:
450  return (c <= (pg_wchar) 127 &&
453  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
454  return iswlower((wint_t) c);
455  /* FALL THRU */
457  return (c <= (pg_wchar) UCHAR_MAX &&
458  islower((unsigned char) c));
460 #ifdef HAVE_LOCALE_T
461  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
462  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
463 #endif
464  /* FALL THRU */
466 #ifdef HAVE_LOCALE_T
467  return (c <= (pg_wchar) UCHAR_MAX &&
468  islower_l((unsigned char) c, pg_regex_locale->info.lt));
469 #endif
470  break;
471  case PG_REGEX_LOCALE_ICU:
472 #ifdef USE_ICU
473  return u_islower(c);
474 #endif
475  break;
476  }
477  return 0; /* can't get here, but keep compiler quiet */
478 }
#define PG_ISLOWER
#define islower_l
Definition: win32_port.h:414
#define iswlower_l
Definition: win32_port.h:415

References pg_locale_struct::info, islower_l, iswlower_l, pg_char_properties, PG_ISLOWER, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isprint()

static int pg_wc_isprint ( pg_wchar  c)
static

Definition at line 517 of file regc_pg_locale.c.

518 {
519  switch (pg_regex_strategy)
520  {
521  case PG_REGEX_LOCALE_C:
522  return (c <= (pg_wchar) 127 &&
525  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
526  return iswprint((wint_t) c);
527  /* FALL THRU */
529  return (c <= (pg_wchar) UCHAR_MAX &&
530  isprint((unsigned char) c));
532 #ifdef HAVE_LOCALE_T
533  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
534  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
535 #endif
536  /* FALL THRU */
538 #ifdef HAVE_LOCALE_T
539  return (c <= (pg_wchar) UCHAR_MAX &&
540  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
541 #endif
542  break;
543  case PG_REGEX_LOCALE_ICU:
544 #ifdef USE_ICU
545  return u_isprint(c);
546 #endif
547  break;
548  }
549  return 0; /* can't get here, but keep compiler quiet */
550 }
#define PG_ISPRINT
#define isprint_l
Definition: win32_port.h:418
#define iswprint_l
Definition: win32_port.h:419

References pg_locale_struct::info, isprint_l, iswprint_l, pg_char_properties, PG_ISPRINT, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_ispunct()

static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 553 of file regc_pg_locale.c.

554 {
555  switch (pg_regex_strategy)
556  {
557  case PG_REGEX_LOCALE_C:
558  return (c <= (pg_wchar) 127 &&
561  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
562  return iswpunct((wint_t) c);
563  /* FALL THRU */
565  return (c <= (pg_wchar) UCHAR_MAX &&
566  ispunct((unsigned char) c));
568 #ifdef HAVE_LOCALE_T
569  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
570  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
571 #endif
572  /* FALL THRU */
574 #ifdef HAVE_LOCALE_T
575  return (c <= (pg_wchar) UCHAR_MAX &&
576  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
577 #endif
578  break;
579  case PG_REGEX_LOCALE_ICU:
580 #ifdef USE_ICU
581  return u_ispunct(c);
582 #endif
583  break;
584  }
585  return 0; /* can't get here, but keep compiler quiet */
586 }
#define PG_ISPUNCT
#define ispunct_l
Definition: win32_port.h:420
#define iswpunct_l
Definition: win32_port.h:421

References pg_locale_struct::info, ispunct_l, iswpunct_l, pg_char_properties, PG_ISPUNCT, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isspace()

static int pg_wc_isspace ( pg_wchar  c)
static

Definition at line 589 of file regc_pg_locale.c.

590 {
591  switch (pg_regex_strategy)
592  {
593  case PG_REGEX_LOCALE_C:
594  return (c <= (pg_wchar) 127 &&
597  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
598  return iswspace((wint_t) c);
599  /* FALL THRU */
601  return (c <= (pg_wchar) UCHAR_MAX &&
602  isspace((unsigned char) c));
604 #ifdef HAVE_LOCALE_T
605  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
606  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
607 #endif
608  /* FALL THRU */
610 #ifdef HAVE_LOCALE_T
611  return (c <= (pg_wchar) UCHAR_MAX &&
612  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
613 #endif
614  break;
615  case PG_REGEX_LOCALE_ICU:
616 #ifdef USE_ICU
617  return u_isspace(c);
618 #endif
619  break;
620  }
621  return 0; /* can't get here, but keep compiler quiet */
622 }
#define PG_ISSPACE
#define iswspace_l
Definition: win32_port.h:423
#define isspace_l
Definition: win32_port.h:422

References pg_locale_struct::info, isspace_l, iswspace_l, pg_char_properties, PG_ISSPACE, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isupper()

static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 409 of file regc_pg_locale.c.

410 {
411  switch (pg_regex_strategy)
412  {
413  case PG_REGEX_LOCALE_C:
414  return (c <= (pg_wchar) 127 &&
417  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
418  return iswupper((wint_t) c);
419  /* FALL THRU */
421  return (c <= (pg_wchar) UCHAR_MAX &&
422  isupper((unsigned char) c));
424 #ifdef HAVE_LOCALE_T
425  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
426  return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
427 #endif
428  /* FALL THRU */
430 #ifdef HAVE_LOCALE_T
431  return (c <= (pg_wchar) UCHAR_MAX &&
432  isupper_l((unsigned char) c, pg_regex_locale->info.lt));
433 #endif
434  break;
435  case PG_REGEX_LOCALE_ICU:
436 #ifdef USE_ICU
437  return u_isupper(c);
438 #endif
439  break;
440  }
441  return 0; /* can't get here, but keep compiler quiet */
442 }
#define PG_ISUPPER
#define iswupper_l
Definition: win32_port.h:413
#define isupper_l
Definition: win32_port.h:412

References pg_locale_struct::info, isupper_l, iswupper_l, pg_char_properties, PG_ISUPPER, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isword()

static int pg_wc_isword ( pg_wchar  c)
static

Definition at line 400 of file regc_pg_locale.c.

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

References CHR, and pg_wc_isalnum().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_tolower()

static pg_wchar pg_wc_tolower ( pg_wchar  c)
static

Definition at line 669 of file regc_pg_locale.c.

670 {
671  switch (pg_regex_strategy)
672  {
673  case PG_REGEX_LOCALE_C:
674  if (c <= (pg_wchar) 127)
675  return pg_ascii_tolower((unsigned char) c);
676  return c;
678  /* force C behavior for ASCII characters, per comments above */
679  if (c <= (pg_wchar) 127)
680  return pg_ascii_tolower((unsigned char) c);
681  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
682  return towlower((wint_t) c);
683  /* FALL THRU */
685  /* force C behavior for ASCII characters, per comments above */
686  if (c <= (pg_wchar) 127)
687  return pg_ascii_tolower((unsigned char) c);
688  if (c <= (pg_wchar) UCHAR_MAX)
689  return tolower((unsigned char) c);
690  return c;
692 #ifdef HAVE_LOCALE_T
693  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
694  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
695 #endif
696  /* FALL THRU */
698 #ifdef HAVE_LOCALE_T
699  if (c <= (pg_wchar) UCHAR_MAX)
700  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
701 #endif
702  return c;
703  case PG_REGEX_LOCALE_ICU:
704 #ifdef USE_ICU
705  return u_tolower(c);
706 #endif
707  break;
708  }
709  return 0; /* can't get here, but keep compiler quiet */
710 }
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

References pg_locale_struct::info, pg_ascii_tolower(), pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, pg_regex_strategy, tolower_l, and towlower_l.

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

◆ pg_wc_toupper()

static pg_wchar pg_wc_toupper ( pg_wchar  c)
static

Definition at line 625 of file regc_pg_locale.c.

626 {
627  switch (pg_regex_strategy)
628  {
629  case PG_REGEX_LOCALE_C:
630  if (c <= (pg_wchar) 127)
631  return pg_ascii_toupper((unsigned char) c);
632  return c;
634  /* force C behavior for ASCII characters, per comments above */
635  if (c <= (pg_wchar) 127)
636  return pg_ascii_toupper((unsigned char) c);
637  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
638  return towupper((wint_t) c);
639  /* FALL THRU */
641  /* force C behavior for ASCII characters, per comments above */
642  if (c <= (pg_wchar) 127)
643  return pg_ascii_toupper((unsigned char) c);
644  if (c <= (pg_wchar) UCHAR_MAX)
645  return toupper((unsigned char) c);
646  return c;
648 #ifdef HAVE_LOCALE_T
649  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
650  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
651 #endif
652  /* FALL THRU */
654 #ifdef HAVE_LOCALE_T
655  if (c <= (pg_wchar) UCHAR_MAX)
656  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
657 #endif
658  return c;
659  case PG_REGEX_LOCALE_ICU:
660 #ifdef USE_ICU
661  return u_toupper(c);
662 #endif
663  break;
664  }
665  return 0; /* can't get here, but keep compiler quiet */
666 }
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
#define toupper_l
Definition: win32_port.h:403
#define towupper_l
Definition: win32_port.h:405

References pg_locale_struct::info, pg_ascii_toupper(), pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, pg_regex_strategy, toupper_l, and towupper_l.

Referenced by allcases(), and range().

◆ store_match()

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

Definition at line 742 of file regc_pg_locale.c.

743 {
744  chr *newchrs;
745 
746  if (nchrs > 1)
747  {
748  if (pcc->cv.nranges >= pcc->cv.rangespace)
749  {
750  pcc->cv.rangespace *= 2;
751  newchrs = (chr *) realloc(pcc->cv.ranges,
752  pcc->cv.rangespace * sizeof(chr) * 2);
753  if (newchrs == NULL)
754  return false;
755  pcc->cv.ranges = newchrs;
756  }
757  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
758  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
759  pcc->cv.nranges++;
760  }
761  else
762  {
763  assert(nchrs == 1);
764  if (pcc->cv.nchrs >= pcc->cv.chrspace)
765  {
766  pcc->cv.chrspace *= 2;
767  newchrs = (chr *) realloc(pcc->cv.chrs,
768  pcc->cv.chrspace * sizeof(chr));
769  if (newchrs == NULL)
770  return false;
771  pcc->cv.chrs = newchrs;
772  }
773  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
774  }
775  return true;
776 }
#define assert(x)
Definition: regcustom.h:63

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

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 736 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_regex_strategy