PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_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

#define PG_ISALNUM   (PG_ISDIGIT | PG_ISALPHA)

Definition at line 84 of file regc_pg_locale.c.

Referenced by pg_wc_isalnum().

#define PG_ISALPHA   0x02

Definition at line 83 of file regc_pg_locale.c.

Referenced by pg_wc_isalpha().

#define PG_ISDIGIT   0x01

Definition at line 82 of file regc_pg_locale.c.

Referenced by pg_wc_isdigit().

#define PG_ISGRAPH   0x10

Definition at line 87 of file regc_pg_locale.c.

Referenced by pg_wc_isgraph().

#define PG_ISLOWER   0x08

Definition at line 86 of file regc_pg_locale.c.

Referenced by pg_wc_islower().

#define PG_ISPRINT   0x20

Definition at line 88 of file regc_pg_locale.c.

Referenced by pg_wc_isprint().

#define PG_ISPUNCT   0x40

Definition at line 89 of file regc_pg_locale.c.

Referenced by pg_wc_ispunct().

#define PG_ISSPACE   0x80

Definition at line 90 of file regc_pg_locale.c.

Referenced by pg_wc_isspace().

#define PG_ISUPPER   0x04

Definition at line 85 of file regc_pg_locale.c.

Referenced by pg_wc_isupper().

Typedef Documentation

typedef int(* pg_wc_probefunc)(pg_wchar c)

Definition at line 740 of file regc_pg_locale.c.

Enumeration Type Documentation

Enumerator
PG_REGEX_LOCALE_C 
PG_REGEX_LOCALE_WIDE 
PG_REGEX_LOCALE_1BYTE 
PG_REGEX_LOCALE_WIDE_L 
PG_REGEX_LOCALE_1BYTE_L 
PG_REGEX_LOCALE_ICU 

Definition at line 65 of file regc_pg_locale.c.

66 {
67  PG_REGEX_LOCALE_C, /* C locale (encoding independent) */
68  PG_REGEX_LOCALE_WIDE, /* Use <wctype.h> functions */
69  PG_REGEX_LOCALE_1BYTE, /* Use <ctype.h> functions */
70  PG_REGEX_LOCALE_WIDE_L, /* Use locale_t <wctype.h> functions */
71  PG_REGEX_LOCALE_1BYTE_L, /* Use locale_t <ctype.h> functions */
72  PG_REGEX_LOCALE_ICU /* Use ICU uchar.h functions */
PG_Locale_Strategy

Function Documentation

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

Definition at line 800 of file regc_pg_locale.c.

References cvec::cclasscode, cvec::chrs, cvec::chrspace, pg_ctype_cache::collation, pg_ctype_cache::cv, free, malloc, MAX_SIMPLE_CHR, cvec::nchrs, pg_ctype_cache::next, cvec::nranges, pg_ctype_cache_list, pg_regex_collation, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, pg_regex_strategy, pg_ctype_cache::probefunc, cvec::ranges, cvec::rangespace, realloc, and store_match().

Referenced by cclass().

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

Definition at line 232 of file regc_pg_locale.c.

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

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

233 {
234  if (lc_ctype_is_c(collation))
235  {
236  /* C/POSIX collations use this path regardless of database encoding */
238  pg_regex_locale = 0;
240  }
241  else
242  {
243  if (collation == DEFAULT_COLLATION_OID)
244  pg_regex_locale = 0;
245  else if (OidIsValid(collation))
246  {
247  /*
248  * NB: pg_newlocale_from_collation will fail if not HAVE_LOCALE_T;
249  * the case of pg_regex_locale != 0 but not HAVE_LOCALE_T does not
250  * have to be considered below.
251  */
253  }
254  else
255  {
256  /*
257  * This typically means that the parser could not resolve a
258  * conflict of implicit collations, so report it that way.
259  */
260  ereport(ERROR,
261  (errcode(ERRCODE_INDETERMINATE_COLLATION),
262  errmsg("could not determine which collation to use for regular expression"),
263  errhint("Use the COLLATE clause to set the collation explicitly.")));
264  }
265 
266 #ifdef USE_ICU
269  else
270 #endif
271 #ifdef USE_WIDE_UPPER_LOWER
272  if (GetDatabaseEncoding() == PG_UTF8)
273  {
274  if (pg_regex_locale)
276  else
278  }
279  else
280 #endif /* USE_WIDE_UPPER_LOWER */
281  {
282  if (pg_regex_locale)
284  else
286  }
287 
288  pg_regex_collation = collation;
289  }
290 }
#define COLLPROVIDER_ICU
Definition: pg_collation.h:85
int errhint(const char *fmt,...)
Definition: elog.c:987
static pg_locale_t pg_regex_locale
static Oid pg_regex_collation
static PG_Locale_Strategy pg_regex_strategy
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:532
#define ERROR
Definition: elog.h:43
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
#define ereport(elevel, rest)
Definition: elog.h:122
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1275
int GetDatabaseEncoding(void)
Definition: mbutils.c:1015
#define C_COLLATION_OID
Definition: pg_collation.h:78
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1178
static int pg_wc_isalnum ( pg_wchar  c)
static

Definition at line 369 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

370 {
371  switch (pg_regex_strategy)
372  {
373  case PG_REGEX_LOCALE_C:
374  return (c <= (pg_wchar) 127 &&
377 #ifdef USE_WIDE_UPPER_LOWER
378  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
379  return iswalnum((wint_t) c);
380 #endif
381  /* FALL THRU */
383  return (c <= (pg_wchar) UCHAR_MAX &&
384  isalnum((unsigned char) c));
386 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
387  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
388  return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
389 #endif
390  /* FALL THRU */
392 #ifdef HAVE_LOCALE_T
393  return (c <= (pg_wchar) UCHAR_MAX &&
394  isalnum_l((unsigned char) c, pg_regex_locale->info.lt));
395 #endif
396  break;
397  case PG_REGEX_LOCALE_ICU:
398 #ifdef USE_ICU
399  return u_isalnum(c);
400 #endif
401  break;
402  }
403  return 0; /* can't get here, but keep compiler quiet */
404 }
#define iswalnum_l
Definition: win32.h:333
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define PG_ISALNUM
char * c
#define isalnum_l
Definition: win32.h:332
unsigned int pg_wchar
Definition: mbprint.c:31
static int pg_wc_isalpha ( pg_wchar  c)
static

Definition at line 331 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

332 {
333  switch (pg_regex_strategy)
334  {
335  case PG_REGEX_LOCALE_C:
336  return (c <= (pg_wchar) 127 &&
339 #ifdef USE_WIDE_UPPER_LOWER
340  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
341  return iswalpha((wint_t) c);
342 #endif
343  /* FALL THRU */
345  return (c <= (pg_wchar) UCHAR_MAX &&
346  isalpha((unsigned char) c));
348 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
349  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
350  return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
351 #endif
352  /* FALL THRU */
354 #ifdef HAVE_LOCALE_T
355  return (c <= (pg_wchar) UCHAR_MAX &&
356  isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
357 #endif
358  break;
359  case PG_REGEX_LOCALE_ICU:
360 #ifdef USE_ICU
361  return u_isalpha(c);
362 #endif
363  break;
364  }
365  return 0; /* can't get here, but keep compiler quiet */
366 }
#define PG_ISALPHA
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define iswalpha_l
Definition: win32.h:331
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define isalpha_l
Definition: win32.h:330
static int pg_wc_isdigit ( pg_wchar  c)
static

Definition at line 293 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

294 {
295  switch (pg_regex_strategy)
296  {
297  case PG_REGEX_LOCALE_C:
298  return (c <= (pg_wchar) 127 &&
301 #ifdef USE_WIDE_UPPER_LOWER
302  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
303  return iswdigit((wint_t) c);
304 #endif
305  /* FALL THRU */
307  return (c <= (pg_wchar) UCHAR_MAX &&
308  isdigit((unsigned char) c));
310 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
311  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
312  return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
313 #endif
314  /* FALL THRU */
316 #ifdef HAVE_LOCALE_T
317  return (c <= (pg_wchar) UCHAR_MAX &&
318  isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
319 #endif
320  break;
321  case PG_REGEX_LOCALE_ICU:
322 #ifdef USE_ICU
323  return u_isdigit(c);
324 #endif
325  break;
326  }
327  return 0; /* can't get here, but keep compiler quiet */
328 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define isdigit_l
Definition: win32.h:328
#define iswdigit_l
Definition: win32.h:329
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define PG_ISDIGIT
static int pg_wc_isgraph ( pg_wchar  c)
static

Definition at line 483 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

484 {
485  switch (pg_regex_strategy)
486  {
487  case PG_REGEX_LOCALE_C:
488  return (c <= (pg_wchar) 127 &&
491 #ifdef USE_WIDE_UPPER_LOWER
492  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
493  return iswgraph((wint_t) c);
494 #endif
495  /* FALL THRU */
497  return (c <= (pg_wchar) UCHAR_MAX &&
498  isgraph((unsigned char) c));
500 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
501  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
502  return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
503 #endif
504  /* FALL THRU */
506 #ifdef HAVE_LOCALE_T
507  return (c <= (pg_wchar) UCHAR_MAX &&
508  isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
509 #endif
510  break;
511  case PG_REGEX_LOCALE_ICU:
512 #ifdef USE_ICU
513  return u_isgraph(c);
514 #endif
515  break;
516  }
517  return 0; /* can't get here, but keep compiler quiet */
518 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define PG_ISGRAPH
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswgraph_l
Definition: win32.h:339
#define isgraph_l
Definition: win32.h:338
static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 445 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

446 {
447  switch (pg_regex_strategy)
448  {
449  case PG_REGEX_LOCALE_C:
450  return (c <= (pg_wchar) 127 &&
453 #ifdef USE_WIDE_UPPER_LOWER
454  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
455  return iswlower((wint_t) c);
456 #endif
457  /* FALL THRU */
459  return (c <= (pg_wchar) UCHAR_MAX &&
460  islower((unsigned char) c));
462 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
463  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
464  return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
465 #endif
466  /* FALL THRU */
468 #ifdef HAVE_LOCALE_T
469  return (c <= (pg_wchar) UCHAR_MAX &&
470  islower_l((unsigned char) c, pg_regex_locale->info.lt));
471 #endif
472  break;
473  case PG_REGEX_LOCALE_ICU:
474 #ifdef USE_ICU
475  return u_islower(c);
476 #endif
477  break;
478  }
479  return 0; /* can't get here, but keep compiler quiet */
480 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswlower_l
Definition: win32.h:337
#define islower_l
Definition: win32.h:336
#define PG_ISLOWER
static int pg_wc_isprint ( pg_wchar  c)
static

Definition at line 521 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

522 {
523  switch (pg_regex_strategy)
524  {
525  case PG_REGEX_LOCALE_C:
526  return (c <= (pg_wchar) 127 &&
529 #ifdef USE_WIDE_UPPER_LOWER
530  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
531  return iswprint((wint_t) c);
532 #endif
533  /* FALL THRU */
535  return (c <= (pg_wchar) UCHAR_MAX &&
536  isprint((unsigned char) c));
538 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
539  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
540  return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
541 #endif
542  /* FALL THRU */
544 #ifdef HAVE_LOCALE_T
545  return (c <= (pg_wchar) UCHAR_MAX &&
546  isprint_l((unsigned char) c, pg_regex_locale->info.lt));
547 #endif
548  break;
549  case PG_REGEX_LOCALE_ICU:
550 #ifdef USE_ICU
551  return u_isprint(c);
552 #endif
553  break;
554  }
555  return 0; /* can't get here, but keep compiler quiet */
556 }
#define PG_ISPRINT
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
#define iswprint_l
Definition: win32.h:341
static PG_Locale_Strategy pg_regex_strategy
#define isprint_l
Definition: win32.h:340
union pg_locale_struct::@120 info
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 559 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

560 {
561  switch (pg_regex_strategy)
562  {
563  case PG_REGEX_LOCALE_C:
564  return (c <= (pg_wchar) 127 &&
567 #ifdef USE_WIDE_UPPER_LOWER
568  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
569  return iswpunct((wint_t) c);
570 #endif
571  /* FALL THRU */
573  return (c <= (pg_wchar) UCHAR_MAX &&
574  ispunct((unsigned char) c));
576 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
577  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
578  return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
579 #endif
580  /* FALL THRU */
582 #ifdef HAVE_LOCALE_T
583  return (c <= (pg_wchar) UCHAR_MAX &&
584  ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
585 #endif
586  break;
587  case PG_REGEX_LOCALE_ICU:
588 #ifdef USE_ICU
589  return u_ispunct(c);
590 #endif
591  break;
592  }
593  return 0; /* can't get here, but keep compiler quiet */
594 }
#define ispunct_l
Definition: win32.h:342
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define iswpunct_l
Definition: win32.h:343
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define PG_ISPUNCT
static int pg_wc_isspace ( pg_wchar  c)
static

Definition at line 597 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

598 {
599  switch (pg_regex_strategy)
600  {
601  case PG_REGEX_LOCALE_C:
602  return (c <= (pg_wchar) 127 &&
605 #ifdef USE_WIDE_UPPER_LOWER
606  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
607  return iswspace((wint_t) c);
608 #endif
609  /* FALL THRU */
611  return (c <= (pg_wchar) UCHAR_MAX &&
612  isspace((unsigned char) c));
614 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
615  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
616  return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
617 #endif
618  /* FALL THRU */
620 #ifdef HAVE_LOCALE_T
621  return (c <= (pg_wchar) UCHAR_MAX &&
622  isspace_l((unsigned char) c, pg_regex_locale->info.lt));
623 #endif
624  break;
625  case PG_REGEX_LOCALE_ICU:
626 #ifdef USE_ICU
627  return u_isspace(c);
628 #endif
629  break;
630  }
631  return 0; /* can't get here, but keep compiler quiet */
632 }
#define isspace_l
Definition: win32.h:344
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define PG_ISSPACE
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswspace_l
Definition: win32.h:345
static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 407 of file regc_pg_locale.c.

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

Referenced by cclass(), and cclass_column_index().

408 {
409  switch (pg_regex_strategy)
410  {
411  case PG_REGEX_LOCALE_C:
412  return (c <= (pg_wchar) 127 &&
415 #ifdef USE_WIDE_UPPER_LOWER
416  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
417  return iswupper((wint_t) c);
418 #endif
419  /* FALL THRU */
421  return (c <= (pg_wchar) UCHAR_MAX &&
422  isupper((unsigned char) c));
424 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
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 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
#define iswupper_l
Definition: win32.h:335
#define isupper_l
Definition: win32.h:334
#define PG_ISUPPER
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
static pg_wchar pg_wc_tolower ( pg_wchar  c)
static

Definition at line 681 of file regc_pg_locale.c.

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

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

682 {
683  switch (pg_regex_strategy)
684  {
685  case PG_REGEX_LOCALE_C:
686  if (c <= (pg_wchar) 127)
687  return pg_ascii_tolower((unsigned char) c);
688  return c;
690  /* force C behavior for ASCII characters, per comments above */
691  if (c <= (pg_wchar) 127)
692  return pg_ascii_tolower((unsigned char) c);
693 #ifdef USE_WIDE_UPPER_LOWER
694  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
695  return towlower((wint_t) c);
696 #endif
697  /* FALL THRU */
699  /* force C behavior for ASCII characters, per comments above */
700  if (c <= (pg_wchar) 127)
701  return pg_ascii_tolower((unsigned char) c);
702  if (c <= (pg_wchar) UCHAR_MAX)
703  return tolower((unsigned char) c);
704  return c;
706 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
707  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
708  return towlower_l((wint_t) c, pg_regex_locale->info.lt);
709 #endif
710  /* FALL THRU */
712 #ifdef HAVE_LOCALE_T
713  if (c <= (pg_wchar) UCHAR_MAX)
714  return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
715 #endif
716  return c;
717  case PG_REGEX_LOCALE_ICU:
718 #ifdef USE_ICU
719  return u_tolower(c);
720 #endif
721  break;
722  }
723  return 0; /* can't get here, but keep compiler quiet */
724 }
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
unsigned char pg_ascii_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:146
union pg_locale_struct::@120 info
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define tolower_l
Definition: win32.h:324
#define towlower_l
Definition: win32.h:326
static pg_wchar pg_wc_toupper ( pg_wchar  c)
static

Definition at line 635 of file regc_pg_locale.c.

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

Referenced by allcases(), and range().

636 {
637  switch (pg_regex_strategy)
638  {
639  case PG_REGEX_LOCALE_C:
640  if (c <= (pg_wchar) 127)
641  return pg_ascii_toupper((unsigned char) c);
642  return c;
644  /* force C behavior for ASCII characters, per comments above */
645  if (c <= (pg_wchar) 127)
646  return pg_ascii_toupper((unsigned char) c);
647 #ifdef USE_WIDE_UPPER_LOWER
648  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
649  return towupper((wint_t) c);
650 #endif
651  /* FALL THRU */
653  /* force C behavior for ASCII characters, per comments above */
654  if (c <= (pg_wchar) 127)
655  return pg_ascii_toupper((unsigned char) c);
656  if (c <= (pg_wchar) UCHAR_MAX)
657  return toupper((unsigned char) c);
658  return c;
660 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
661  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
662  return towupper_l((wint_t) c, pg_regex_locale->info.lt);
663 #endif
664  /* FALL THRU */
666 #ifdef HAVE_LOCALE_T
667  if (c <= (pg_wchar) UCHAR_MAX)
668  return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
669 #endif
670  return c;
671  case PG_REGEX_LOCALE_ICU:
672 #ifdef USE_ICU
673  return u_toupper(c);
674 #endif
675  break;
676  }
677  return 0; /* can't get here, but keep compiler quiet */
678 }
#define toupper_l
Definition: win32.h:325
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
union pg_locale_struct::@120 info
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define towupper_l
Definition: win32.h:327
static bool store_match ( pg_ctype_cache pcc,
pg_wchar  chr1,
int  nchrs 
)
static

Definition at line 756 of file regc_pg_locale.c.

References assert, cvec::chrs, cvec::chrspace, pg_ctype_cache::cv, cvec::nchrs, cvec::nranges, cvec::ranges, cvec::rangespace, and realloc.

Referenced by pg_ctype_get_cache().

757 {
758  chr *newchrs;
759 
760  if (nchrs > 1)
761  {
762  if (pcc->cv.nranges >= pcc->cv.rangespace)
763  {
764  pcc->cv.rangespace *= 2;
765  newchrs = (chr *) realloc(pcc->cv.ranges,
766  pcc->cv.rangespace * sizeof(chr) * 2);
767  if (newchrs == NULL)
768  return false;
769  pcc->cv.ranges = newchrs;
770  }
771  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
772  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
773  pcc->cv.nranges++;
774  }
775  else
776  {
777  assert(nchrs == 1);
778  if (pcc->cv.nchrs >= pcc->cv.chrspace)
779  {
780  pcc->cv.chrspace *= 2;
781  newchrs = (chr *) realloc(pcc->cv.chrs,
782  pcc->cv.chrspace * sizeof(chr));
783  if (newchrs == NULL)
784  return false;
785  pcc->cv.chrs = newchrs;
786  }
787  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
788  }
789  return true;
790 }
struct cvec cv
int chrspace
Definition: regguts.h:259
pg_wchar chr
Definition: regcustom.h:68
chr * ranges
Definition: regguts.h:263
int nchrs
Definition: regguts.h:258
#define assert(TEST)
Definition: imath.c:37
chr * chrs
Definition: regguts.h:260
int rangespace
Definition: regguts.h:262
#define realloc(a, b)
Definition: header.h:60
int nranges
Definition: regguts.h:261

Variable Documentation

const unsigned char pg_char_properties[128]
static
pg_ctype_cache* pg_ctype_cache_list = NULL
static

Definition at line 750 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache().

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_locale_t pg_regex_locale
static

Definition at line 76 of file regc_pg_locale.c.