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-2022, 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;
43 
44 /* lc_time localization cache */
45 extern PGDLLIMPORT char *localized_abbrev_days[];
46 extern PGDLLIMPORT char *localized_full_days[];
48 extern PGDLLIMPORT char *localized_full_months[];
49 
50 
51 extern bool check_locale(int category, const char *locale, char **canonname);
52 extern char *pg_perm_setlocale(int category, const char *locale);
53 extern void check_strxfrm_bug(void);
54 
55 extern bool lc_collate_is_c(Oid collation);
56 extern bool lc_ctype_is_c(Oid collation);
57 
58 /*
59  * Return the POSIX lconv struct (contains number/money formatting
60  * information) with locale information for all categories.
61  */
62 extern struct lconv *PGLC_localeconv(void);
63 
64 extern void cache_locale_time(void);
65 
66 
67 /*
68  * We define our own wrapper around locale_t so we can keep the same
69  * function signatures for all builds, while not having to create a
70  * fake version of the standard type locale_t in the global namespace.
71  * pg_locale_t is occasionally checked for truth, so make it a pointer.
72  */
74 {
75  char provider;
77  union
78  {
79 #ifdef HAVE_LOCALE_T
80  locale_t lt;
81 #endif
82 #ifdef USE_ICU
83  struct
84  {
85  const char *locale;
86  UCollator *ucol;
87  } icu;
88 #endif
89  int dummy; /* in case we have neither LOCALE_T nor ICU */
90  } info;
91 };
92 
93 typedef struct pg_locale_struct *pg_locale_t;
94 
96 
97 extern void make_icu_collator(const char *iculocstr,
98  struct pg_locale_struct *resultp);
99 
101 
102 extern char *get_collation_actual_version(char collprovider, const char *collcollate);
103 
104 #ifdef USE_ICU
105 extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
106 extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar);
107 #endif
108 extern void check_icu_locale(const char *icu_locale);
109 
110 /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
111 extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
113 extern size_t char2wchar(wchar_t *to, size_t tolen,
114  const char *from, size_t fromlen, pg_locale_t locale);
115 
116 #endif /* _PG_LOCALE_ */
#define PGDLLIMPORT
Definition: c.h:1252
static char * locale
Definition: initdb.c:129
static char * icu_locale
Definition: initdb.c:137
struct pg_locale_struct * pg_locale_t
Definition: pg_locale.h:93
void make_icu_collator(const char *iculocstr, struct pg_locale_struct *resultp)
Definition: pg_locale.c:1404
void cache_locale_time(void)
Definition: pg_locale.c:738
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
Definition: pg_locale.c:1990
struct lconv * PGLC_localeconv(void)
Definition: pg_locale.c:456
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1299
void check_strxfrm_bug(void)
Definition: pg_locale.c:1150
PGDLLIMPORT char * locale_time
Definition: pg_locale.c:89
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1481
PGDLLIMPORT char * localized_abbrev_days[]
Definition: pg_locale.c:98
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1352
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1647
PGDLLIMPORT char * locale_numeric
Definition: pg_locale.c:88
PGDLLIMPORT char * localized_full_days[]
Definition: pg_locale.c:99
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:144
PGDLLIMPORT char * localized_full_months[]
Definition: pg_locale.c:101
PGDLLIMPORT char * localized_abbrev_months[]
Definition: pg_locale.c:100
PGDLLIMPORT char * locale_monetary
Definition: pg_locale.c:87
PGDLLIMPORT char * locale_messages
Definition: pg_locale.c:86
PGDLLIMPORT struct pg_locale_struct default_locale
Definition: pg_locale.c:1401
void check_icu_locale(const char *icu_locale)
Definition: pg_locale.c:1954
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:247
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
Definition: pg_locale.c:2061
unsigned int Oid
Definition: postgres_ext.h:31
union pg_locale_struct::@142 info
bool deterministic
Definition: pg_locale.h:76
#define locale_t
Definition: win32_port.h:419