1/*-------------------------------------------------------------------------
4 * Key word lookup for PostgreSQL
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 * src/common/kwlookup.c
14 *-------------------------------------------------------------------------
22 * ScanKeywordLookup - see if a given word is a keyword
24 * The list of keywords to be matched against is passed as a ScanKeywordList.
26 * Returns the keyword number (0..N-1) of the keyword, or -1 if no match.
27 * Callers typically use the keyword number to index into information
28 * arrays, but that is no concern of this code.
30 * The match is done case-insensitively. Note that we deliberately use a
31 * dumbed-down case conversion that will only translate 'A'-'Z' into 'a'-'z',
32 * even if we are in a locale where tolower() would produce more or different
33 * translations. This is to conform to the SQL99 spec, which says that
34 * keywords are to be matched in this way even though non-keyword identifiers
35 * receive a different case-normalization mapping.
46 * Reject immediately if too long to be any keyword. This saves useless
47 * hashing and downcasing work on long strings.
54 * Compute the hash function. We assume it was generated to produce
55 * case-insensitive results. Since it's a perfect hash, we need only
56 * match to the specific keyword it identifies.
60 /* An out-of-range result implies no match */
61 if (h < 0 || h >=
keywords->num_keywords)
65 * Compare character-by-character to see if we have a match, applying an
66 * ASCII-only downcasing to the input characters. We must not use
67 * tolower() since it may produce the wrong translation in some locales
75 if (ch >=
'A' && ch <=
'Z')
static const JsonPathKeyword keywords[]
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
static const char * GetScanKeyword(int n, const ScanKeywordList *keywords)