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_STRATEGY_C , PG_REGEX_STRATEGY_BUILTIN , PG_REGEX_STRATEGY_LIBC_WIDE , PG_REGEX_STRATEGY_LIBC_1BYTE ,
  PG_REGEX_STRATEGY_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 626 of file regc_pg_locale.c.

Enumeration Type Documentation

◆ PG_Locale_Strategy

Enumerator
PG_REGEX_STRATEGY_C 
PG_REGEX_STRATEGY_BUILTIN 
PG_REGEX_STRATEGY_LIBC_WIDE 
PG_REGEX_STRATEGY_LIBC_1BYTE 
PG_REGEX_STRATEGY_ICU 

Definition at line 66 of file regc_pg_locale.c.

67 {
68  PG_REGEX_STRATEGY_C, /* C locale (encoding independent) */
69  PG_REGEX_STRATEGY_BUILTIN, /* built-in Unicode semantics */
70  PG_REGEX_STRATEGY_LIBC_WIDE, /* Use locale_t <wctype.h> functions */
71  PG_REGEX_STRATEGY_LIBC_1BYTE, /* Use locale_t <ctype.h> functions */
72  PG_REGEX_STRATEGY_ICU, /* Use ICU uchar.h functions */
PG_Locale_Strategy
@ PG_REGEX_STRATEGY_C
@ PG_REGEX_STRATEGY_LIBC_WIDE
@ PG_REGEX_STRATEGY_ICU
@ PG_REGEX_STRATEGY_BUILTIN
@ PG_REGEX_STRATEGY_LIBC_1BYTE

Function Documentation

◆ pg_ctype_get_cache()

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

Definition at line 686 of file regc_pg_locale.c.

687 {
688  pg_ctype_cache *pcc;
689  pg_wchar max_chr;
690  pg_wchar cur_chr;
691  int nmatches;
692  chr *newchrs;
693 
694  /*
695  * Do we already have the answer cached?
696  */
697  for (pcc = pg_ctype_cache_list; pcc != NULL; pcc = pcc->next)
698  {
699  if (pcc->probefunc == probefunc &&
701  return &pcc->cv;
702  }
703 
704  /*
705  * Nope, so initialize some workspace ...
706  */
707  pcc = (pg_ctype_cache *) malloc(sizeof(pg_ctype_cache));
708  if (pcc == NULL)
709  return NULL;
710  pcc->probefunc = probefunc;
712  pcc->cv.nchrs = 0;
713  pcc->cv.chrspace = 128;
714  pcc->cv.chrs = (chr *) malloc(pcc->cv.chrspace * sizeof(chr));
715  pcc->cv.nranges = 0;
716  pcc->cv.rangespace = 64;
717  pcc->cv.ranges = (chr *) malloc(pcc->cv.rangespace * sizeof(chr) * 2);
718  if (pcc->cv.chrs == NULL || pcc->cv.ranges == NULL)
719  goto out_of_memory;
720  pcc->cv.cclasscode = cclasscode;
721 
722  /*
723  * Decide how many character codes we ought to look through. In general
724  * we don't go past MAX_SIMPLE_CHR; chr codes above that are handled at
725  * runtime using the "high colormap" mechanism. However, in C locale
726  * there's no need to go further than 127, and if we only have a 1-byte
727  * <ctype.h> API there's no need to go further than that can handle.
728  *
729  * If it's not MAX_SIMPLE_CHR that's constraining the search, mark the
730  * output cvec as not having any locale-dependent behavior, since there
731  * will be no need to do any run-time locale checks. (The #if's here
732  * would always be true for production values of MAX_SIMPLE_CHR, but it's
733  * useful to allow it to be small for testing purposes.)
734  */
735  switch (pg_regex_strategy)
736  {
737  case PG_REGEX_STRATEGY_C:
738 #if MAX_SIMPLE_CHR >= 127
739  max_chr = (pg_wchar) 127;
740  pcc->cv.cclasscode = -1;
741 #else
742  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
743 #endif
744  break;
746  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
747  break;
749  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
750  break;
752 #if MAX_SIMPLE_CHR >= UCHAR_MAX
753  max_chr = (pg_wchar) UCHAR_MAX;
754  pcc->cv.cclasscode = -1;
755 #else
756  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
757 #endif
758  break;
760  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
761  break;
762  default:
763  Assert(false);
764  max_chr = 0; /* can't get here, but keep compiler quiet */
765  break;
766  }
767 
768  /*
769  * And scan 'em ...
770  */
771  nmatches = 0; /* number of consecutive matches */
772 
773  for (cur_chr = 0; cur_chr <= max_chr; cur_chr++)
774  {
775  if ((*probefunc) (cur_chr))
776  nmatches++;
777  else if (nmatches > 0)
778  {
779  if (!store_match(pcc, cur_chr - nmatches, nmatches))
780  goto out_of_memory;
781  nmatches = 0;
782  }
783  }
784 
785  if (nmatches > 0)
786  if (!store_match(pcc, cur_chr - nmatches, nmatches))
787  goto out_of_memory;
788 
789  /*
790  * We might have allocated more memory than needed, if so free it
791  */
792  if (pcc->cv.nchrs == 0)
793  {
794  free(pcc->cv.chrs);
795  pcc->cv.chrs = NULL;
796  pcc->cv.chrspace = 0;
797  }
798  else if (pcc->cv.nchrs < pcc->cv.chrspace)
799  {
800  newchrs = (chr *) realloc(pcc->cv.chrs,
801  pcc->cv.nchrs * sizeof(chr));
802  if (newchrs == NULL)
803  goto out_of_memory;
804  pcc->cv.chrs = newchrs;
805  pcc->cv.chrspace = pcc->cv.nchrs;
806  }
807  if (pcc->cv.nranges == 0)
808  {
809  free(pcc->cv.ranges);
810  pcc->cv.ranges = NULL;
811  pcc->cv.rangespace = 0;
812  }
813  else if (pcc->cv.nranges < pcc->cv.rangespace)
814  {
815  newchrs = (chr *) realloc(pcc->cv.ranges,
816  pcc->cv.nranges * sizeof(chr) * 2);
817  if (newchrs == NULL)
818  goto out_of_memory;
819  pcc->cv.ranges = newchrs;
820  pcc->cv.rangespace = pcc->cv.nranges;
821  }
822 
823  /*
824  * Success, link it into cache chain
825  */
826  pcc->next = pg_ctype_cache_list;
827  pg_ctype_cache_list = pcc;
828 
829  return &pcc->cv;
830 
831  /*
832  * Failure, clean up
833  */
834 out_of_memory:
835  free(pcc->cv.chrs);
836  free(pcc->cv.ranges);
837  free(pcc);
838 
839  return NULL;
840 }
#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_collation, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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  pg_locale_t locale = 0;
235  PG_Locale_Strategy strategy;
236 
237  if (!OidIsValid(collation))
238  {
239  /*
240  * This typically means that the parser could not resolve a conflict
241  * of implicit collations, so report it that way.
242  */
243  ereport(ERROR,
244  (errcode(ERRCODE_INDETERMINATE_COLLATION),
245  errmsg("could not determine which collation to use for regular expression"),
246  errhint("Use the COLLATE clause to set the collation explicitly.")));
247  }
248 
249  if (collation == C_COLLATION_OID)
250  {
251  /*
252  * Some callers expect regexes to work for C_COLLATION_OID before
253  * catalog access is available, so we can't call
254  * pg_newlocale_from_collation().
255  */
256  strategy = PG_REGEX_STRATEGY_C;
257  collation = C_COLLATION_OID;
258  }
259  else
260  {
261  locale = pg_newlocale_from_collation(collation);
262 
263  if (!locale->deterministic)
264  ereport(ERROR,
265  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
266  errmsg("nondeterministic collations are not supported for regular expressions")));
267 
268  if (locale->ctype_is_c)
269  {
270  /*
271  * C/POSIX collations use this path regardless of database
272  * encoding
273  */
274  strategy = PG_REGEX_STRATEGY_C;
275  locale = 0;
276  collation = C_COLLATION_OID;
277  }
278  else if (locale->provider == COLLPROVIDER_BUILTIN)
279  {
281  strategy = PG_REGEX_STRATEGY_BUILTIN;
282  }
283 #ifdef USE_ICU
284  else if (locale->provider == COLLPROVIDER_ICU)
285  {
286  strategy = PG_REGEX_STRATEGY_ICU;
287  }
288 #endif
289  else
290  {
291  Assert(locale->provider == COLLPROVIDER_LIBC);
292  if (GetDatabaseEncoding() == PG_UTF8)
293  strategy = PG_REGEX_STRATEGY_LIBC_WIDE;
294  else
295  strategy = PG_REGEX_STRATEGY_LIBC_1BYTE;
296  }
297  }
298 
299  pg_regex_strategy = strategy;
301  pg_regex_collation = collation;
302 }
#define OidIsValid(objectId)
Definition: c.h:775
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static char * locale
Definition: initdb.c:140
int GetDatabaseEncoding(void)
Definition: mbutils.c:1261
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1510
@ PG_UTF8
Definition: pg_wchar.h:232
static pg_locale_t pg_regex_locale

References Assert, ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), locale, OidIsValid, pg_newlocale_from_collation(), pg_regex_collation, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, and PG_UTF8.

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

◆ pg_wc_isalnum()

static int pg_wc_isalnum ( pg_wchar  c)
static

Definition at line 359 of file regc_pg_locale.c.

360 {
361  switch (pg_regex_strategy)
362  {
363  case PG_REGEX_STRATEGY_C:
364  return (c <= (pg_wchar) 127 &&
367  return pg_u_isalnum(c, true);
369  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
370  return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
371  /* FALL THRU */
373  return (c <= (pg_wchar) UCHAR_MAX &&
374  isalnum_l((unsigned char) c, pg_regex_locale->info.lt));
375  break;
377 #ifdef USE_ICU
378  return u_isalnum(c);
379 #endif
380  break;
381  }
382  return 0; /* can't get here, but keep compiler quiet */
383 }
char * c
#define PG_ISALNUM
static const unsigned char pg_char_properties[128]
union pg_locale_struct::@153 info
locale_t lt
Definition: pg_locale.h:94
bool pg_u_isalnum(pg_wchar code, bool posix)
#define iswalnum_l
Definition: win32_port.h:452
#define isalnum_l
Definition: win32_port.h:451

References pg_locale_struct::info, isalnum_l, iswalnum_l, pg_locale_struct::lt, pg_char_properties, PG_ISALNUM, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 332 of file regc_pg_locale.c.

333 {
334  switch (pg_regex_strategy)
335  {
336  case PG_REGEX_STRATEGY_C:
337  return (c <= (pg_wchar) 127 &&
340  return pg_u_isalpha(c);
342  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
343  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
344  /* FALL THRU */
346  return (c <= (pg_wchar) UCHAR_MAX &&
347  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
348  break;
350 #ifdef USE_ICU
351  return u_isalpha(c);
352 #endif
353  break;
354  }
355  return 0; /* can't get here, but keep compiler quiet */
356 }
#define PG_ISALPHA
bool pg_u_isalpha(pg_wchar code)
#define isalpha_l
Definition: win32_port.h:449
#define iswalpha_l
Definition: win32_port.h:450

References pg_locale_struct::info, isalpha_l, iswalpha_l, pg_locale_struct::lt, pg_char_properties, PG_ISALPHA, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 305 of file regc_pg_locale.c.

306 {
307  switch (pg_regex_strategy)
308  {
309  case PG_REGEX_STRATEGY_C:
310  return (c <= (pg_wchar) 127 &&
313  return pg_u_isdigit(c, true);
315  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
316  return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
317  /* FALL THRU */
319  return (c <= (pg_wchar) UCHAR_MAX &&
320  isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
321  break;
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 PG_ISDIGIT
bool pg_u_isdigit(pg_wchar code, bool posix)
#define isdigit_l
Definition: win32_port.h:447
#define iswdigit_l
Definition: win32_port.h:448

References pg_locale_struct::info, isdigit_l, iswdigit_l, pg_locale_struct::lt, pg_char_properties, PG_ISDIGIT, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 449 of file regc_pg_locale.c.

450 {
451  switch (pg_regex_strategy)
452  {
453  case PG_REGEX_STRATEGY_C:
454  return (c <= (pg_wchar) 127 &&
457  return pg_u_isgraph(c);
459  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
460  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
461  /* FALL THRU */
463  return (c <= (pg_wchar) UCHAR_MAX &&
464  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
465  break;
467 #ifdef USE_ICU
468  return u_isgraph(c);
469 #endif
470  break;
471  }
472  return 0; /* can't get here, but keep compiler quiet */
473 }
#define PG_ISGRAPH
bool pg_u_isgraph(pg_wchar code)
#define isgraph_l
Definition: win32_port.h:457
#define iswgraph_l
Definition: win32_port.h:458

References pg_locale_struct::info, isgraph_l, iswgraph_l, pg_locale_struct::lt, pg_char_properties, PG_ISGRAPH, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 422 of file regc_pg_locale.c.

423 {
424  switch (pg_regex_strategy)
425  {
426  case PG_REGEX_STRATEGY_C:
427  return (c <= (pg_wchar) 127 &&
430  return pg_u_islower(c);
432  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
433  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
434  /* FALL THRU */
436  return (c <= (pg_wchar) UCHAR_MAX &&
437  islower_l((unsigned char) c, pg_regex_locale->info.lt));
438  break;
440 #ifdef USE_ICU
441  return u_islower(c);
442 #endif
443  break;
444  }
445  return 0; /* can't get here, but keep compiler quiet */
446 }
#define PG_ISLOWER
bool pg_u_islower(pg_wchar code)
#define islower_l
Definition: win32_port.h:455
#define iswlower_l
Definition: win32_port.h:456

References pg_locale_struct::info, islower_l, iswlower_l, pg_locale_struct::lt, pg_char_properties, PG_ISLOWER, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 476 of file regc_pg_locale.c.

477 {
478  switch (pg_regex_strategy)
479  {
480  case PG_REGEX_STRATEGY_C:
481  return (c <= (pg_wchar) 127 &&
484  return pg_u_isprint(c);
486  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
487  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
488  /* FALL THRU */
490  return (c <= (pg_wchar) UCHAR_MAX &&
491  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
492  break;
494 #ifdef USE_ICU
495  return u_isprint(c);
496 #endif
497  break;
498  }
499  return 0; /* can't get here, but keep compiler quiet */
500 }
#define PG_ISPRINT
bool pg_u_isprint(pg_wchar code)
#define isprint_l
Definition: win32_port.h:459
#define iswprint_l
Definition: win32_port.h:460

References pg_locale_struct::info, isprint_l, iswprint_l, pg_locale_struct::lt, pg_char_properties, PG_ISPRINT, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 503 of file regc_pg_locale.c.

504 {
505  switch (pg_regex_strategy)
506  {
507  case PG_REGEX_STRATEGY_C:
508  return (c <= (pg_wchar) 127 &&
511  return pg_u_ispunct(c, true);
513  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
514  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
515  /* FALL THRU */
517  return (c <= (pg_wchar) UCHAR_MAX &&
518  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
519  break;
521 #ifdef USE_ICU
522  return u_ispunct(c);
523 #endif
524  break;
525  }
526  return 0; /* can't get here, but keep compiler quiet */
527 }
#define PG_ISPUNCT
bool pg_u_ispunct(pg_wchar code, bool posix)
#define ispunct_l
Definition: win32_port.h:461
#define iswpunct_l
Definition: win32_port.h:462

References pg_locale_struct::info, ispunct_l, iswpunct_l, pg_locale_struct::lt, pg_char_properties, PG_ISPUNCT, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 530 of file regc_pg_locale.c.

531 {
532  switch (pg_regex_strategy)
533  {
534  case PG_REGEX_STRATEGY_C:
535  return (c <= (pg_wchar) 127 &&
538  return pg_u_isspace(c);
540  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
541  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
542  /* FALL THRU */
544  return (c <= (pg_wchar) UCHAR_MAX &&
545  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
546  break;
548 #ifdef USE_ICU
549  return u_isspace(c);
550 #endif
551  break;
552  }
553  return 0; /* can't get here, but keep compiler quiet */
554 }
#define PG_ISSPACE
bool pg_u_isspace(pg_wchar code)
#define iswspace_l
Definition: win32_port.h:464
#define isspace_l
Definition: win32_port.h:463

References pg_locale_struct::info, isspace_l, iswspace_l, pg_locale_struct::lt, pg_char_properties, PG_ISSPACE, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 395 of file regc_pg_locale.c.

396 {
397  switch (pg_regex_strategy)
398  {
399  case PG_REGEX_STRATEGY_C:
400  return (c <= (pg_wchar) 127 &&
403  return pg_u_isupper(c);
405  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
406  return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
407  /* FALL THRU */
409  return (c <= (pg_wchar) UCHAR_MAX &&
410  isupper_l((unsigned char) c, pg_regex_locale->info.lt));
411  break;
413 #ifdef USE_ICU
414  return u_isupper(c);
415 #endif
416  break;
417  }
418  return 0; /* can't get here, but keep compiler quiet */
419 }
#define PG_ISUPPER
bool pg_u_isupper(pg_wchar code)
#define iswupper_l
Definition: win32_port.h:454
#define isupper_l
Definition: win32_port.h:453

References pg_locale_struct::info, isupper_l, iswupper_l, pg_locale_struct::lt, pg_char_properties, PG_ISUPPER, pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 386 of file regc_pg_locale.c.

387 {
388  /* We define word characters as alnum class plus underscore */
389  if (c == CHR('_'))
390  return 1;
391  return pg_wc_isalnum(c);
392 }
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 585 of file regc_pg_locale.c.

586 {
587  switch (pg_regex_strategy)
588  {
589  case PG_REGEX_STRATEGY_C:
590  if (c <= (pg_wchar) 127)
591  return pg_ascii_tolower((unsigned char) c);
592  return c;
594  return unicode_lowercase_simple(c);
596  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
597  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
598  /* FALL THRU */
600  if (c <= (pg_wchar) UCHAR_MAX)
601  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
602  return c;
604 #ifdef USE_ICU
605  return u_tolower(c);
606 #endif
607  break;
608  }
609  return 0; /* can't get here, but keep compiler quiet */
610 }
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:445
#define tolower_l
Definition: win32_port.h:443

References pg_locale_struct::info, pg_locale_struct::lt, pg_ascii_tolower(), pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 557 of file regc_pg_locale.c.

558 {
559  switch (pg_regex_strategy)
560  {
561  case PG_REGEX_STRATEGY_C:
562  if (c <= (pg_wchar) 127)
563  return pg_ascii_toupper((unsigned char) c);
564  return c;
566  return unicode_uppercase_simple(c);
568  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
569  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
570  /* FALL THRU */
572  if (c <= (pg_wchar) UCHAR_MAX)
573  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
574  return c;
576 #ifdef USE_ICU
577  return u_toupper(c);
578 #endif
579  break;
580  }
581  return 0; /* can't get here, but keep compiler quiet */
582 }
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:444
#define towupper_l
Definition: win32_port.h:446

References pg_locale_struct::info, pg_locale_struct::lt, pg_ascii_toupper(), pg_regex_locale, pg_regex_strategy, PG_REGEX_STRATEGY_BUILTIN, PG_REGEX_STRATEGY_C, PG_REGEX_STRATEGY_ICU, PG_REGEX_STRATEGY_LIBC_1BYTE, PG_REGEX_STRATEGY_LIBC_WIDE, 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 642 of file regc_pg_locale.c.

643 {
644  chr *newchrs;
645 
646  if (nchrs > 1)
647  {
648  if (pcc->cv.nranges >= pcc->cv.rangespace)
649  {
650  pcc->cv.rangespace *= 2;
651  newchrs = (chr *) realloc(pcc->cv.ranges,
652  pcc->cv.rangespace * sizeof(chr) * 2);
653  if (newchrs == NULL)
654  return false;
655  pcc->cv.ranges = newchrs;
656  }
657  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
658  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
659  pcc->cv.nranges++;
660  }
661  else
662  {
663  assert(nchrs == 1);
664  if (pcc->cv.nchrs >= pcc->cv.chrspace)
665  {
666  pcc->cv.chrspace *= 2;
667  newchrs = (chr *) realloc(pcc->cv.chrs,
668  pcc->cv.chrspace * sizeof(chr));
669  if (newchrs == NULL)
670  return false;
671  pcc->cv.chrs = newchrs;
672  }
673  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
674  }
675  return true;
676 }
#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 636 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