1/*-------------------------------------------------------------------------
4 * Portable SQL-like case-independent comparisons and conversions.
6 * SQL99 specifies Unicode-aware case normalization, which we don't yet
7 * have the infrastructure for. Instead we use tolower() to provide a
8 * locale-aware translation. However, there are some locales where this
9 * is not right either (eg, Turkish may do strange things with 'i' and
10 * 'I'). Our current compromise is to use tolower() for characters with
11 * the high bit set, and use an ASCII-only downcasing for 7-bit
14 * NB: this code should match downcase_truncate_identifier() in scansup.c.
16 * We also provide strict ASCII-only case conversion functions, which can
17 * be used to implement C/POSIX case folding semantics no matter what the
18 * C library thinks the locale is.
21 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
23 * src/port/pgstrcasecmp.c
25 *-------------------------------------------------------------------------
33 * Case-independent comparison of two null-terminated strings.
40 unsigned char ch1 = (
unsigned char) *
s1++;
41 unsigned char ch2 = (
unsigned char) *
s2++;
45 if (ch1 >=
'A' && ch1 <=
'Z')
50 if (ch2 >=
'A' && ch2 <=
'Z')
56 return (
int) ch1 - (int) ch2;
65 * Case-independent comparison of two not-necessarily-null-terminated strings.
66 * At most n bytes will be examined from each string.
73 unsigned char ch1 = (
unsigned char) *
s1++;
74 unsigned char ch2 = (
unsigned char) *
s2++;
78 if (ch1 >=
'A' && ch1 <=
'Z')
83 if (ch2 >=
'A' && ch2 <=
'Z')
89 return (
int) ch1 - (int) ch2;
98 * Fold a character to upper case.
100 * Unlike some versions of toupper(), this is safe to apply to characters
101 * that aren't lower case letters. Note however that the whole thing is
102 * a bit bogus for multibyte character sets.
107 if (ch >=
'a' && ch <=
'z')
115 * Fold a character to lower case.
117 * Unlike some versions of tolower(), this is safe to apply to characters
118 * that aren't upper case letters. Note however that the whole thing is
119 * a bit bogus for multibyte character sets.
124 if (ch >=
'A' && ch <=
'Z')
132 * Fold a character to upper case, following C/POSIX locale rules.
137 if (ch >=
'a' && ch <=
'z')
143 * Fold a character to lower case, following C/POSIX locale rules.
148 if (ch >=
'A' && ch <=
'Z')
#define IS_HIGHBIT_SET(ch)
int pg_strcasecmp(const char *s1, const char *s2)
unsigned char pg_toupper(unsigned char ch)
unsigned char pg_tolower(unsigned char ch)
unsigned char pg_ascii_tolower(unsigned char ch)
unsigned char pg_ascii_toupper(unsigned char ch)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)