PostgreSQL Source Code  git master
scansup.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "mb/pg_wchar.h"
#include "parser/scansup.h"
Include dependency graph for scansup.c:

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.

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

Referenced by downcase_truncate_identifier(), and parse_ident().

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 NAMEDATALEN
void truncate_identifier(char *ident, int len, bool warn)
Definition: scansup.c:93
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1152
warn
Definition: strftime.c:109
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1436
void * palloc(Size size)
Definition: mcxt.c:950
int i

◆ downcase_truncate_identifier()

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

Definition at line 37 of file scansup.c.

References downcase_identifier().

Referenced by find_provider(), interval_part(), interval_trunc(), parse_sane_timezone(), SplitIdentifierString(), time_part(), timestamp_part(), timestamp_trunc(), timestamp_zone(), timestamptz_part(), timestamptz_trunc_internal(), timestamptz_trunc_zone(), timestamptz_zone(), timetz_part(), and timetz_zone().

38 {
39  return downcase_identifier(ident, len, warn, true);
40 }
char * downcase_identifier(const char *ident, int len, bool warn, bool truncate)
Definition: scansup.c:46
warn
Definition: strftime.c:109

◆ scanner_isspace()

bool scanner_isspace ( char  ch)

Definition at line 117 of file scansup.c.

Referenced by check_uescapechar(), from_char_seq_search(), parse_ident(), parseNameAndArgTypes(), pgss_store(), SplitDirectoriesString(), SplitGUCList(), and SplitIdentifierString().

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 == '\f')
125  return true;
126  return false;
127 }

◆ truncate_identifier()

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

Definition at line 93 of file scansup.c.

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

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

94 {
95  if (len >= NAMEDATALEN)
96  {
97  len = pg_mbcliplen(ident, len, NAMEDATALEN - 1);
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:691
#define NAMEDATALEN
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:967
#define ereport(elevel,...)
Definition: elog.h:155
#define NOTICE
Definition: elog.h:37
warn
Definition: strftime.c:109
int errmsg(const char *fmt,...)
Definition: elog.c:902