PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
regc_locale.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cname
 

Enumerations

enum  classes {
  CC_ALNUM, CC_ALPHA, CC_ASCII, CC_BLANK,
  CC_CNTRL, CC_DIGIT, CC_GRAPH, CC_LOWER,
  CC_PRINT, CC_PUNCT, CC_SPACE, CC_UPPER,
  CC_XDIGIT
}
 

Functions

static chr element (struct vars *v, const chr *startp, const chr *endp)
 
static struct cvecrange (struct vars *v, chr a, chr b, int cases)
 
static int before (chr x, chr y)
 
static struct cvececlass (struct vars *v, chr c, int cases)
 
static struct cveccclass (struct vars *v, const chr *startp, const chr *endp, int cases)
 
static int cclass_column_index (struct colormap *cm, chr c)
 
static struct cvecallcases (struct vars *v, chr c)
 
static int cmp (const chr *x, const chr *y, size_t len)
 
static int casecmp (const chr *x, const chr *y, size_t len)
 

Variables

static const struct cname cnames []
 
static const char *const classNames [NUM_CCLASSES+1]
 

Enumeration Type Documentation

enum classes
Enumerator
CC_ALNUM 
CC_ALPHA 
CC_ASCII 
CC_BLANK 
CC_CNTRL 
CC_DIGIT 
CC_GRAPH 
CC_LOWER 
CC_PRINT 
CC_PUNCT 
CC_SPACE 
CC_UPPER 
CC_XDIGIT 

Definition at line 360 of file regc_locale.c.

Function Documentation

static struct cvec* allcases ( struct vars v,
chr  c 
)
static

Definition at line 716 of file regc_locale.c.

References addchr(), getcvec(), pg_wc_tolower(), and pg_wc_toupper().

Referenced by eclass().

718 {
719  struct cvec *cv;
720  chr lc,
721  uc;
722 
723  lc = pg_wc_tolower(c);
724  uc = pg_wc_toupper(c);
725 
726  cv = getcvec(v, 2, 0);
727  addchr(cv, lc);
728  if (lc != uc)
729  addchr(cv, uc);
730  return cv;
731 }
static pg_wchar pg_wc_toupper(pg_wchar c)
pg_wchar chr
Definition: regcustom.h:68
char * c
Definition: regguts.h:256
static pg_wchar pg_wc_tolower(pg_wchar c)
static void addchr(struct cvec *cv, chr c)
Definition: regc_cvec.c:79
static struct cvec * getcvec(struct vars *v, int nchrs, int nranges)
Definition: regc_cvec.c:112
static int before ( chr  x,
chr  y 
)
static

Definition at line 496 of file regc_locale.c.

Referenced by avlRotate(), dlist_insert_before(), ExecQueryUsingCursor(), PSQLexecWatch(), range(), and SendQuery().

497 {
498  if (x < y)
499  return 1;
500  return 0;
501 }
static int casecmp ( const chr x,
const chr y,
size_t  len 
)
static

Definition at line 757 of file regc_locale.c.

References pg_wc_tolower().

759 {
760  for (; len > 0; len--, x++, y++)
761  {
762  if ((*x != *y) && (pg_wc_tolower(*x) != pg_wc_tolower(*y)))
763  return 1;
764  }
765  return 0;
766 }
static pg_wchar pg_wc_tolower(pg_wchar c)
static struct cvec* cclass ( struct vars v,
const chr startp,
const chr endp,
int  cases 
)
static

Definition at line 548 of file regc_locale.c.

References addchr(), addrange(), CC_ALNUM, CC_ALPHA, CC_ASCII, CC_BLANK, CC_CNTRL, CC_DIGIT, CC_GRAPH, CC_LOWER, CC_PRINT, CC_PUNCT, CC_SPACE, CC_UPPER, CC_XDIGIT, classNames, ERR, getcvec(), i, NULL, pg_char_and_wchar_strncmp(), pg_ctype_get_cache(), pg_wc_isalnum(), pg_wc_isalpha(), pg_wc_isdigit(), pg_wc_isgraph(), pg_wc_islower(), pg_wc_isprint(), pg_wc_ispunct(), pg_wc_isspace(), pg_wc_isupper(), REG_ECTYPE, and REG_ESPACE.

552 {
553  size_t len;
554  struct cvec *cv = NULL;
555  const char *const * namePtr;
556  int i,
557  index;
558 
559  /*
560  * Map the name to the corresponding enumerated value.
561  */
562  len = endp - startp;
563  index = -1;
564  for (namePtr = classNames, i = 0; *namePtr != NULL; namePtr++, i++)
565  {
566  if (strlen(*namePtr) == len &&
567  pg_char_and_wchar_strncmp(*namePtr, startp, len) == 0)
568  {
569  index = i;
570  break;
571  }
572  }
573  if (index == -1)
574  {
575  ERR(REG_ECTYPE);
576  return NULL;
577  }
578 
579  /*
580  * Remap lower and upper to alpha if the match is case insensitive.
581  */
582 
583  if (cases &&
584  ((enum classes) index == CC_LOWER ||
585  (enum classes) index == CC_UPPER))
586  index = (int) CC_ALPHA;
587 
588  /*
589  * Now compute the character class contents. For classes that are based
590  * on the behavior of a <wctype.h> or <ctype.h> function, we use
591  * pg_ctype_get_cache so that we can cache the results. Other classes
592  * have definitions that are hard-wired here, and for those we just
593  * construct a transient cvec on the fly.
594  *
595  * NB: keep this code in sync with cclass_column_index(), below.
596  */
597 
598  switch ((enum classes) index)
599  {
600  case CC_PRINT:
601  cv = pg_ctype_get_cache(pg_wc_isprint, index);
602  break;
603  case CC_ALNUM:
604  cv = pg_ctype_get_cache(pg_wc_isalnum, index);
605  break;
606  case CC_ALPHA:
607  cv = pg_ctype_get_cache(pg_wc_isalpha, index);
608  break;
609  case CC_ASCII:
610  /* hard-wired meaning */
611  cv = getcvec(v, 0, 1);
612  if (cv)
613  addrange(cv, 0, 0x7f);
614  break;
615  case CC_BLANK:
616  /* hard-wired meaning */
617  cv = getcvec(v, 2, 0);
618  addchr(cv, '\t');
619  addchr(cv, ' ');
620  break;
621  case CC_CNTRL:
622  /* hard-wired meaning */
623  cv = getcvec(v, 0, 2);
624  addrange(cv, 0x0, 0x1f);
625  addrange(cv, 0x7f, 0x9f);
626  break;
627  case CC_DIGIT:
628  cv = pg_ctype_get_cache(pg_wc_isdigit, index);
629  break;
630  case CC_PUNCT:
631  cv = pg_ctype_get_cache(pg_wc_ispunct, index);
632  break;
633  case CC_XDIGIT:
634 
635  /*
636  * It's not clear how to define this in non-western locales, and
637  * even less clear that there's any particular use in trying. So
638  * just hard-wire the meaning.
639  */
640  cv = getcvec(v, 0, 3);
641  if (cv)
642  {
643  addrange(cv, '0', '9');
644  addrange(cv, 'a', 'f');
645  addrange(cv, 'A', 'F');
646  }
647  break;
648  case CC_SPACE:
649  cv = pg_ctype_get_cache(pg_wc_isspace, index);
650  break;
651  case CC_LOWER:
652  cv = pg_ctype_get_cache(pg_wc_islower, index);
653  break;
654  case CC_UPPER:
655  cv = pg_ctype_get_cache(pg_wc_isupper, index);
656  break;
657  case CC_GRAPH:
658  cv = pg_ctype_get_cache(pg_wc_isgraph, index);
659  break;
660  }
661 
662  /* If cv is NULL now, the reason must be "out of memory" */
663  if (cv == NULL)
664  ERR(REG_ESPACE);
665  return cv;
666 }
static int pg_wc_ispunct(pg_wchar c)
#define ERR
Definition: _int.h:146
classes
Definition: regc_locale.c:360
#define REG_ESPACE
Definition: regex.h:149
static void addrange(struct cvec *cv, chr from, chr to)
Definition: regc_cvec.c:90
Definition: type.h:90
static int pg_wc_isalpha(pg_wchar c)
static int pg_wc_isspace(pg_wchar c)
int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n)
Definition: wstrncmp.c:55
static struct cvec * pg_ctype_get_cache(pg_wc_probefunc probefunc, int cclasscode)
static int pg_wc_islower(pg_wchar c)
Definition: regguts.h:256
static int pg_wc_isalnum(pg_wchar c)
static const char *const classNames[NUM_CCLASSES+1]
Definition: regc_locale.c:355
static int pg_wc_isdigit(pg_wchar c)
#define REG_ECTYPE
Definition: regex.h:141
#define NULL
Definition: c.h:229
static int pg_wc_isprint(pg_wchar c)
int i
static void addchr(struct cvec *cv, chr c)
Definition: regc_cvec.c:79
static struct cvec * getcvec(struct vars *v, int nchrs, int nranges)
Definition: regc_cvec.c:112
static int pg_wc_isupper(pg_wchar c)
static int pg_wc_isgraph(pg_wchar c)
static int cclass_column_index ( struct colormap cm,
chr  c 
)
static

Definition at line 672 of file regc_locale.c.

References assert, CC_ALNUM, CC_ALPHA, CC_ASCII, CC_BLANK, CC_CNTRL, CC_DIGIT, CC_GRAPH, CC_LOWER, CC_PRINT, CC_PUNCT, CC_SPACE, CC_UPPER, CC_XDIGIT, colormap::classbits, MAX_SIMPLE_CHR, pg_wc_isalnum(), pg_wc_isalpha(), pg_wc_isdigit(), pg_wc_isgraph(), pg_wc_islower(), pg_wc_isprint(), pg_wc_ispunct(), pg_wc_isspace(), and pg_wc_isupper().

Referenced by pg_reg_getcolor().

673 {
674  int colnum = 0;
675 
676  /* Shouldn't go through all these pushups for simple chrs */
678 
679  /*
680  * Note: we should not see requests to consider cclasses that are not
681  * treated as locale-specific by cclass(), above.
682  */
683  if (cm->classbits[CC_PRINT] && pg_wc_isprint(c))
684  colnum |= cm->classbits[CC_PRINT];
685  if (cm->classbits[CC_ALNUM] && pg_wc_isalnum(c))
686  colnum |= cm->classbits[CC_ALNUM];
687  if (cm->classbits[CC_ALPHA] && pg_wc_isalpha(c))
688  colnum |= cm->classbits[CC_ALPHA];
689  assert(cm->classbits[CC_ASCII] == 0);
690  assert(cm->classbits[CC_BLANK] == 0);
691  assert(cm->classbits[CC_CNTRL] == 0);
692  if (cm->classbits[CC_DIGIT] && pg_wc_isdigit(c))
693  colnum |= cm->classbits[CC_DIGIT];
694  if (cm->classbits[CC_PUNCT] && pg_wc_ispunct(c))
695  colnum |= cm->classbits[CC_PUNCT];
696  assert(cm->classbits[CC_XDIGIT] == 0);
697  if (cm->classbits[CC_SPACE] && pg_wc_isspace(c))
698  colnum |= cm->classbits[CC_SPACE];
699  if (cm->classbits[CC_LOWER] && pg_wc_islower(c))
700  colnum |= cm->classbits[CC_LOWER];
701  if (cm->classbits[CC_UPPER] && pg_wc_isupper(c))
702  colnum |= cm->classbits[CC_UPPER];
703  if (cm->classbits[CC_GRAPH] && pg_wc_isgraph(c))
704  colnum |= cm->classbits[CC_GRAPH];
705 
706  return colnum;
707 }
static int pg_wc_ispunct(pg_wchar c)
int classbits[NUM_CCLASSES]
Definition: regguts.h:221
static int pg_wc_isalpha(pg_wchar c)
static int pg_wc_isspace(pg_wchar c)
char * c
#define assert(TEST)
Definition: imath.c:37
static int pg_wc_islower(pg_wchar c)
static int pg_wc_isalnum(pg_wchar c)
static int pg_wc_isdigit(pg_wchar c)
static int pg_wc_isprint(pg_wchar c)
static int pg_wc_isupper(pg_wchar c)
static int pg_wc_isgraph(pg_wchar c)
#define MAX_SIMPLE_CHR
Definition: regcustom.h:97
static int cmp ( const chr x,
const chr y,
size_t  len 
)
static

Definition at line 742 of file regc_locale.c.

References VS.

Referenced by addToArray(), adjacent_cmp_bounds(), adjacent_inner_consistent(), avlInsertNode(), bit_cmp(), bitposition(), bounds_adjacent(), bpchar_larger(), bpchar_smaller(), bpcharcmp(), bpcharge(), bpchargt(), bpcharle(), bpcharlt(), byteacmp(), byteage(), byteagt(), byteale(), bytealt(), calc_word_similarity(), collectMatchBitmap(), comp_ptrgm(), findeq(), GetVariable(), gin_btree_compare_prefix(), gin_cmp_prefix(), gin_cmp_tslexeme(), ginMergeItemPointers(), IndexNextWithReorder(), invariant_geq_offset(), invariant_leq_nontarget_offset(), invariant_leq_offset(), ln_var(), make_row_comparison_op(), make_row_distinct_op(), matchPartialInPendingList(), mcelem_array_contain_overlap_selec(), mcelem_array_contained_selec(), med3(), mp_int_add(), mp_int_compare(), mp_int_compare_value(), mp_int_div(), mp_int_sub(), mp_int_to_string(), oidvectoreq(), oidvectorge(), oidvectorgt(), oidvectorle(), oidvectorlt(), oidvectorne(), pg_qsort(), qsort_arg(), range_cmp(), range_contains_elem_internal(), range_ge(), range_gt(), range_le(), range_lt(), range_serialize(), rb_find(), rb_insert(), rbound_bsearch(), seg_different(), seg_ge(), seg_gt(), seg_le(), seg_lt(), seg_same(), set_cheapest(), SetVariable(), SetVariableHooks(), sift_up(), spg_range_quad_inner_consistent(), transformAExprIn(), tsCompareString(), tsvector_bsearch(), and tsvector_concat().

744 {
745  return memcmp(VS(x), VS(y), len * sizeof(chr));
746 }
pg_wchar chr
Definition: regcustom.h:68
#define VS(x)
Definition: regguts.h:61
static struct cvec* eclass ( struct vars v,
chr  c,
int  cases 
)
static

Definition at line 508 of file regc_locale.c.

References addchr(), allcases(), assert, vars::cflags, CHR, getcvec(), NULL, and REG_FAKE.

Referenced by make_canonical_pathkey(), make_pathkey_from_sortinfo(), and print_pathkeys().

512 {
513  struct cvec *cv;
514 
515  /* crude fake equivalence class for testing */
516  if ((v->cflags & REG_FAKE) && c == 'x')
517  {
518  cv = getcvec(v, 4, 0);
519  addchr(cv, CHR('x'));
520  addchr(cv, CHR('y'));
521  if (cases)
522  {
523  addchr(cv, CHR('X'));
524  addchr(cv, CHR('Y'));
525  }
526  return cv;
527  }
528 
529  /* otherwise, none */
530  if (cases)
531  return allcases(v, c);
532  cv = getcvec(v, 1, 0);
533  assert(cv != NULL);
534  addchr(cv, c);
535  return cv;
536 }
char * c
#define assert(TEST)
Definition: imath.c:37
#define REG_FAKE
Definition: regex.h:116
Definition: regguts.h:256
static struct cvec * allcases(struct vars *v, chr c)
Definition: regc_locale.c:716
#define NULL
Definition: c.h:229
int cflags
Definition: regcomp.c:232
#define CHR(c)
Definition: regcustom.h:71
static void addchr(struct cvec *cv, chr c)
Definition: regc_cvec.c:79
static struct cvec * getcvec(struct vars *v, int nchrs, int nranges)
Definition: regc_cvec.c:112
static chr element ( struct vars v,
const chr startp,
const chr endp 
)
static

Definition at line 380 of file regc_locale.c.

References assert, CHR, cnames, cname::code, ERR, cname::name, NOTE, NULL, pg_char_and_wchar_strncmp(), REG_ECOLLATE, and REG_ULOCALE.

Referenced by chrnamed(), ecpg_store_input(), eval_const_expressions_mutator(), json_array_element(), json_array_element_text(), jsonb_array_element(), jsonb_array_element_text(), populate_array_element(), transformArrayExpr(), transformCreateSchemaStmt(), and transformCreateStmt().

383 {
384  const struct cname *cn;
385  size_t len;
386 
387  /* generic: one-chr names stand for themselves */
388  assert(startp < endp);
389  len = endp - startp;
390  if (len == 1)
391  return *startp;
392 
393  NOTE(REG_ULOCALE);
394 
395  /* search table */
396  for (cn = cnames; cn->name != NULL; cn++)
397  {
398  if (strlen(cn->name) == len &&
399  pg_char_and_wchar_strncmp(cn->name, startp, len) == 0)
400  {
401  break; /* NOTE BREAK OUT */
402  }
403  }
404  if (cn->name != NULL)
405  return CHR(cn->code);
406 
407  /* couldn't find it */
408  ERR(REG_ECOLLATE);
409  return 0;
410 }
#define ERR
Definition: _int.h:146
const char * name
Definition: regc_locale.c:57
#define REG_ULOCALE
Definition: regex.h:70
const char code
Definition: regc_locale.c:58
int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n)
Definition: wstrncmp.c:55
#define assert(TEST)
Definition: imath.c:37
#define REG_ECOLLATE
Definition: regex.h:140
#define NULL
Definition: c.h:229
#define NOTE(b)
Definition: regcomp.c:270
static const struct cname cnames[]
#define CHR(c)
Definition: regcustom.h:71
static struct cvec* range ( struct vars v,
chr  a,
chr  b,
int  cases 
)
static

Definition at line 416 of file regc_locale.c.

References addchr(), addrange(), before(), CANCEL_REQUESTED, cvec::chrspace, ERR, getcvec(), cvec::nchrs, NOERRN, NULL, pg_wc_tolower(), pg_wc_toupper(), vars::re, REG_CANCEL, REG_ERANGE, and REG_ETOOBIG.

Referenced by AdjustIntervalForTypmod(), chrnamed(), codepoint_range_cmp(), compute_range_stats(), DecodeInterval(), g_box_consider_split(), interval_in(), make_range(), pg_to_ascii(), range_constructor2(), range_constructor3(), range_gist_class_split(), range_gist_double_sorting_split(), range_gist_fallback_split(), range_gist_picksplit(), range_gist_single_sorting_split(), range_in(), range_out(), range_recv(), range_send(), range_serialize(), spg_range_quad_inner_consistent(), spg_range_quad_picksplit(), TQExamineRange(), and TQRemapRange().

420 {
421  int nchrs;
422  struct cvec *cv;
423  chr c,
424  cc;
425 
426  if (a != b && !before(a, b))
427  {
428  ERR(REG_ERANGE);
429  return NULL;
430  }
431 
432  if (!cases)
433  { /* easy version */
434  cv = getcvec(v, 0, 1);
435  NOERRN();
436  addrange(cv, a, b);
437  return cv;
438  }
439 
440  /*
441  * When case-independent, it's hard to decide when cvec ranges are usable,
442  * so for now at least, we won't try. We use a range for the originally
443  * specified chrs and then add on any case-equivalents that are outside
444  * that range as individual chrs.
445  *
446  * To ensure sane behavior if someone specifies a very large range, limit
447  * the allocation size to 100000 chrs (arbitrary) and check for overrun
448  * inside the loop below.
449  */
450  nchrs = b - a + 1;
451  if (nchrs <= 0 || nchrs > 100000)
452  nchrs = 100000;
453 
454  cv = getcvec(v, nchrs, 1);
455  NOERRN();
456  addrange(cv, a, b);
457 
458  for (c = a; c <= b; c++)
459  {
460  cc = pg_wc_tolower(c);
461  if (cc != c &&
462  (before(cc, a) || before(b, cc)))
463  {
464  if (cv->nchrs >= cv->chrspace)
465  {
466  ERR(REG_ETOOBIG);
467  return NULL;
468  }
469  addchr(cv, cc);
470  }
471  cc = pg_wc_toupper(c);
472  if (cc != c &&
473  (before(cc, a) || before(b, cc)))
474  {
475  if (cv->nchrs >= cv->chrspace)
476  {
477  ERR(REG_ETOOBIG);
478  return NULL;
479  }
480  addchr(cv, cc);
481  }
482  if (CANCEL_REQUESTED(v->re))
483  {
484  ERR(REG_CANCEL);
485  return NULL;
486  }
487  }
488 
489  return cv;
490 }
#define ERR
Definition: _int.h:146
#define NOERRN()
Definition: regcomp.c:267
static void addrange(struct cvec *cv, chr from, chr to)
Definition: regc_cvec.c:90
static pg_wchar pg_wc_toupper(pg_wchar c)
int chrspace
Definition: regguts.h:259
static int before(chr x, chr y)
Definition: regc_locale.c:496
pg_wchar chr
Definition: regcustom.h:68
int nchrs
Definition: regguts.h:258
regex_t * re
Definition: regcomp.c:226
char * c
Definition: regguts.h:256
static pg_wchar pg_wc_tolower(pg_wchar c)
#define NULL
Definition: c.h:229
#define REG_ERANGE
Definition: regex.h:148
#define REG_ETOOBIG
Definition: regex.h:155
#define CANCEL_REQUESTED(re)
Definition: regguts.h:452
static void addchr(struct cvec *cv, chr c)
Definition: regc_cvec.c:79
static struct cvec * getcvec(struct vars *v, int nchrs, int nranges)
Definition: regc_cvec.c:112
#define REG_CANCEL
Definition: regex.h:157

Variable Documentation

const char* const classNames[NUM_CCLASSES+1]
static
Initial value:
= {
"alnum", "alpha", "ascii", "blank", "cntrl", "digit", "graph",
"lower", "print", "punct", "space", "upper", "xdigit", NULL
}
#define NULL
Definition: c.h:229

Definition at line 355 of file regc_locale.c.

Referenced by cclass().

const struct cname cnames[]
static

Referenced by element(), and extractRemainingColumns().