PostgreSQL Source Code  git master
keywords.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ScanKeyword
 

Macros

#define UNRESERVED_KEYWORD   0
 
#define COL_NAME_KEYWORD   1
 
#define TYPE_FUNC_NAME_KEYWORD   2
 
#define RESERVED_KEYWORD   3
 

Typedefs

typedef struct ScanKeyword ScanKeyword
 

Functions

const ScanKeywordScanKeywordLookup (const char *text, const ScanKeyword *keywords, int num_keywords)
 

Variables

PGDLLIMPORT const ScanKeyword ScanKeywords []
 
PGDLLIMPORT const int NumScanKeywords
 

Macro Definition Documentation

◆ COL_NAME_KEYWORD

#define COL_NAME_KEYWORD   1

Definition at line 19 of file keywords.h.

Referenced by pg_get_keywords().

◆ RESERVED_KEYWORD

#define RESERVED_KEYWORD   3

Definition at line 21 of file keywords.h.

Referenced by pg_get_keywords().

◆ TYPE_FUNC_NAME_KEYWORD

#define TYPE_FUNC_NAME_KEYWORD   2

Definition at line 20 of file keywords.h.

Referenced by pg_get_keywords().

◆ UNRESERVED_KEYWORD

#define UNRESERVED_KEYWORD   0

Definition at line 18 of file keywords.h.

Referenced by fmtId(), pg_get_keywords(), and quote_identifier().

Typedef Documentation

◆ ScanKeyword

Function Documentation

◆ ScanKeywordLookup()

const ScanKeyword* ScanKeywordLookup ( const char *  text,
const ScanKeyword keywords,
int  num_keywords 
)

Definition at line 64 of file keywords.c.

References difference(), i, ScanKeyword::name, NAMEDATALEN, and word().

Referenced by fmtId(), plpgsql_yylex(), quote_identifier(), and ScanECPGKeywordLookup().

67 {
68  int len,
69  i;
70  char word[NAMEDATALEN];
71  const ScanKeyword *low;
72  const ScanKeyword *high;
73 
74  len = strlen(text);
75  /* We assume all keywords are shorter than NAMEDATALEN. */
76  if (len >= NAMEDATALEN)
77  return NULL;
78 
79  /*
80  * Apply an ASCII-only downcasing. We must not use tolower() since it may
81  * produce the wrong translation in some locales (eg, Turkish).
82  */
83  for (i = 0; i < len; i++)
84  {
85  char ch = text[i];
86 
87  if (ch >= 'A' && ch <= 'Z')
88  ch += 'a' - 'A';
89  word[i] = ch;
90  }
91  word[len] = '\0';
92 
93  /*
94  * Now do a binary search using plain strcmp() comparison.
95  */
96  low = keywords;
97  high = keywords + (num_keywords - 1);
98  while (low <= high)
99  {
100  const ScanKeyword *middle;
101  int difference;
102 
103  middle = low + (high - low) / 2;
104  difference = strcmp(middle->name, word);
105  if (difference == 0)
106  return middle;
107  else if (difference < 0)
108  low = middle + 1;
109  else
110  high = middle - 1;
111  }
112 
113  return NULL;
114 }
#define NAMEDATALEN
const char * name
Definition: keywords.h:26
Datum difference(PG_FUNCTION_ARGS)
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1243
int i
Definition: c.h:487

Variable Documentation

◆ NumScanKeywords

PGDLLIMPORT const int NumScanKeywords

◆ ScanKeywords

PGDLLIMPORT const ScanKeyword ScanKeywords[]