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  {
80 #ifdef USE_ICU
81  struct
82  {
83  const char *locale;
84  UCollator *ucol;
85  } icu;
86 #endif
87  } info;
88 };
89 
90 typedef struct pg_locale_struct *pg_locale_t;
91 
93 
94 extern void make_icu_collator(const char *iculocstr,
95  const char *icurules,
96  struct pg_locale_struct *resultp);
97 
100 
101 extern char *get_collation_actual_version(char collprovider, const char *collcollate);
102 extern int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale);
103 extern int pg_strncoll(const char *arg1, size_t len1,
104  const char *arg2, size_t len2, pg_locale_t locale);
106 extern size_t pg_strxfrm(char *dest, const char *src, size_t destsize,
108 extern size_t pg_strnxfrm(char *dest, size_t destsize, const char *src,
109  size_t srclen, pg_locale_t locale);
111 extern size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,
113 extern size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
114  size_t srclen, pg_locale_t locale);
115 
116 extern void icu_validate_locale(const char *loc_str);
117 extern char *icu_language_tag(const char *loc_str, int elevel);
118 
119 #ifdef USE_ICU
120 extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
121 extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar);
122 #endif
123 
124 /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
125 extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
127 extern 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:1305
Oid collid
static char * locale
Definition: initdb.c:140
struct pg_locale_struct * pg_locale_t
Definition: pg_locale.h:90
size_t pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition: pg_locale.c:2345
PGDLLIMPORT int icu_validation_level
Definition: pg_locale.c:103
void cache_locale_time(void)
Definition: pg_locale.c:807
bool pg_strxfrm_enabled(pg_locale_t locale)
Definition: pg_locale.c:2277
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
Definition: pg_locale.c:2934
struct lconv * PGLC_localeconv(void)
Definition: pg_locale.c:525
int pg_strncoll(const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
Definition: pg_locale.c:2061
void make_icu_collator(const char *iculocstr, const char *icurules, struct pg_locale_struct *resultp)
Definition: pg_locale.c:1412
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1307
void icu_validate_locale(const char *loc_str)
Definition: pg_locale.c:2853
PGDLLIMPORT char * locale_time
Definition: pg_locale.c:101
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1514
PGDLLIMPORT char * localized_abbrev_days[]
Definition: pg_locale.c:112
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1360
bool pg_locale_deterministic(pg_locale_t locale)
Definition: pg_locale.c:1494
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1677
PGDLLIMPORT char * locale_numeric
Definition: pg_locale.c:100
PGDLLIMPORT char * localized_full_days[]
Definition: pg_locale.c:113
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:213
char * icu_language_tag(const char *loc_str, int elevel)
Definition: pg_locale.c:2796
int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
Definition: pg_locale.c:2026
PGDLLIMPORT char * localized_full_months[]
Definition: pg_locale.c:115
PGDLLIMPORT char * localized_abbrev_months[]
Definition: pg_locale.c:114
PGDLLIMPORT char * locale_monetary
Definition: pg_locale.c:99
bool pg_strxfrm_prefix_enabled(pg_locale_t locale)
Definition: pg_locale.c:2368
PGDLLIMPORT char * locale_messages
Definition: pg_locale.c:98
PGDLLIMPORT struct pg_locale_struct default_locale
Definition: pg_locale.c:1409
size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition: pg_locale.c:2430
PGDLLIMPORT bool database_ctype_is_c
Definition: pg_locale.c:118
size_t pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
Definition: pg_locale.c:2309
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:316
size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize, pg_locale_t locale)
Definition: pg_locale.c:2395
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
Definition: pg_locale.c:2990
unsigned int Oid
Definition: postgres_ext.h:31
locale_t lt
Definition: pg_locale.h:79
union pg_locale_struct::@145 info
bool deterministic
Definition: pg_locale.h:76
#define locale_t
Definition: win32_port.h:424