PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_locale.h
Go to the documentation of this file.
1/*-----------------------------------------------------------------------
2 *
3 * PostgreSQL locale utilities
4 *
5 * src/include/utils/pg_locale.h
6 *
7 * Copyright (c) 2002-2025, PostgreSQL Global Development Group
8 *
9 *-----------------------------------------------------------------------
10 */
11
12#ifndef _PG_LOCALE_
13#define _PG_LOCALE_
14
15#ifdef USE_ICU
16#include <unicode/ucol.h>
17#endif
18
19/* use for libc locale names */
20#define LOCALE_NAME_BUFLEN 128
21
22/* GUC settings */
23extern PGDLLIMPORT char *locale_messages;
24extern PGDLLIMPORT char *locale_monetary;
25extern PGDLLIMPORT char *locale_numeric;
26extern PGDLLIMPORT char *locale_time;
28
29/* lc_time localization cache */
31extern PGDLLIMPORT char *localized_full_days[];
34
35/* is the databases's LC_CTYPE the C locale? */
37
38extern bool check_locale(int category, const char *locale, char **canonname);
39extern char *pg_perm_setlocale(int category, const char *locale);
40
41/*
42 * Return the POSIX lconv struct (contains number/money formatting
43 * information) with locale information for all categories.
44 */
45extern struct lconv *PGLC_localeconv(void);
46
47extern void cache_locale_time(void);
48
49
50/*
51 * We use a discriminated union to hold either a locale_t or an ICU collator.
52 * pg_locale_t is occasionally checked for truth, so make it a pointer.
53 *
54 * Also, hold two flags: whether the collation's LC_COLLATE or LC_CTYPE is C
55 * (or POSIX), so we can optimize a few code paths in various places. For the
56 * built-in C and POSIX collations, we can know that without even doing a
57 * cache lookup, but we want to support aliases for C/POSIX too. For the
58 * "default" collation, there are separate static cache variables, since
59 * consulting the pg_collation catalog doesn't tell us what we need.
60 *
61 * Note that some code relies on the flags not reporting false negatives
62 * (that is, saying it's not C when it is). For example, char2wchar()
63 * could fail if the locale is C, so str_tolower() shouldn't call it
64 * in that case.
65 */
67{
73 union
74 {
75 struct
76 {
77 const char *locale;
80#ifdef USE_ICU
81 struct
82 {
83 const char *locale;
84 UCollator *ucol;
85 } icu;
86#endif
88};
89
91
92extern void init_database_collation(void);
94
95extern char *get_collation_actual_version(char collprovider, const char *collcollate);
96extern size_t pg_strlower(char *dest, size_t destsize,
97 const char *src, ssize_t srclen,
99extern size_t pg_strtitle(char *dest, size_t destsize,
100 const char *src, ssize_t srclen,
102extern size_t pg_strupper(char *dest, size_t destsize,
103 const char *src, ssize_t srclen,
105extern int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale);
106extern int pg_strncoll(const char *arg1, ssize_t len1,
107 const char *arg2, ssize_t len2, pg_locale_t locale);
109extern size_t pg_strxfrm(char *dest, const char *src, size_t destsize,
111extern size_t pg_strnxfrm(char *dest, size_t destsize, const char *src,
112 ssize_t srclen, pg_locale_t locale);
114extern size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,
116extern size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
117 ssize_t srclen, pg_locale_t locale);
118
119extern int builtin_locale_encoding(const char *locale);
120extern const char *builtin_validate_locale(int encoding, const char *locale);
121extern void icu_validate_locale(const char *loc_str);
122extern char *icu_language_tag(const char *loc_str, int elevel);
123
124/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
125extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
127extern size_t char2wchar(wchar_t *to, size_t tolen,
128 const char *from, size_t fromlen, pg_locale_t locale);
129
130#endif /* _PG_LOCALE_ */
#define PGDLLIMPORT
Definition: c.h:1274
Oid collid
static char * locale
Definition: initdb.c:140
int32 encoding
Definition: pg_database.h:41
size_t pg_strupper(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
Definition: pg_locale.c:1531
struct pg_locale_struct * pg_locale_t
Definition: pg_locale.h:90
size_t pg_strtitle(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
Definition: pg_locale.c:1512
PGDLLIMPORT int icu_validation_level
Definition: pg_locale.c:146
void cache_locale_time(void)
Definition: pg_locale.c:839
size_t pg_strnxfrm(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
Definition: pg_locale.c:1680
bool pg_strxfrm_enabled(pg_locale_t locale)
Definition: pg_locale.c:1620
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
void icu_validate_locale(const char *loc_str)
Definition: pg_locale.c:1884
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1390
PGDLLIMPORT char * locale_time
Definition: pg_locale.c:144
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1341
PGDLLIMPORT char * localized_abbrev_days[]
Definition: pg_locale.c:155
int builtin_locale_encoding(const char *locale)
Definition: pg_locale.c:1767
size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
Definition: pg_locale.c:1747
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:223
PGDLLIMPORT char * locale_numeric
Definition: pg_locale.c:143
PGDLLIMPORT char * localized_full_days[]
Definition: pg_locale.c:156
struct lconv * PGLC_localeconv(void)
Definition: pg_locale.c:557
int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
Definition: pg_locale.c:1555
PGDLLIMPORT char * localized_full_months[]
Definition: pg_locale.c:158
PGDLLIMPORT char * localized_abbrev_months[]
Definition: pg_locale.c:157
PGDLLIMPORT char * locale_monetary
Definition: pg_locale.c:142
bool pg_strxfrm_prefix_enabled(pg_locale_t locale)
Definition: pg_locale.c:1703
char * icu_language_tag(const char *loc_str, int elevel)
Definition: pg_locale.c:1826
PGDLLIMPORT char * locale_messages
Definition: pg_locale.c:141
int pg_strncoll(const char *arg1, ssize_t len1, const char *arg2, ssize_t len2, pg_locale_t locale)
Definition: pg_locale.c:1587
void init_database_collation(void)
Definition: pg_locale.c:1299
PGDLLIMPORT bool database_ctype_is_c
Definition: pg_locale.c:161
size_t pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
Definition: pg_locale.c:1643
const char * builtin_validate_locale(int encoding, const char *locale)
Definition: pg_locale.c:1788
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:326
size_t pg_strlower(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
Definition: pg_locale.c:1493
size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize, pg_locale_t locale)
Definition: pg_locale.c:1722
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
unsigned int Oid
Definition: postgres_ext.h:31
union pg_locale_struct::@157 info
locale_t lt
Definition: pg_locale.h:79
const char * locale
Definition: pg_locale.h:77
bool deterministic
Definition: pg_locale.h:69
struct pg_locale_struct::@157::@158 builtin
#define locale_t
Definition: win32_port.h:442