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
}
 

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

Referenced by pg_wc_isalnum().

#define PG_ISALPHA   0x02

Definition at line 82 of file regc_pg_locale.c.

Referenced by pg_wc_isalpha().

#define PG_ISDIGIT   0x01

Definition at line 81 of file regc_pg_locale.c.

Referenced by pg_wc_isdigit().

#define PG_ISGRAPH   0x10

Definition at line 86 of file regc_pg_locale.c.

Referenced by pg_wc_isgraph().

#define PG_ISLOWER   0x08

Definition at line 85 of file regc_pg_locale.c.

Referenced by pg_wc_islower().

#define PG_ISPRINT   0x20

Definition at line 87 of file regc_pg_locale.c.

Referenced by pg_wc_isprint().

#define PG_ISPUNCT   0x40

Definition at line 88 of file regc_pg_locale.c.

Referenced by pg_wc_ispunct().

#define PG_ISSPACE   0x80

Definition at line 89 of file regc_pg_locale.c.

Referenced by pg_wc_isspace().

#define PG_ISUPPER   0x04

Definition at line 84 of file regc_pg_locale.c.

Referenced by pg_wc_isupper().

Typedef Documentation

typedef int(* pg_wc_probefunc)(pg_wchar c)

Definition at line 679 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 

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 */
PG_Locale_Strategy

Function Documentation

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

Definition at line 739 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, NULL, pg_ctype_cache_list, pg_regex_collation, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, 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().

740 {
741  pg_ctype_cache *pcc;
742  pg_wchar max_chr;
743  pg_wchar cur_chr;
744  int nmatches;
745  chr *newchrs;
746 
747  /*
748  * Do we already have the answer cached?
749  */
750  for (pcc = pg_ctype_cache_list; pcc != NULL; pcc = pcc->next)
751  {
752  if (pcc->probefunc == probefunc &&
754  return &pcc->cv;
755  }
756 
757  /*
758  * Nope, so initialize some workspace ...
759  */
760  pcc = (pg_ctype_cache *) malloc(sizeof(pg_ctype_cache));
761  if (pcc == NULL)
762  return NULL;
763  pcc->probefunc = probefunc;
765  pcc->cv.nchrs = 0;
766  pcc->cv.chrspace = 128;
767  pcc->cv.chrs = (chr *) malloc(pcc->cv.chrspace * sizeof(chr));
768  pcc->cv.nranges = 0;
769  pcc->cv.rangespace = 64;
770  pcc->cv.ranges = (chr *) malloc(pcc->cv.rangespace * sizeof(chr) * 2);
771  if (pcc->cv.chrs == NULL || pcc->cv.ranges == NULL)
772  goto out_of_memory;
773  pcc->cv.cclasscode = cclasscode;
774 
775  /*
776  * Decide how many character codes we ought to look through. In general
777  * we don't go past MAX_SIMPLE_CHR; chr codes above that are handled at
778  * runtime using the "high colormap" mechanism. However, in C locale
779  * there's no need to go further than 127, and if we only have a 1-byte
780  * <ctype.h> API there's no need to go further than that can handle.
781  *
782  * If it's not MAX_SIMPLE_CHR that's constraining the search, mark the
783  * output cvec as not having any locale-dependent behavior, since there
784  * will be no need to do any run-time locale checks. (The #if's here
785  * would always be true for production values of MAX_SIMPLE_CHR, but it's
786  * useful to allow it to be small for testing purposes.)
787  */
788  switch (pg_regex_strategy)
789  {
790  case PG_REGEX_LOCALE_C:
791 #if MAX_SIMPLE_CHR >= 127
792  max_chr = (pg_wchar) 127;
793  pcc->cv.cclasscode = -1;
794 #else
795  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
796 #endif
797  break;
800  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
801  break;
804 #if MAX_SIMPLE_CHR >= UCHAR_MAX
805  max_chr = (pg_wchar) UCHAR_MAX;
806  pcc->cv.cclasscode = -1;
807 #else
808  max_chr = (pg_wchar) MAX_SIMPLE_CHR;
809 #endif
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  if (pcc->cv.chrs)
884  free(pcc->cv.chrs);
885  if (pcc->cv.ranges)
886  free(pcc->cv.ranges);
887  free(pcc);
888 
889  return NULL;
890 }
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:45
pg_wchar chr
Definition: regcustom.h:59
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:60
chr * chrs
Definition: regguts.h:260
#define NULL
Definition: c.h:226
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:55
int nranges
Definition: regguts.h:261
#define MAX_SIMPLE_CHR
Definition: regcustom.h:88
void pg_set_regex_collation ( Oid  collation)

Definition at line 231 of file regc_pg_locale.c.

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

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

232 {
233  if (lc_ctype_is_c(collation))
234  {
235  /* C/POSIX collations use this path regardless of database encoding */
237  pg_regex_locale = 0;
239  }
240  else
241  {
242  if (collation == DEFAULT_COLLATION_OID)
243  pg_regex_locale = 0;
244  else if (OidIsValid(collation))
245  {
246  /*
247  * NB: pg_newlocale_from_collation will fail if not HAVE_LOCALE_T;
248  * the case of pg_regex_locale != 0 but not HAVE_LOCALE_T does not
249  * have to be considered below.
250  */
252  }
253  else
254  {
255  /*
256  * This typically means that the parser could not resolve a
257  * conflict of implicit collations, so report it that way.
258  */
259  ereport(ERROR,
260  (errcode(ERRCODE_INDETERMINATE_COLLATION),
261  errmsg("could not determine which collation to use for regular expression"),
262  errhint("Use the COLLATE clause to set the collation explicitly.")));
263  }
264 
265 #ifdef USE_WIDE_UPPER_LOWER
266  if (GetDatabaseEncoding() == PG_UTF8)
267  {
268  if (pg_regex_locale)
270  else
272  }
273  else
274 #endif /* USE_WIDE_UPPER_LOWER */
275  {
276  if (pg_regex_locale)
278  else
280  }
281 
282  pg_regex_collation = collation;
283  }
284 }
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:534
#define ERROR
Definition: elog.h:43
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:68
#define ereport(elevel, rest)
Definition: elog.h:122
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1260
int GetDatabaseEncoding(void)
Definition: mbutils.c:1015
#define C_COLLATION_OID
Definition: pg_collation.h:71
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1173
static int pg_wc_isalnum ( pg_wchar  c)
static

Definition at line 353 of file regc_pg_locale.c.

References isalnum_l, iswalnum_l, pg_char_properties, PG_ISALNUM, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

354 {
355  switch (pg_regex_strategy)
356  {
357  case PG_REGEX_LOCALE_C:
358  return (c <= (pg_wchar) 127 &&
361 #ifdef USE_WIDE_UPPER_LOWER
362  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
363  return iswalnum((wint_t) c);
364 #endif
365  /* FALL THRU */
367  return (c <= (pg_wchar) UCHAR_MAX &&
368  isalnum((unsigned char) c));
370 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
371  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
372  return iswalnum_l((wint_t) c, pg_regex_locale);
373 #endif
374  /* FALL THRU */
376 #ifdef HAVE_LOCALE_T
377  return (c <= (pg_wchar) UCHAR_MAX &&
378  isalnum_l((unsigned char) c, pg_regex_locale));
379 #endif
380  break;
381  }
382  return 0; /* can't get here, but keep compiler quiet */
383 }
#define iswalnum_l
Definition: win32.h:343
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define PG_ISALNUM
char * c
#define isalnum_l
Definition: win32.h:342
unsigned int pg_wchar
Definition: mbprint.c:31
static int pg_wc_isalpha ( pg_wchar  c)
static

Definition at line 320 of file regc_pg_locale.c.

References isalpha_l, iswalpha_l, pg_char_properties, PG_ISALPHA, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

321 {
322  switch (pg_regex_strategy)
323  {
324  case PG_REGEX_LOCALE_C:
325  return (c <= (pg_wchar) 127 &&
328 #ifdef USE_WIDE_UPPER_LOWER
329  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
330  return iswalpha((wint_t) c);
331 #endif
332  /* FALL THRU */
334  return (c <= (pg_wchar) UCHAR_MAX &&
335  isalpha((unsigned char) c));
337 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
338  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
339  return iswalpha_l((wint_t) c, pg_regex_locale);
340 #endif
341  /* FALL THRU */
343 #ifdef HAVE_LOCALE_T
344  return (c <= (pg_wchar) UCHAR_MAX &&
345  isalpha_l((unsigned char) c, pg_regex_locale));
346 #endif
347  break;
348  }
349  return 0; /* can't get here, but keep compiler quiet */
350 }
#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
#define iswalpha_l
Definition: win32.h:341
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define isalpha_l
Definition: win32.h:340
static int pg_wc_isdigit ( pg_wchar  c)
static

Definition at line 287 of file regc_pg_locale.c.

References isdigit_l, iswdigit_l, pg_char_properties, PG_ISDIGIT, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

288 {
289  switch (pg_regex_strategy)
290  {
291  case PG_REGEX_LOCALE_C:
292  return (c <= (pg_wchar) 127 &&
295 #ifdef USE_WIDE_UPPER_LOWER
296  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
297  return iswdigit((wint_t) c);
298 #endif
299  /* FALL THRU */
301  return (c <= (pg_wchar) UCHAR_MAX &&
302  isdigit((unsigned char) c));
304 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
305  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
306  return iswdigit_l((wint_t) c, pg_regex_locale);
307 #endif
308  /* FALL THRU */
310 #ifdef HAVE_LOCALE_T
311  return (c <= (pg_wchar) UCHAR_MAX &&
312  isdigit_l((unsigned char) c, pg_regex_locale));
313 #endif
314  break;
315  }
316  return 0; /* can't get here, but keep compiler quiet */
317 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define isdigit_l
Definition: win32.h:338
#define iswdigit_l
Definition: win32.h:339
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 452 of file regc_pg_locale.c.

References isgraph_l, iswgraph_l, pg_char_properties, PG_ISGRAPH, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

453 {
454  switch (pg_regex_strategy)
455  {
456  case PG_REGEX_LOCALE_C:
457  return (c <= (pg_wchar) 127 &&
460 #ifdef USE_WIDE_UPPER_LOWER
461  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
462  return iswgraph((wint_t) c);
463 #endif
464  /* FALL THRU */
466  return (c <= (pg_wchar) UCHAR_MAX &&
467  isgraph((unsigned char) c));
469 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
470  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
471  return iswgraph_l((wint_t) c, pg_regex_locale);
472 #endif
473  /* FALL THRU */
475 #ifdef HAVE_LOCALE_T
476  return (c <= (pg_wchar) UCHAR_MAX &&
477  isgraph_l((unsigned char) c, pg_regex_locale));
478 #endif
479  break;
480  }
481  return 0; /* can't get here, but keep compiler quiet */
482 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define PG_ISGRAPH
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswgraph_l
Definition: win32.h:349
#define isgraph_l
Definition: win32.h:348
static int pg_wc_islower ( pg_wchar  c)
static

Definition at line 419 of file regc_pg_locale.c.

References islower_l, iswlower_l, pg_char_properties, PG_ISLOWER, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

420 {
421  switch (pg_regex_strategy)
422  {
423  case PG_REGEX_LOCALE_C:
424  return (c <= (pg_wchar) 127 &&
427 #ifdef USE_WIDE_UPPER_LOWER
428  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
429  return iswlower((wint_t) c);
430 #endif
431  /* FALL THRU */
433  return (c <= (pg_wchar) UCHAR_MAX &&
434  islower((unsigned char) c));
436 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
437  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
438  return iswlower_l((wint_t) c, pg_regex_locale);
439 #endif
440  /* FALL THRU */
442 #ifdef HAVE_LOCALE_T
443  return (c <= (pg_wchar) UCHAR_MAX &&
444  islower_l((unsigned char) c, pg_regex_locale));
445 #endif
446  break;
447  }
448  return 0; /* can't get here, but keep compiler quiet */
449 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswlower_l
Definition: win32.h:347
#define islower_l
Definition: win32.h:346
#define PG_ISLOWER
static int pg_wc_isprint ( pg_wchar  c)
static

Definition at line 485 of file regc_pg_locale.c.

References isprint_l, iswprint_l, pg_char_properties, PG_ISPRINT, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

486 {
487  switch (pg_regex_strategy)
488  {
489  case PG_REGEX_LOCALE_C:
490  return (c <= (pg_wchar) 127 &&
493 #ifdef USE_WIDE_UPPER_LOWER
494  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
495  return iswprint((wint_t) c);
496 #endif
497  /* FALL THRU */
499  return (c <= (pg_wchar) UCHAR_MAX &&
500  isprint((unsigned char) c));
502 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
503  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
504  return iswprint_l((wint_t) c, pg_regex_locale);
505 #endif
506  /* FALL THRU */
508 #ifdef HAVE_LOCALE_T
509  return (c <= (pg_wchar) UCHAR_MAX &&
510  isprint_l((unsigned char) c, pg_regex_locale));
511 #endif
512  break;
513  }
514  return 0; /* can't get here, but keep compiler quiet */
515 }
#define PG_ISPRINT
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
#define iswprint_l
Definition: win32.h:351
static PG_Locale_Strategy pg_regex_strategy
#define isprint_l
Definition: win32.h:350
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
static int pg_wc_ispunct ( pg_wchar  c)
static

Definition at line 518 of file regc_pg_locale.c.

References ispunct_l, iswpunct_l, pg_char_properties, PG_ISPUNCT, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

519 {
520  switch (pg_regex_strategy)
521  {
522  case PG_REGEX_LOCALE_C:
523  return (c <= (pg_wchar) 127 &&
526 #ifdef USE_WIDE_UPPER_LOWER
527  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
528  return iswpunct((wint_t) c);
529 #endif
530  /* FALL THRU */
532  return (c <= (pg_wchar) UCHAR_MAX &&
533  ispunct((unsigned char) c));
535 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
536  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
537  return iswpunct_l((wint_t) c, pg_regex_locale);
538 #endif
539  /* FALL THRU */
541 #ifdef HAVE_LOCALE_T
542  return (c <= (pg_wchar) UCHAR_MAX &&
543  ispunct_l((unsigned char) c, pg_regex_locale));
544 #endif
545  break;
546  }
547  return 0; /* can't get here, but keep compiler quiet */
548 }
#define ispunct_l
Definition: win32.h:352
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define iswpunct_l
Definition: win32.h:353
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 551 of file regc_pg_locale.c.

References isspace_l, iswspace_l, pg_char_properties, PG_ISSPACE, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

552 {
553  switch (pg_regex_strategy)
554  {
555  case PG_REGEX_LOCALE_C:
556  return (c <= (pg_wchar) 127 &&
559 #ifdef USE_WIDE_UPPER_LOWER
560  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
561  return iswspace((wint_t) c);
562 #endif
563  /* FALL THRU */
565  return (c <= (pg_wchar) UCHAR_MAX &&
566  isspace((unsigned char) c));
568 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
569  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
570  return iswspace_l((wint_t) c, pg_regex_locale);
571 #endif
572  /* FALL THRU */
574 #ifdef HAVE_LOCALE_T
575  return (c <= (pg_wchar) UCHAR_MAX &&
576  isspace_l((unsigned char) c, pg_regex_locale));
577 #endif
578  break;
579  }
580  return 0; /* can't get here, but keep compiler quiet */
581 }
#define isspace_l
Definition: win32.h:354
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define PG_ISSPACE
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define iswspace_l
Definition: win32.h:355
static int pg_wc_isupper ( pg_wchar  c)
static

Definition at line 386 of file regc_pg_locale.c.

References isupper_l, iswupper_l, pg_char_properties, PG_ISUPPER, pg_regex_locale, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, and pg_regex_strategy.

Referenced by cclass(), and cclass_column_index().

387 {
388  switch (pg_regex_strategy)
389  {
390  case PG_REGEX_LOCALE_C:
391  return (c <= (pg_wchar) 127 &&
394 #ifdef USE_WIDE_UPPER_LOWER
395  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
396  return iswupper((wint_t) c);
397 #endif
398  /* FALL THRU */
400  return (c <= (pg_wchar) UCHAR_MAX &&
401  isupper((unsigned char) c));
403 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
404  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
405  return iswupper_l((wint_t) c, pg_regex_locale);
406 #endif
407  /* FALL THRU */
409 #ifdef HAVE_LOCALE_T
410  return (c <= (pg_wchar) UCHAR_MAX &&
411  isupper_l((unsigned char) c, pg_regex_locale));
412 #endif
413  break;
414  }
415  return 0; /* can't get here, but keep compiler quiet */
416 }
static const unsigned char pg_char_properties[128]
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
#define iswupper_l
Definition: win32.h:345
#define isupper_l
Definition: win32.h:344
#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 625 of file regc_pg_locale.c.

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

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

626 {
627  switch (pg_regex_strategy)
628  {
629  case PG_REGEX_LOCALE_C:
630  if (c <= (pg_wchar) 127)
631  return pg_ascii_tolower((unsigned char) c);
632  return c;
634  /* force C behavior for ASCII characters, per comments above */
635  if (c <= (pg_wchar) 127)
636  return pg_ascii_tolower((unsigned char) c);
637 #ifdef USE_WIDE_UPPER_LOWER
638  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
639  return towlower((wint_t) c);
640 #endif
641  /* FALL THRU */
643  /* force C behavior for ASCII characters, per comments above */
644  if (c <= (pg_wchar) 127)
645  return pg_ascii_tolower((unsigned char) c);
646  if (c <= (pg_wchar) UCHAR_MAX)
647  return tolower((unsigned char) c);
648  return c;
650 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
651  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
652  return towlower_l((wint_t) c, pg_regex_locale);
653 #endif
654  /* FALL THRU */
656 #ifdef HAVE_LOCALE_T
657  if (c <= (pg_wchar) UCHAR_MAX)
658  return tolower_l((unsigned char) c, pg_regex_locale);
659 #endif
660  return c;
661  }
662  return 0; /* can't get here, but keep compiler quiet */
663 }
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
char * c
unsigned int pg_wchar
Definition: mbprint.c:31
#define tolower_l
Definition: win32.h:334
#define towlower_l
Definition: win32.h:336
static pg_wchar pg_wc_toupper ( pg_wchar  c)
static

Definition at line 584 of file regc_pg_locale.c.

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

Referenced by allcases(), and range().

585 {
586  switch (pg_regex_strategy)
587  {
588  case PG_REGEX_LOCALE_C:
589  if (c <= (pg_wchar) 127)
590  return pg_ascii_toupper((unsigned char) c);
591  return c;
593  /* force C behavior for ASCII characters, per comments above */
594  if (c <= (pg_wchar) 127)
595  return pg_ascii_toupper((unsigned char) c);
596 #ifdef USE_WIDE_UPPER_LOWER
597  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
598  return towupper((wint_t) c);
599 #endif
600  /* FALL THRU */
602  /* force C behavior for ASCII characters, per comments above */
603  if (c <= (pg_wchar) 127)
604  return pg_ascii_toupper((unsigned char) c);
605  if (c <= (pg_wchar) UCHAR_MAX)
606  return toupper((unsigned char) c);
607  return c;
609 #if defined(HAVE_LOCALE_T) && defined(USE_WIDE_UPPER_LOWER)
610  if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
611  return towupper_l((wint_t) c, pg_regex_locale);
612 #endif
613  /* FALL THRU */
615 #ifdef HAVE_LOCALE_T
616  if (c <= (pg_wchar) UCHAR_MAX)
617  return toupper_l((unsigned char) c, pg_regex_locale);
618 #endif
619  return c;
620  }
621  return 0; /* can't get here, but keep compiler quiet */
622 }
#define toupper_l
Definition: win32.h:335
static pg_locale_t pg_regex_locale
static PG_Locale_Strategy pg_regex_strategy
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:337
static bool store_match ( pg_ctype_cache pcc,
pg_wchar  chr1,
int  nchrs 
)
static

Definition at line 695 of file regc_pg_locale.c.

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

Referenced by pg_ctype_get_cache().

696 {
697  chr *newchrs;
698 
699  if (nchrs > 1)
700  {
701  if (pcc->cv.nranges >= pcc->cv.rangespace)
702  {
703  pcc->cv.rangespace *= 2;
704  newchrs = (chr *) realloc(pcc->cv.ranges,
705  pcc->cv.rangespace * sizeof(chr) * 2);
706  if (newchrs == NULL)
707  return false;
708  pcc->cv.ranges = newchrs;
709  }
710  pcc->cv.ranges[pcc->cv.nranges * 2] = chr1;
711  pcc->cv.ranges[pcc->cv.nranges * 2 + 1] = chr1 + nchrs - 1;
712  pcc->cv.nranges++;
713  }
714  else
715  {
716  assert(nchrs == 1);
717  if (pcc->cv.nchrs >= pcc->cv.chrspace)
718  {
719  pcc->cv.chrspace *= 2;
720  newchrs = (chr *) realloc(pcc->cv.chrs,
721  pcc->cv.chrspace * sizeof(chr));
722  if (newchrs == NULL)
723  return false;
724  pcc->cv.chrs = newchrs;
725  }
726  pcc->cv.chrs[pcc->cv.nchrs++] = chr1;
727  }
728  return true;
729 }
struct cvec cv
int chrspace
Definition: regguts.h:259
pg_wchar chr
Definition: regcustom.h:59
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
#define NULL
Definition: c.h:226
int rangespace
Definition: regguts.h:262
#define realloc(a, b)
Definition: header.h:55
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 689 of file regc_pg_locale.c.

Referenced by pg_ctype_get_cache().

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