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

Go to the source code of this file.

Functions

char * downcase_truncate_identifier (const char *ident, int len, bool warn)
 
char * downcase_identifier (const char *ident, int len, bool warn, bool truncate)
 
void truncate_identifier (char *ident, int len, bool warn)
 
bool scanner_isspace (char ch)
 

Function Documentation

◆ downcase_identifier()

char* downcase_identifier ( const char *  ident,
int  len,
bool  warn,
bool  truncate 
)

Definition at line 46 of file scansup.c.

47 {
48  char *result;
49  int i;
50  bool enc_is_single_byte;
51 
52  result = palloc(len + 1);
53  enc_is_single_byte = pg_database_encoding_max_length() == 1;
54 
55  /*
56  * SQL99 specifies Unicode-aware case normalization, which we don't yet
57  * have the infrastructure for. Instead we use tolower() to provide a
58  * locale-aware translation. However, there are some locales where this
59  * is not right either (eg, Turkish may do strange things with 'i' and
60  * 'I'). Our current compromise is to use tolower() for characters with
61  * the high bit set, as long as they aren't part of a multi-byte
62  * character, and use an ASCII-only downcasing for 7-bit characters.
63  */
64  for (i = 0; i < len; i++)
65  {
66  unsigned char ch = (unsigned char) ident[i];
67 
68  if (ch >= 'A' && ch <= 'Z')
69  ch += 'a' - 'A';
70  else if (enc_is_single_byte && IS_HIGHBIT_SET(ch) && isupper(ch))
71  ch = tolower(ch);
72  result[i] = (char) ch;
73  }
74  result[i] = '\0';
75 
76  if (i >= NAMEDATALEN && truncate)
77  truncate_identifier(result, i, warn);
78 
79  return result;
80 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1142
#define ident
Definition: indent_codes.h:47
int i
Definition: isn.c:73
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1546
void * palloc(Size size)
Definition: mcxt.c:1304
#define NAMEDATALEN
const void size_t len
void truncate_identifier(char *ident, int len, bool warn)
Definition: scansup.c:93
warn
Definition: strftime.c:110

References i, ident, IS_HIGHBIT_SET, len, NAMEDATALEN, palloc(), pg_database_encoding_max_length(), and truncate_identifier().

Referenced by downcase_truncate_identifier(), and parse_ident().

◆ downcase_truncate_identifier()

char* downcase_truncate_identifier ( const char *  ident,
int  len,
bool  warn 
)

◆ scanner_isspace()

bool scanner_isspace ( char  ch)

Definition at line 117 of file scansup.c.

118 {
119  /* This must match scan.l's list of {space} characters */
120  if (ch == ' ' ||
121  ch == '\t' ||
122  ch == '\n' ||
123  ch == '\r' ||
124  ch == '\v' ||
125  ch == '\f')
126  return true;
127  return false;
128 }

Referenced by array_in(), array_out(), check_uescapechar(), CleanQuerytext(), CreateSchemaCommand(), from_char_seq_search(), get_val(), parse_hstore(), parse_ident(), parseNameAndArgTypes(), ReadArrayDimensions(), ReadArrayToken(), SplitDirectoriesString(), SplitGUCList(), and SplitIdentifierString().

◆ truncate_identifier()

void truncate_identifier ( char *  ident,
int  len,
bool  warn 
)

Definition at line 93 of file scansup.c.

94 {
95  if (len >= NAMEDATALEN)
96  {
98  if (warn)
100  (errcode(ERRCODE_NAME_TOO_LONG),
101  errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
102  ident, len, ident)));
103  ident[len] = '\0';
104  }
105 }
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:149
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:1083

References ereport, errcode(), errmsg(), ident, len, NAMEDATALEN, NOTICE, and pg_mbcliplen().

Referenced by base_yylex(), createNewConnection(), deleteConnection(), downcase_identifier(), get_connect_string(), getConnectionByName(), parse_and_validate_value(), and SplitIdentifierString().