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_BUILTIN , 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 86 of file regc_pg_locale.c.

◆ PG_ISALPHA

#define PG_ISALPHA   0x02

Definition at line 85 of file regc_pg_locale.c.

◆ PG_ISDIGIT

#define PG_ISDIGIT   0x01

Definition at line 84 of file regc_pg_locale.c.

◆ PG_ISGRAPH

#define PG_ISGRAPH   0x10

Definition at line 89 of file regc_pg_locale.c.

◆ PG_ISLOWER

#define PG_ISLOWER   0x08

Definition at line 88 of file regc_pg_locale.c.

◆ PG_ISPRINT

#define PG_ISPRINT   0x20

Definition at line 90 of file regc_pg_locale.c.

◆ PG_ISPUNCT

#define PG_ISPUNCT   0x40

Definition at line 91 of file regc_pg_locale.c.

◆ PG_ISSPACE

#define PG_ISSPACE   0x80

Definition at line 92 of file regc_pg_locale.c.

◆ PG_ISUPPER

#define PG_ISUPPER   0x04

Definition at line 87 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 706 of file regc_pg_locale.c.

Enumeration Type Documentation

◆ PG_Locale_Strategy

Enumerator
PG_REGEX_LOCALE_C 
PG_REGEX_BUILTIN 
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 66 of file regc_pg_locale.c.

67 {
68  PG_REGEX_LOCALE_C, /* C locale (encoding independent) */
69  PG_REGEX_BUILTIN, /* built-in Unicode semantics */
70  PG_REGEX_LOCALE_WIDE, /* Use <wctype.h> functions */
71  PG_REGEX_LOCALE_1BYTE, /* Use <ctype.h> functions */
72  PG_REGEX_LOCALE_WIDE_L, /* Use locale_t <wctype.h> functions */
73  PG_REGEX_LOCALE_1BYTE_L, /* Use locale_t <ctype.h> functions */
74  PG_REGEX_LOCALE_ICU, /* Use ICU uchar.h functions */
PG_Locale_Strategy
@ PG_REGEX_LOCALE_1BYTE
@ PG_REGEX_LOCALE_WIDE
@ PG_REGEX_BUILTIN
@ 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 766 of file regc_pg_locale.c.

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

References Assert, 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_BUILTIN, 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 234 of file regc_pg_locale.c.

235 {
236  if (!OidIsValid(collation))
237  {
238  /*
239  * This typically means that the parser could not resolve a conflict
240  * of implicit collations, so report it that way.
241  */
242  ereport(ERROR,
243  (errcode(ERRCODE_INDETERMINATE_COLLATION),
244  errmsg("could not determine which collation to use for regular expression"),
245  errhint("Use the COLLATE clause to set the collation explicitly.")));
246  }
247 
248  if (lc_ctype_is_c(collation))
249  {
250  /* C/POSIX collations use this path regardless of database encoding */
252  pg_regex_locale = 0;
253  pg_regex_collation = C_COLLATION_OID;
254  }
255  else
256  {
258 
260  ereport(ERROR,
261  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
262  errmsg("nondeterministic collations are not supported for regular expressions")));
263 
264 #ifdef USE_ICU
265  if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
267  else
268 #endif
269  if (GetDatabaseEncoding() == PG_UTF8)
270  {
271  if (pg_regex_locale)
272  {
273  if (pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
275  else
277  }
278  else
280  }
281  else
282  {
283  if (pg_regex_locale)
285  else
287  }
288 
289  pg_regex_collation = collation;
290  }
291 }
#define OidIsValid(objectId)
Definition: c.h:775
int errhint(const char *fmt,...)
Definition: elog.c:1319
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int GetDatabaseEncoding(void)
Definition: mbutils.c:1261
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1551
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1384
bool pg_locale_deterministic(pg_locale_t locale)
Definition: pg_locale.c:1531
@ PG_UTF8
Definition: pg_wchar.h:232
static pg_locale_t pg_regex_locale

References ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), lc_ctype_is_c(), OidIsValid, pg_locale_deterministic(), pg_newlocale_from_collation(), PG_REGEX_BUILTIN, 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 362 of file regc_pg_locale.c.

363 {
364  switch (pg_regex_strategy)
365  {
366  case PG_REGEX_LOCALE_C:
367  return (c <= (pg_wchar) 127 &&
369  case PG_REGEX_BUILTIN:
370  return pg_u_isalnum(c, true);
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  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
380  return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
381  /* FALL THRU */
383  return (c <= (pg_wchar) UCHAR_MAX &&
384  isalnum_l((unsigned char) c, pg_regex_locale->info.lt));
385  break;
386  case PG_REGEX_LOCALE_ICU:
387 #ifdef USE_ICU
388  return u_isalnum(c);
389 #endif
390  break;
391  }
392  return 0; /* can't get here, but keep compiler quiet */
393 }
char * c
#define PG_ISALNUM
static const unsigned char pg_char_properties[128]
locale_t lt
Definition: pg_locale.h:83
union pg_locale_struct::@151 info
bool pg_u_isalnum(pg_wchar code, bool posix)
#define iswalnum_l
Definition: win32_port.h:434
#define isalnum_l
Definition: win32_port.h:433

References pg_locale_struct::info, isalnum_l, iswalnum_l, pg_locale_struct::lt, pg_char_properties, PG_ISALNUM, PG_REGEX_BUILTIN, 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, and pg_u_isalnum().

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 &&
335  case PG_REGEX_BUILTIN:
336  return pg_u_isalpha(c);
338  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
339  return iswalpha((wint_t) c);
340  /* FALL THRU */
342  return (c <= (pg_wchar) UCHAR_MAX &&
343  isalpha((unsigned char) c));
345  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
346  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
347  /* FALL THRU */
349  return (c <= (pg_wchar) UCHAR_MAX &&
350  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
351  break;
352  case PG_REGEX_LOCALE_ICU:
353 #ifdef USE_ICU
354  return u_isalpha(c);
355 #endif
356  break;
357  }
358  return 0; /* can't get here, but keep compiler quiet */
359 }
#define PG_ISALPHA
bool pg_u_isalpha(pg_wchar code)
#define isalpha_l
Definition: win32_port.h:431
#define iswalpha_l
Definition: win32_port.h:432

References pg_locale_struct::info, isalpha_l, iswalpha_l, pg_locale_struct::lt, pg_char_properties, PG_ISALPHA, PG_REGEX_BUILTIN, 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, and pg_u_isalpha().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isdigit()

static int pg_wc_isdigit ( pg_wchar  c)
static

Definition at line 294 of file regc_pg_locale.c.

295 {
296  switch (pg_regex_strategy)
297  {
298  case PG_REGEX_LOCALE_C:
299  return (c <= (pg_wchar) 127 &&
301  case PG_REGEX_BUILTIN:
302  return pg_u_isdigit(c, true);
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  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
312  return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
313  /* FALL THRU */
315  return (c <= (pg_wchar) UCHAR_MAX &&
316  isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
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
bool pg_u_isdigit(pg_wchar code, bool posix)
#define isdigit_l
Definition: win32_port.h:429
#define iswdigit_l
Definition: win32_port.h:430

References pg_locale_struct::info, isdigit_l, iswdigit_l, pg_locale_struct::lt, pg_char_properties, PG_ISDIGIT, PG_REGEX_BUILTIN, 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, and pg_u_isdigit().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isgraph()

static int pg_wc_isgraph ( pg_wchar  c)
static

Definition at line 473 of file regc_pg_locale.c.

474 {
475  switch (pg_regex_strategy)
476  {
477  case PG_REGEX_LOCALE_C:
478  return (c <= (pg_wchar) 127 &&
480  case PG_REGEX_BUILTIN:
481  return pg_u_isgraph(c);
483  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
484  return iswgraph((wint_t) c);
485  /* FALL THRU */
487  return (c <= (pg_wchar) UCHAR_MAX &&
488  isgraph((unsigned char) c));
490  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
491  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
492  /* FALL THRU */
494  return (c <= (pg_wchar) UCHAR_MAX &&
495  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
496  break;
497  case PG_REGEX_LOCALE_ICU:
498 #ifdef USE_ICU
499  return u_isgraph(c);
500 #endif
501  break;
502  }
503  return 0; /* can't get here, but keep compiler quiet */
504 }
#define PG_ISGRAPH
bool pg_u_isgraph(pg_wchar code)
#define isgraph_l
Definition: win32_port.h:439
#define iswgraph_l
Definition: win32_port.h:440

References pg_locale_struct::info, isgraph_l, iswgraph_l, pg_locale_struct::lt, pg_char_properties, PG_ISGRAPH, PG_REGEX_BUILTIN, 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, and pg_u_isgraph().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_islower()

static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 439 of file regc_pg_locale.c.

440 {
441  switch (pg_regex_strategy)
442  {
443  case PG_REGEX_LOCALE_C:
444  return (c <= (pg_wchar) 127 &&
446  case PG_REGEX_BUILTIN:
447  return pg_u_islower(c);
449  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
450  return iswlower((wint_t) c);
451  /* FALL THRU */
453  return (c <= (pg_wchar) UCHAR_MAX &&
454  islower((unsigned char) c));
456  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
457  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
458  /* FALL THRU */
460  return (c <= (pg_wchar) UCHAR_MAX &&
461  islower_l((unsigned char) c, pg_regex_locale->info.lt));
462  break;
463  case PG_REGEX_LOCALE_ICU:
464 #ifdef USE_ICU
465  return u_islower(c);
466 #endif
467  break;
468  }
469  return 0; /* can't get here, but keep compiler quiet */
470 }
#define PG_ISLOWER
bool pg_u_islower(pg_wchar code)
#define islower_l
Definition: win32_port.h:437
#define iswlower_l
Definition: win32_port.h:438

References pg_locale_struct::info, islower_l, iswlower_l, pg_locale_struct::lt, pg_char_properties, PG_ISLOWER, PG_REGEX_BUILTIN, 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, and pg_u_islower().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isprint()

static int pg_wc_isprint ( pg_wchar  c)
static

Definition at line 507 of file regc_pg_locale.c.

508 {
509  switch (pg_regex_strategy)
510  {
511  case PG_REGEX_LOCALE_C:
512  return (c <= (pg_wchar) 127 &&
514  case PG_REGEX_BUILTIN:
515  return pg_u_isprint(c);
517  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
518  return iswprint((wint_t) c);
519  /* FALL THRU */
521  return (c <= (pg_wchar) UCHAR_MAX &&
522  isprint((unsigned char) c));
524  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
525  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
526  /* FALL THRU */
528  return (c <= (pg_wchar) UCHAR_MAX &&
529  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
530  break;
531  case PG_REGEX_LOCALE_ICU:
532 #ifdef USE_ICU
533  return u_isprint(c);
534 #endif
535  break;
536  }
537  return 0; /* can't get here, but keep compiler quiet */
538 }
#define PG_ISPRINT
bool pg_u_isprint(pg_wchar code)
#define isprint_l
Definition: win32_port.h:441
#define iswprint_l
Definition: win32_port.h:442

References pg_locale_struct::info, isprint_l, iswprint_l, pg_locale_struct::lt, pg_char_properties, PG_ISPRINT, PG_REGEX_BUILTIN, 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, and pg_u_isprint().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_ispunct()

static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 541 of file regc_pg_locale.c.

542 {
543  switch (pg_regex_strategy)
544  {
545  case PG_REGEX_LOCALE_C:
546  return (c <= (pg_wchar) 127 &&
548  case PG_REGEX_BUILTIN:
549  return pg_u_ispunct(c, true);
551  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
552  return iswpunct((wint_t) c);
553  /* FALL THRU */
555  return (c <= (pg_wchar) UCHAR_MAX &&
556  ispunct((unsigned char) c));
558  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
559  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
560  /* FALL THRU */
562  return (c <= (pg_wchar) UCHAR_MAX &&
563  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
564  break;
565  case PG_REGEX_LOCALE_ICU:
566 #ifdef USE_ICU
567  return u_ispunct(c);
568 #endif
569  break;
570  }
571  return 0; /* can't get here, but keep compiler quiet */
572 }
#define PG_ISPUNCT
bool pg_u_ispunct(pg_wchar code, bool posix)
#define ispunct_l
Definition: win32_port.h:443
#define iswpunct_l
Definition: win32_port.h:444

References pg_locale_struct::info, ispunct_l, iswpunct_l, pg_locale_struct::lt, pg_char_properties, PG_ISPUNCT, PG_REGEX_BUILTIN, 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, and pg_u_ispunct().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isspace()

static int pg_wc_isspace ( pg_wchar  c)
static

Definition at line 575 of file regc_pg_locale.c.

576 {
577  switch (pg_regex_strategy)
578  {
579  case PG_REGEX_LOCALE_C:
580  return (c <= (pg_wchar) 127 &&
582  case PG_REGEX_BUILTIN:
583  return pg_u_isspace(c);
585  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
586  return iswspace((wint_t) c);
587  /* FALL THRU */
589  return (c <= (pg_wchar) UCHAR_MAX &&
590  isspace((unsigned char) c));
592  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
593  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
594  /* FALL THRU */
596  return (c <= (pg_wchar) UCHAR_MAX &&
597  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
598  break;
599  case PG_REGEX_LOCALE_ICU:
600 #ifdef USE_ICU
601  return u_isspace(c);
602 #endif
603  break;
604  }
605  return 0; /* can't get here, but keep compiler quiet */
606 }
#define PG_ISSPACE
bool pg_u_isspace(pg_wchar code)
#define iswspace_l
Definition: win32_port.h:446
#define isspace_l
Definition: win32_port.h:445

References pg_locale_struct::info, isspace_l, iswspace_l, pg_locale_struct::lt, pg_char_properties, PG_ISSPACE, PG_REGEX_BUILTIN, 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, and pg_u_isspace().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isupper()

static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 405 of file regc_pg_locale.c.

406 {
407  switch (pg_regex_strategy)
408  {
409  case PG_REGEX_LOCALE_C:
410  return (c <= (pg_wchar) 127 &&
412  case PG_REGEX_BUILTIN:
413  return pg_u_isupper(c);
415  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
416  return iswupper((wint_t) c);
417  /* FALL THRU */
419  return (c <= (pg_wchar) UCHAR_MAX &&
420  isupper((unsigned char) c));
422  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
423  return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
424  /* FALL THRU */
426  return (c <= (pg_wchar) UCHAR_MAX &&
427  isupper_l((unsigned char) c, pg_regex_locale->info.lt));
428  break;
429  case PG_REGEX_LOCALE_ICU:
430 #ifdef USE_ICU
431  return u_isupper(c);
432 #endif
433  break;
434  }
435  return 0; /* can't get here, but keep compiler quiet */
436 }
#define PG_ISUPPER
bool pg_u_isupper(pg_wchar code)
#define iswupper_l
Definition: win32_port.h:436
#define isupper_l
Definition: win32_port.h:435

References pg_locale_struct::info, isupper_l, iswupper_l, pg_locale_struct::lt, pg_char_properties, PG_ISUPPER, PG_REGEX_BUILTIN, 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, and pg_u_isupper().

Referenced by cclass_column_index(), and cclasscvec().

◆ pg_wc_isword()

static int pg_wc_isword ( pg_wchar  c)
static

Definition at line 396 of file regc_pg_locale.c.

397 {
398  /* We define word characters as alnum class plus underscore */
399  if (c == CHR('_'))
400  return 1;
401  return pg_wc_isalnum(c);
402 }
static int pg_wc_isalnum(pg_wchar c)
#define CHR(c)
Definition: regcustom.h:62

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

652 {
653  switch (pg_regex_strategy)
654  {
655  case PG_REGEX_LOCALE_C:
656  if (c <= (pg_wchar) 127)
657  return pg_ascii_tolower((unsigned char) c);
658  return c;
659  case PG_REGEX_BUILTIN:
660  return unicode_lowercase_simple(c);
662  /* force C behavior for ASCII characters, per comments above */
663  if (c <= (pg_wchar) 127)
664  return pg_ascii_tolower((unsigned char) c);
665  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
666  return towlower((wint_t) c);
667  /* FALL THRU */
669  /* force C behavior for ASCII characters, per comments above */
670  if (c <= (pg_wchar) 127)
671  return pg_ascii_tolower((unsigned char) c);
672  if (c <= (pg_wchar) UCHAR_MAX)
673  return tolower((unsigned char) c);
674  return c;
676  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
677  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
678  /* FALL THRU */
680  if (c <= (pg_wchar) UCHAR_MAX)
681  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
682  return c;
683  case PG_REGEX_LOCALE_ICU:
684 #ifdef USE_ICU
685  return u_tolower(c);
686 #endif
687  break;
688  }
689  return 0; /* can't get here, but keep compiler quiet */
690 }
unsigned char pg_ascii_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:146
pg_wchar unicode_lowercase_simple(pg_wchar code)
Definition: unicode_case.c:29
#define towlower_l
Definition: win32_port.h:427
#define tolower_l
Definition: win32_port.h:425

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

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

◆ pg_wc_toupper()

static pg_wchar pg_wc_toupper ( pg_wchar  c)
static

Definition at line 609 of file regc_pg_locale.c.

610 {
611  switch (pg_regex_strategy)
612  {
613  case PG_REGEX_LOCALE_C:
614  if (c <= (pg_wchar) 127)
615  return pg_ascii_toupper((unsigned char) c);
616  return c;
617  case PG_REGEX_BUILTIN:
618  return unicode_uppercase_simple(c);
620  /* force C behavior for ASCII characters, per comments above */
621  if (c <= (pg_wchar) 127)
622  return pg_ascii_toupper((unsigned char) c);
623  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
624  return towupper((wint_t) c);
625  /* FALL THRU */
627  /* force C behavior for ASCII characters, per comments above */
628  if (c <= (pg_wchar) 127)
629  return pg_ascii_toupper((unsigned char) c);
630  if (c <= (pg_wchar) UCHAR_MAX)
631  return toupper((unsigned char) c);
632  return c;
634  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
635  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
636  /* FALL THRU */
638  if (c <= (pg_wchar) UCHAR_MAX)
639  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
640  return c;
641  case PG_REGEX_LOCALE_ICU:
642 #ifdef USE_ICU
643  return u_toupper(c);
644 #endif
645  break;
646  }
647  return 0; /* can't get here, but keep compiler quiet */
648 }
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
pg_wchar unicode_uppercase_simple(pg_wchar code)
Definition: unicode_case.c:45
#define toupper_l
Definition: win32_port.h:426
#define towupper_l
Definition: win32_port.h:428

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

Referenced by allcases(), and range().

◆ store_match()

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

Definition at line 722 of file regc_pg_locale.c.

723 {
724  chr *newchrs;
725 
726  if (nchrs > 1)
727  {
728  if (pcc->cv.nranges >= pcc->cv.rangespace)
729  {
730  pcc->cv.rangespace *= 2;
731  newchrs = (chr *) realloc(pcc->cv.ranges,
732  pcc->cv.rangespace * sizeof(chr) * 2);
733  if (newchrs == NULL)
734  return false;
735  pcc->cv.ranges = newchrs;
736  }
737  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
738  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
739  pcc->cv.nranges++;
740  }
741  else
742  {
743  assert(nchrs == 1);
744  if (pcc->cv.nchrs >= pcc->cv.chrspace)
745  {
746  pcc->cv.chrspace *= 2;
747  newchrs = (chr *) realloc(pcc->cv.chrs,
748  pcc->cv.chrspace * sizeof(chr));
749  if (newchrs == NULL)
750  return false;
751  pcc->cv.chrs = newchrs;
752  }
753  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
754  }
755  return true;
756 }
#define assert(x)
Definition: regcustom.h:56

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

Referenced by pg_ctype_get_cache().

◆ pg_regex_collation

Oid pg_regex_collation
static

Definition at line 79 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache(), and pg_set_regex_collation().

◆ pg_regex_locale

◆ pg_regex_strategy