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 #include "utils/guc.h"
23 
24 #ifdef USE_ICU
25 /*
26  * ucol_strcollUTF8() was introduced in ICU 50, but it is buggy before ICU 53.
27  * (see
28  * <https://www.postgresql.org/message-id/flat/f1438ec6-22aa-4029-9a3b-26f79d330e72%40manitou-mail.org>)
29  */
30 #if U_ICU_VERSION_MAJOR_NUM >= 53
31 #define HAVE_UCOL_STRCOLLUTF8 1
32 #else
33 #undef HAVE_UCOL_STRCOLLUTF8
34 #endif
35 #endif
36 
37 /* use for libc locale names */
38 #define LOCALE_NAME_BUFLEN 128
39 
40 /* GUC settings */
41 extern PGDLLIMPORT char *locale_messages;
42 extern PGDLLIMPORT char *locale_monetary;
43 extern PGDLLIMPORT char *locale_numeric;
44 extern PGDLLIMPORT char *locale_time;
45 
46 /* lc_time localization cache */
47 extern PGDLLIMPORT char *localized_abbrev_days[];
48 extern PGDLLIMPORT char *localized_full_days[];
50 extern PGDLLIMPORT char *localized_full_months[];
51 
52 
53 extern bool check_locale_messages(char **newval, void **extra, GucSource source);
54 extern void assign_locale_messages(const char *newval, void *extra);
55 extern bool check_locale_monetary(char **newval, void **extra, GucSource source);
56 extern void assign_locale_monetary(const char *newval, void *extra);
57 extern bool check_locale_numeric(char **newval, void **extra, GucSource source);
58 extern void assign_locale_numeric(const char *newval, void *extra);
59 extern bool check_locale_time(char **newval, void **extra, GucSource source);
60 extern void assign_locale_time(const char *newval, void *extra);
61 
62 extern bool check_locale(int category, const char *locale, char **canonname);
63 extern char *pg_perm_setlocale(int category, const char *locale);
64 extern void check_strxfrm_bug(void);
65 
66 extern bool lc_collate_is_c(Oid collation);
67 extern bool lc_ctype_is_c(Oid collation);
68 
69 /*
70  * Return the POSIX lconv struct (contains number/money formatting
71  * information) with locale information for all categories.
72  */
73 extern struct lconv *PGLC_localeconv(void);
74 
75 extern void cache_locale_time(void);
76 
77 
78 /*
79  * We define our own wrapper around locale_t so we can keep the same
80  * function signatures for all builds, while not having to create a
81  * fake version of the standard type locale_t in the global namespace.
82  * pg_locale_t is occasionally checked for truth, so make it a pointer.
83  */
85 {
86  char provider;
88  union
89  {
90 #ifdef HAVE_LOCALE_T
91  locale_t lt;
92 #endif
93 #ifdef USE_ICU
94  struct
95  {
96  const char *locale;
97  UCollator *ucol;
98  } icu;
99 #endif
100  int dummy; /* in case we have neither LOCALE_T nor ICU */
101  } info;
102 };
103 
105 
107 
108 extern void make_icu_collator(const char *iculocstr,
109  struct pg_locale_struct *resultp);
110 
112 
113 extern char *get_collation_actual_version(char collprovider, const char *collcollate);
114 
115 #ifdef USE_ICU
116 extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
117 extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar);
118 #endif
119 extern void check_icu_locale(const char *icu_locale);
120 
121 /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
122 extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
124 extern size_t char2wchar(wchar_t *to, size_t tolen,
125  const char *from, size_t fromlen, pg_locale_t locale);
126 
127 #endif /* _PG_LOCALE_ */
#define PGDLLIMPORT
Definition: c.h:1331
#define newval
GucSource
Definition: guc.h:105
static char * locale
Definition: initdb.c:128
static char * icu_locale
Definition: initdb.c:136
struct pg_locale_struct * pg_locale_t
Definition: pg_locale.h:104
void make_icu_collator(const char *iculocstr, struct pg_locale_struct *resultp)
Definition: pg_locale.c:1441
void cache_locale_time(void)
Definition: pg_locale.c:747
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
Definition: pg_locale.c:2027
struct lconv * PGLC_localeconv(void)
Definition: pg_locale.c:465
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1336
void check_strxfrm_bug(void)
Definition: pg_locale.c:1187
void assign_locale_time(const char *newval, void *extra)
Definition: pg_locale.c:319
PGDLLIMPORT char * locale_time
Definition: pg_locale.c:88
bool check_locale_time(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:313
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1518
PGDLLIMPORT char * localized_abbrev_days[]
Definition: pg_locale.c:97
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1389
bool check_locale_numeric(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:301
void assign_locale_numeric(const char *newval, void *extra)
Definition: pg_locale.c:307
bool check_locale_messages(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:335
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1684
PGDLLIMPORT char * locale_numeric
Definition: pg_locale.c:87
PGDLLIMPORT char * localized_full_days[]
Definition: pg_locale.c:98
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:143
void assign_locale_messages(const char *newval, void *extra)
Definition: pg_locale.c:358
PGDLLIMPORT char * localized_full_months[]
Definition: pg_locale.c:100
PGDLLIMPORT char * localized_abbrev_months[]
Definition: pg_locale.c:99
PGDLLIMPORT char * locale_monetary
Definition: pg_locale.c:86
PGDLLIMPORT char * locale_messages
Definition: pg_locale.c:85
PGDLLIMPORT struct pg_locale_struct default_locale
Definition: pg_locale.c:1438
void check_icu_locale(const char *icu_locale)
Definition: pg_locale.c:1991
void assign_locale_monetary(const char *newval, void *extra)
Definition: pg_locale.c:295
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:246
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
Definition: pg_locale.c:2098
bool check_locale_monetary(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:289
static rewind_source * source
Definition: pg_rewind.c:81
unsigned int Oid
Definition: postgres_ext.h:31
union pg_locale_struct::@150 info
bool deterministic
Definition: pg_locale.h:87
#define locale_t
Definition: win32_port.h:401