1/*-------------------------------------------------------------------------
4 * scanner support routines used by the core lexer
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/parser/scansup.c
13 *-------------------------------------------------------------------------
24 * downcase_truncate_identifier() --- do appropriate downcasing and
25 * truncation of an unquoted identifier. Optionally warn of truncation.
27 * Returns a palloc'd string containing the adjusted identifier.
29 * Note: in some usages the passed string is not null-terminated.
31 * Note: the API of this function is designed to allow for downcasing
32 * transformations that increase the string length, but we don't yet
33 * support that. If you want to implement it, you'll need to fix
34 * SplitIdentifierString() in utils/adt/varlena.c.
43 * a workhorse for downcase_truncate_identifier
50 bool enc_is_single_byte;
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.
66 unsigned char ch = (
unsigned char)
ident[
i];
68 if (ch >=
'A' && ch <=
'Z')
72 result[
i] = (char) ch;
84 * truncate_identifier() --- truncate an identifier to NAMEDATALEN-1 bytes.
86 * The given string is modified in-place, if necessary. A warning is
87 * issued if requested.
89 * We require the caller to pass in the string length since this saves a
90 * strlen() call in some common usages.
100 (
errcode(ERRCODE_NAME_TOO_LONG),
101 errmsg(
"identifier \"%s\" will be truncated to \"%.*s\"",
108 * scanner_isspace() --- return true if flex scanner considers char whitespace
110 * This should be used instead of the potentially locale-dependent isspace()
111 * function when it's important to match the lexer's behavior.
113 * In principle we might need similar functions for isalnum etc, but for the
114 * moment only isspace seems needed.
119 /* This must match scan.l's list of {space} characters */
#define IS_HIGHBIT_SET(ch)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int pg_mbcliplen(const char *mbstr, int len, int limit)
int pg_database_encoding_max_length(void)
char * downcase_identifier(const char *ident, int len, bool warn, bool truncate)
void truncate_identifier(char *ident, int len, bool warn)
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
bool scanner_isspace(char ch)