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

◆ PG_ISALPHA

#define PG_ISALPHA   0x02

Definition at line 82 of file regc_pg_locale.c.

◆ PG_ISDIGIT

#define PG_ISDIGIT   0x01

Definition at line 81 of file regc_pg_locale.c.

◆ PG_ISGRAPH

#define PG_ISGRAPH   0x10

Definition at line 86 of file regc_pg_locale.c.

◆ PG_ISLOWER

#define PG_ISLOWER   0x08

Definition at line 85 of file regc_pg_locale.c.

◆ PG_ISPRINT

#define PG_ISPRINT   0x20

Definition at line 87 of file regc_pg_locale.c.

◆ PG_ISPUNCT

#define PG_ISPUNCT   0x40

Definition at line 88 of file regc_pg_locale.c.

◆ PG_ISSPACE

#define PG_ISSPACE   0x80

Definition at line 89 of file regc_pg_locale.c.

◆ PG_ISUPPER

#define PG_ISUPPER   0x04

Definition at line 84 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 676 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 64 of file regc_pg_locale.c.

65 {
66  PG_REGEX_LOCALE_C, /* C locale (encoding independent) */
67  PG_REGEX_LOCALE_WIDE, /* Use <wctype.h> functions */
68  PG_REGEX_LOCALE_1BYTE, /* Use <ctype.h> functions */
69  PG_REGEX_LOCALE_WIDE_L, /* Use locale_t <wctype.h> functions */
70  PG_REGEX_LOCALE_1BYTE_L, /* Use locale_t <ctype.h> functions */
71  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 736 of file regc_pg_locale.c.

737 {
738  pg_ctype_cache *pcc;
739  pg_wchar max_chr;
740  pg_wchar cur_chr;
741  int nmatches;
742  chr *newchrs;
743 
744  /*
745  * Do we already have the answer cached?
746  */
747  for (pcc = pg_ctype_cache_list; pcc != NULL; pcc = pcc->next)
748  {
749  if (pcc->probefunc == probefunc &&
751  return &pcc->cv;
752  }
753 
754  /*
755  * Nope, so initialize some workspace ...
756  */
757  pcc = (pg_ctype_cache *) malloc(sizeof(pg_ctype_cache));
758  if (pcc == NULL)
759  return NULL;
760  pcc->probefunc = probefunc;
762  pcc->cv.nchrs = 0;
763  pcc->cv.chrspace = 128;
764  pcc->cv.chrs = (chr *) malloc(pcc->cv.chrspace * sizeof(chr));
765  pcc->cv.nranges = 0;
766  pcc->cv.rangespace = 64;
767  pcc->cv.ranges = (chr *) malloc(pcc->cv.rangespace * sizeof(chr) * 2);
768  if (pcc->cv.chrs == NULL || pcc->cv.ranges == NULL)
769  goto out_of_memory;
770  pcc->cv.cclasscode = cclasscode;
771 
772  /*
773  * Decide how many character codes we ought to look through. In general
774  * we don't go past MAX_SIMPLE_CHR; chr codes above that are handled at
775  * runtime using the "high colormap" mechanism. However, in C locale
776  * there's no need to go further than 127, and if we only have a 1-byte
777  * <ctype.h> API there's no need to go further than that can handle.
778  *
779  * If it's not MAX_SIMPLE_CHR that's constraining the search, mark the
780  * output cvec as not having any locale-dependent behavior, since there
781  * will be no need to do any run-time locale checks. (The #if's here
782  * would always be true for production values of MAX_SIMPLE_CHR, but it's
783  * useful to allow it to be small for testing purposes.)
784  */
785  switch (pg_regex_strategy)
786  {
787  case PG_REGEX_LOCALE_C:
788 #if MAX_SIMPLE_CHR >= 127
789  max_chr = (pg_wchar) 127;
790  pcc->cv.cclasscode = -1;
791 #else
792  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
793 #endif
794  break;
797  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
798  break;
801 #if MAX_SIMPLE_CHR >= UCHAR_MAX
802  max_chr = (pg_wchar) UCHAR_MAX;
803  pcc->cv.cclasscode = -1;
804 #else
805  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
806 #endif
807  break;
808  case PG_REGEX_LOCALE_ICU:
809  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
810  break;
811  default:
812  max_chr = 0; /* can't get here, but keep compiler quiet */
813  break;
814  }
815 
816  /*
817  * And scan 'em ...
818  */
819  nmatches = 0; /* number of consecutive matches */
820 
821  for (cur_chr = 0; cur_chr <= max_chr; cur_chr++)
822  {
823  if ((*probefunc) (cur_chr))
824  nmatches++;
825  else if (nmatches > 0)
826  {
827  if (!store_match(pcc, cur_chr - nmatches, nmatches))
828  goto out_of_memory;
829  nmatches = 0;
830  }
831  }
832 
833  if (nmatches > 0)
834  if (!store_match(pcc, cur_chr - nmatches, nmatches))
835  goto out_of_memory;
836 
837  /*
838  * We might have allocated more memory than needed, if so free it
839  */
840  if (pcc->cv.nchrs == 0)
841  {
842  free(pcc->cv.chrs);
843  pcc->cv.chrs = NULL;
844  pcc->cv.chrspace = 0;
845  }
846  else if (pcc->cv.nchrs < pcc->cv.chrspace)
847  {
848  newchrs = (chr *) realloc(pcc->cv.chrs,
849  pcc->cv.nchrs * sizeof(chr));
850  if (newchrs == NULL)
851  goto out_of_memory;
852  pcc->cv.chrs = newchrs;
853  pcc->cv.chrspace = pcc->cv.nchrs;
854  }
855  if (pcc->cv.nranges == 0)
856  {
857  free(pcc->cv.ranges);
858  pcc->cv.ranges = NULL;
859  pcc->cv.rangespace = 0;
860  }
861  else if (pcc->cv.nranges < pcc->cv.rangespace)
862  {
863  newchrs = (chr *) realloc(pcc->cv.ranges,
864  pcc->cv.nranges * sizeof(chr) * 2);
865  if (newchrs == NULL)
866  goto out_of_memory;
867  pcc->cv.ranges = newchrs;
868  pcc->cv.rangespace = pcc->cv.nranges;
869  }
870 
871  /*
872  * Success, link it into cache chain
873  */
874  pcc->next = pg_ctype_cache_list;
875  pg_ctype_cache_list = pcc;
876 
877  return &pcc->cv;
878 
879  /*
880  * Failure, clean up
881  */
882 out_of_memory:
883  free(pcc->cv.chrs);
884  free(pcc->cv.ranges);
885  free(pcc);
886 
887  return NULL;
888 }
#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 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 231 of file regc_pg_locale.c.

232 {
233  if (!OidIsValid(collation))
234  {
235  /*
236  * This typically means that the parser could not resolve a conflict
237  * of implicit collations, so report it that way.
238  */
239  ereport(ERROR,
240  (errcode(ERRCODE_INDETERMINATE_COLLATION),
241  errmsg("could not determine which collation to use for regular expression"),
242  errhint("Use the COLLATE clause to set the collation explicitly.")));
243  }
244 
245  if (lc_ctype_is_c(collation))
246  {
247  /* C/POSIX collations use this path regardless of database encoding */
249  pg_regex_locale = 0;
250  pg_regex_collation = C_COLLATION_OID;
251  }
252  else
253  {
255 
257  ereport(ERROR,
258  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
259  errmsg("nondeterministic collations are not supported for regular expressions")));
260 
261 #ifdef USE_ICU
262  if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
264  else
265 #endif
266  if (GetDatabaseEncoding() == PG_UTF8)
267  {
268  if (pg_regex_locale)
270  else
272  }
273  else
274  {
275  if (pg_regex_locale)
277  else
279  }
280 
281  pg_regex_collation = collation;
282  }
283 }
#define OidIsValid(objectId)
Definition: c.h:762
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:1513
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1359
bool pg_locale_deterministic(pg_locale_t locale)
Definition: pg_locale.c:1493
@ 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_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 350 of file regc_pg_locale.c.

351 {
352  switch (pg_regex_strategy)
353  {
354  case PG_REGEX_LOCALE_C:
355  return (c <= (pg_wchar) 127 &&
358  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
359  return iswalnum((wint_t) c);
360  /* FALL THRU */
362  return (c <= (pg_wchar) UCHAR_MAX &&
363  isalnum((unsigned char) c));
365  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
366  return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
367  /* FALL THRU */
369  return (c <= (pg_wchar) UCHAR_MAX &&
370  isalnum_l((unsigned char) c, pg_regex_locale->info.lt));
371  break;
372  case PG_REGEX_LOCALE_ICU:
373 #ifdef USE_ICU
374  return u_isalnum(c);
375 #endif
376  break;
377  }
378  return 0; /* can't get here, but keep compiler quiet */
379 }
char * c
#define PG_ISALNUM
static const unsigned char pg_char_properties[128]
locale_t lt
Definition: pg_locale.h:79
union pg_locale_struct::@146 info
#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_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 318 of file regc_pg_locale.c.

319 {
320  switch (pg_regex_strategy)
321  {
322  case PG_REGEX_LOCALE_C:
323  return (c <= (pg_wchar) 127 &&
326  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
327  return iswalpha((wint_t) c);
328  /* FALL THRU */
330  return (c <= (pg_wchar) UCHAR_MAX &&
331  isalpha((unsigned char) c));
333  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
334  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
335  /* FALL THRU */
337  return (c <= (pg_wchar) UCHAR_MAX &&
338  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
339  break;
340  case PG_REGEX_LOCALE_ICU:
341 #ifdef USE_ICU
342  return u_isalpha(c);
343 #endif
344  break;
345  }
346  return 0; /* can't get here, but keep compiler quiet */
347 }
#define PG_ISALPHA
#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_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 286 of file regc_pg_locale.c.

287 {
288  switch (pg_regex_strategy)
289  {
290  case PG_REGEX_LOCALE_C:
291  return (c <= (pg_wchar) 127 &&
294  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
295  return iswdigit((wint_t) c);
296  /* FALL THRU */
298  return (c <= (pg_wchar) UCHAR_MAX &&
299  isdigit((unsigned char) c));
301  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
302  return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
303  /* FALL THRU */
305  return (c <= (pg_wchar) UCHAR_MAX &&
306  isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
307  break;
308  case PG_REGEX_LOCALE_ICU:
309 #ifdef USE_ICU
310  return u_isdigit(c);
311 #endif
312  break;
313  }
314  return 0; /* can't get here, but keep compiler quiet */
315 }
#define PG_ISDIGIT
#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_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 455 of file regc_pg_locale.c.

456 {
457  switch (pg_regex_strategy)
458  {
459  case PG_REGEX_LOCALE_C:
460  return (c <= (pg_wchar) 127 &&
463  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
464  return iswgraph((wint_t) c);
465  /* FALL THRU */
467  return (c <= (pg_wchar) UCHAR_MAX &&
468  isgraph((unsigned char) c));
470  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
471  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
472  /* FALL THRU */
474  return (c <= (pg_wchar) UCHAR_MAX &&
475  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
476  break;
477  case PG_REGEX_LOCALE_ICU:
478 #ifdef USE_ICU
479  return u_isgraph(c);
480 #endif
481  break;
482  }
483  return 0; /* can't get here, but keep compiler quiet */
484 }
#define PG_ISGRAPH
#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_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 423 of file regc_pg_locale.c.

424 {
425  switch (pg_regex_strategy)
426  {
427  case PG_REGEX_LOCALE_C:
428  return (c <= (pg_wchar) 127 &&
431  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
432  return iswlower((wint_t) c);
433  /* FALL THRU */
435  return (c <= (pg_wchar) UCHAR_MAX &&
436  islower((unsigned char) c));
438  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
439  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
440  /* FALL THRU */
442  return (c <= (pg_wchar) UCHAR_MAX &&
443  islower_l((unsigned char) c, pg_regex_locale->info.lt));
444  break;
445  case PG_REGEX_LOCALE_ICU:
446 #ifdef USE_ICU
447  return u_islower(c);
448 #endif
449  break;
450  }
451  return 0; /* can't get here, but keep compiler quiet */
452 }
#define PG_ISLOWER
#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_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 487 of file regc_pg_locale.c.

488 {
489  switch (pg_regex_strategy)
490  {
491  case PG_REGEX_LOCALE_C:
492  return (c <= (pg_wchar) 127 &&
495  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
496  return iswprint((wint_t) c);
497  /* FALL THRU */
499  return (c <= (pg_wchar) UCHAR_MAX &&
500  isprint((unsigned char) c));
502  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
503  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
504  /* FALL THRU */
506  return (c <= (pg_wchar) UCHAR_MAX &&
507  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
508  break;
509  case PG_REGEX_LOCALE_ICU:
510 #ifdef USE_ICU
511  return u_isprint(c);
512 #endif
513  break;
514  }
515  return 0; /* can't get here, but keep compiler quiet */
516 }
#define PG_ISPRINT
#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_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 519 of file regc_pg_locale.c.

520 {
521  switch (pg_regex_strategy)
522  {
523  case PG_REGEX_LOCALE_C:
524  return (c <= (pg_wchar) 127 &&
527  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
528  return iswpunct((wint_t) c);
529  /* FALL THRU */
531  return (c <= (pg_wchar) UCHAR_MAX &&
532  ispunct((unsigned char) c));
534  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
535  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
536  /* FALL THRU */
538  return (c <= (pg_wchar) UCHAR_MAX &&
539  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
540  break;
541  case PG_REGEX_LOCALE_ICU:
542 #ifdef USE_ICU
543  return u_ispunct(c);
544 #endif
545  break;
546  }
547  return 0; /* can't get here, but keep compiler quiet */
548 }
#define PG_ISPUNCT
#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_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 551 of file regc_pg_locale.c.

552 {
553  switch (pg_regex_strategy)
554  {
555  case PG_REGEX_LOCALE_C:
556  return (c <= (pg_wchar) 127 &&
559  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
560  return iswspace((wint_t) c);
561  /* FALL THRU */
563  return (c <= (pg_wchar) UCHAR_MAX &&
564  isspace((unsigned char) c));
566  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
567  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
568  /* FALL THRU */
570  return (c <= (pg_wchar) UCHAR_MAX &&
571  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
572  break;
573  case PG_REGEX_LOCALE_ICU:
574 #ifdef USE_ICU
575  return u_isspace(c);
576 #endif
577  break;
578  }
579  return 0; /* can't get here, but keep compiler quiet */
580 }
#define PG_ISSPACE
#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_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 391 of file regc_pg_locale.c.

392 {
393  switch (pg_regex_strategy)
394  {
395  case PG_REGEX_LOCALE_C:
396  return (c <= (pg_wchar) 127 &&
399  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
400  return iswupper((wint_t) c);
401  /* FALL THRU */
403  return (c <= (pg_wchar) UCHAR_MAX &&
404  isupper((unsigned char) c));
406  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
407  return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
408  /* FALL THRU */
410  return (c <= (pg_wchar) UCHAR_MAX &&
411  isupper_l((unsigned char) c, pg_regex_locale->info.lt));
412  break;
413  case PG_REGEX_LOCALE_ICU:
414 #ifdef USE_ICU
415  return u_isupper(c);
416 #endif
417  break;
418  }
419  return 0; /* can't get here, but keep compiler quiet */
420 }
#define PG_ISUPPER
#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_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 382 of file regc_pg_locale.c.

383 {
384  /* We define word characters as alnum class plus underscore */
385  if (c == CHR('_'))
386  return 1;
387  return pg_wc_isalnum(c);
388 }
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 623 of file regc_pg_locale.c.

624 {
625  switch (pg_regex_strategy)
626  {
627  case PG_REGEX_LOCALE_C:
628  if (c <= (pg_wchar) 127)
629  return pg_ascii_tolower((unsigned char) c);
630  return c;
632  /* force C behavior for ASCII characters, per comments above */
633  if (c <= (pg_wchar) 127)
634  return pg_ascii_tolower((unsigned char) c);
635  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
636  return towlower((wint_t) c);
637  /* FALL THRU */
639  /* force C behavior for ASCII characters, per comments above */
640  if (c <= (pg_wchar) 127)
641  return pg_ascii_tolower((unsigned char) c);
642  if (c <= (pg_wchar) UCHAR_MAX)
643  return tolower((unsigned char) c);
644  return c;
646  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
647  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
648  /* FALL THRU */
650  if (c <= (pg_wchar) UCHAR_MAX)
651  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
652  return c;
653  case PG_REGEX_LOCALE_ICU:
654 #ifdef USE_ICU
655  return u_tolower(c);
656 #endif
657  break;
658  }
659  return 0; /* can't get here, but keep compiler quiet */
660 }
unsigned char pg_ascii_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:146
#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_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 583 of file regc_pg_locale.c.

584 {
585  switch (pg_regex_strategy)
586  {
587  case PG_REGEX_LOCALE_C:
588  if (c <= (pg_wchar) 127)
589  return pg_ascii_toupper((unsigned char) c);
590  return c;
592  /* force C behavior for ASCII characters, per comments above */
593  if (c <= (pg_wchar) 127)
594  return pg_ascii_toupper((unsigned char) c);
595  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
596  return towupper((wint_t) c);
597  /* FALL THRU */
599  /* force C behavior for ASCII characters, per comments above */
600  if (c <= (pg_wchar) 127)
601  return pg_ascii_toupper((unsigned char) c);
602  if (c <= (pg_wchar) UCHAR_MAX)
603  return toupper((unsigned char) c);
604  return c;
606  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
607  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
608  /* FALL THRU */
610  if (c <= (pg_wchar) UCHAR_MAX)
611  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
612  return c;
613  case PG_REGEX_LOCALE_ICU:
614 #ifdef USE_ICU
615  return u_toupper(c);
616 #endif
617  break;
618  }
619  return 0; /* can't get here, but keep compiler quiet */
620 }
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
#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_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 692 of file regc_pg_locale.c.

693 {
694  chr *newchrs;
695 
696  if (nchrs > 1)
697  {
698  if (pcc->cv.nranges >= pcc->cv.rangespace)
699  {
700  pcc->cv.rangespace *= 2;
701  newchrs = (chr *) realloc(pcc->cv.ranges,
702  pcc->cv.rangespace * sizeof(chr) * 2);
703  if (newchrs == NULL)
704  return false;
705  pcc->cv.ranges = newchrs;
706  }
707  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
708  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
709  pcc->cv.nranges++;
710  }
711  else
712  {
713  assert(nchrs == 1);
714  if (pcc->cv.nchrs >= pcc->cv.chrspace)
715  {
716  pcc->cv.chrspace *= 2;
717  newchrs = (chr *) realloc(pcc->cv.chrs,
718  pcc->cv.chrspace * sizeof(chr));
719  if (newchrs == NULL)
720  return false;
721  pcc->cv.chrs = newchrs;
722  }
723  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
724  }
725  return true;
726 }
#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 686 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache().

◆ pg_regex_collation

Oid pg_regex_collation
static

Definition at line 76 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache(), and pg_set_regex_collation().

◆ pg_regex_locale

◆ pg_regex_strategy