PostgreSQL Source Code  git master
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-2024, PostgreSQL Global Development Group
8  *
9  *-----------------------------------------------------------------------
10  */
11 
12 #ifndef _PG_LOCALE_
13 #define _PG_LOCALE_
14 
15 #if defined(LOCALE_T_IN_XLOCALE) || defined(WCSTOMBS_L_IN_XLOCALE)
16 #include <xlocale.h>
17 #endif
18 #ifdef USE_ICU
19 #include <unicode/ucol.h>
20 #endif
21 
22 #ifdef USE_ICU
23 /*
24  * ucol_strcollUTF8() was introduced in ICU 50, but it is buggy before ICU 53.
25  * (see
26  * <https://www.postgresql.org/message-id/flat/f1438ec6-22aa-4029-9a3b-26f79d330e72%40manitou-mail.org>)
27  */
28 #if U_ICU_VERSION_MAJOR_NUM >= 53
29 #define HAVE_UCOL_STRCOLLUTF8 1
30 #else
31 #undef HAVE_UCOL_STRCOLLUTF8
32 #endif
33 #endif
34 
35 /* use for libc locale names */
36 #define LOCALE_NAME_BUFLEN 128
37 
38 /* GUC settings */
39 extern PGDLLIMPORT char *locale_messages;
40 extern PGDLLIMPORT char *locale_monetary;
41 extern PGDLLIMPORT char *locale_numeric;
42 extern PGDLLIMPORT char *locale_time;
44 
45 /* lc_time localization cache */
46 extern PGDLLIMPORT char *localized_abbrev_days[];
47 extern PGDLLIMPORT char *localized_full_days[];
49 extern PGDLLIMPORT char *localized_full_months[];
50 
51 /* is the databases's LC_CTYPE the C locale? */
53 
54 extern bool check_locale(int category, const char *locale, char **canonname);
55 extern char *pg_perm_setlocale(int category, const char *locale);
56 
57 extern bool lc_collate_is_c(Oid collation);
58 extern bool lc_ctype_is_c(Oid collation);
59 
60 /*
61  * Return the POSIX lconv struct (contains number/money formatting
62  * information) with locale information for all categories.
63  */
64 extern struct lconv *PGLC_localeconv(void);
65 
66 extern void cache_locale_time(void);
67 
68 
69 /*
70  * We use a discriminated union to hold either a locale_t or an ICU collator.
71  * pg_locale_t is occasionally checked for truth, so make it a pointer.
72  */
74 {
75  char provider;
77  union
78  {
79  struct
80  {
81  const char *locale;
84 #ifdef USE_ICU
85  struct
86  {
87  const char *locale;
88  UCollator *ucol;
89  } icu;
90 #endif
91  } info;
92 };
93 
94 typedef struct pg_locale_struct *pg_locale_t;
95 
97 
98 extern void make_icu_collator(const char *iculocstr,
99  const char *icurules,
100  struct pg_locale_struct *resultp);
101 
104 
105 extern char *get_collation_actual_version(char collprovider, const char *collcollate);
106 extern int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale);
107 extern int pg_strncoll(const char *arg1, size_t len1,
108  const char *arg2, size_t len2, pg_locale_t locale);
110 extern size_t pg_strxfrm(char *dest, const char *src, size_t destsize,
112 extern size_t pg_strnxfrm(char *dest, size_t destsize, const char *src,
113  size_t srclen, pg_locale_t locale);
115 extern size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,
117 extern size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
118  size_t srclen, pg_locale_t locale);
119 
120 extern int builtin_locale_encoding(const char *locale);
121 extern const char *builtin_validate_locale(int encoding, const char *locale);
122 extern void icu_validate_locale(const char *loc_str);
123 extern char *icu_language_tag(const char *loc_str, int elevel);
124 
125 #ifdef USE_ICU
126 extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
127 extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar);
128 #endif
129 
130 /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
131 extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
133 extern size_t char2wchar(wchar_t *to, size_t tolen,
134  const char *from, size_t fromlen, pg_locale_t locale);
135 
136 #endif /* _PG_LOCALE_ */
#define PGDLLIMPORT
Definition: c.h:1316
Oid collid
static char * locale
Definition: initdb.c:140
int32 encoding
Definition: pg_database.h:41
struct pg_locale_struct * pg_locale_t
Definition: pg_locale.h:94
size_t pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition: pg_locale.c:2417
PGDLLIMPORT int icu_validation_level
Definition: pg_locale.c:102
void cache_locale_time(void)
Definition: pg_locale.c:806
bool pg_strxfrm_enabled(pg_locale_t locale)
Definition: pg_locale.c:2349
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
Definition: pg_locale.c:3059
struct lconv * PGLC_localeconv(void)
Definition: pg_locale.c:524
int pg_strncoll(const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
Definition: pg_locale.c:2133
void make_icu_collator(const char *iculocstr, const char *icurules, struct pg_locale_struct *resultp)
Definition: pg_locale.c:1449
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1317
void icu_validate_locale(const char *loc_str)
Definition: pg_locale.c:2978
PGDLLIMPORT char * locale_time
Definition: pg_locale.c:100
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1551
PGDLLIMPORT char * localized_abbrev_days[]
Definition: pg_locale.c:111
int builtin_locale_encoding(const char *locale)
Definition: pg_locale.c:2524
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1384
bool pg_locale_deterministic(pg_locale_t locale)
Definition: pg_locale.c:1531
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1729
PGDLLIMPORT char * locale_numeric
Definition: pg_locale.c:99
PGDLLIMPORT char * localized_full_days[]
Definition: pg_locale.c:112
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:212
char * icu_language_tag(const char *loc_str, int elevel)
Definition: pg_locale.c:2921
int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
Definition: pg_locale.c:2098
PGDLLIMPORT char * localized_full_months[]
Definition: pg_locale.c:114
PGDLLIMPORT char * localized_abbrev_months[]
Definition: pg_locale.c:113
PGDLLIMPORT char * locale_monetary
Definition: pg_locale.c:98
bool pg_strxfrm_prefix_enabled(pg_locale_t locale)
Definition: pg_locale.c:2440
PGDLLIMPORT char * locale_messages
Definition: pg_locale.c:97
PGDLLIMPORT struct pg_locale_struct default_locale
Definition: pg_locale.c:1446
size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition: pg_locale.c:2502
PGDLLIMPORT bool database_ctype_is_c
Definition: pg_locale.c:117
size_t pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
Definition: pg_locale.c:2381
const char * builtin_validate_locale(int encoding, const char *locale)
Definition: pg_locale.c:2545
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:315
size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize, pg_locale_t locale)
Definition: pg_locale.c:2467
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
Definition: pg_locale.c:3115
unsigned int Oid
Definition: postgres_ext.h:31
locale_t lt
Definition: pg_locale.h:83
struct pg_locale_struct::@151::@152 builtin
const char * locale
Definition: pg_locale.h:81
union pg_locale_struct::@151 info
bool deterministic
Definition: pg_locale.h:76
#define locale_t
Definition: win32_port.h:424