PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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 
25 /* GUC settings */
26 extern char *locale_messages;
27 extern char *locale_monetary;
28 extern char *locale_numeric;
29 extern char *locale_time;
30 
31 /* lc_time localization cache */
32 extern char *localized_abbrev_days[];
33 extern char *localized_full_days[];
34 extern char *localized_abbrev_months[];
35 extern char *localized_full_months[];
36 
37 
38 extern bool check_locale_messages(char **newval, void **extra, GucSource source);
39 extern void assign_locale_messages(const char *newval, void *extra);
40 extern bool check_locale_monetary(char **newval, void **extra, GucSource source);
41 extern void assign_locale_monetary(const char *newval, void *extra);
42 extern bool check_locale_numeric(char **newval, void **extra, GucSource source);
43 extern void assign_locale_numeric(const char *newval, void *extra);
44 extern bool check_locale_time(char **newval, void **extra, GucSource source);
45 extern void assign_locale_time(const char *newval, void *extra);
46 
47 extern bool check_locale(int category, const char *locale, char **canonname);
48 extern char *pg_perm_setlocale(int category, const char *locale);
49 extern void check_strxfrm_bug(void);
50 
51 extern bool lc_collate_is_c(Oid collation);
52 extern bool lc_ctype_is_c(Oid collation);
53 
54 /*
55  * Return the POSIX lconv struct (contains number/money formatting
56  * information) with locale information for all categories.
57  */
58 extern struct lconv *PGLC_localeconv(void);
59 
60 extern void cache_locale_time(void);
61 
62 
63 /*
64  * We define our own wrapper around locale_t so we can keep the same
65  * function signatures for all builds, while not having to create a
66  * fake version of the standard type locale_t in the global namespace.
67  * pg_locale_t is occasionally checked for truth, so make it a pointer.
68  */
70 {
71  char provider;
72  union
73  {
74 #ifdef HAVE_LOCALE_T
75  locale_t lt;
76 #endif
77 #ifdef USE_ICU
78  struct {
79  const char *locale;
80  UCollator *ucol;
81  } icu;
82 #endif
83  int dummy; /* in case we have neither LOCALE_T nor ICU */
84  } info;
85 };
86 
87 typedef struct pg_locale_struct *pg_locale_t;
88 
89 extern pg_locale_t pg_newlocale_from_collation(Oid collid);
90 
91 extern char *get_collation_actual_version(char collprovider, const char *collcollate);
92 
93 #ifdef USE_ICU
94 extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
95 extern int32_t icu_from_uchar(char **result, UChar *buff_uchar, int32_t len_uchar);
96 #endif
97 
98 /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
99 #ifdef USE_WIDE_UPPER_LOWER
100 extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
101  pg_locale_t locale);
102 extern size_t char2wchar(wchar_t *to, size_t tolen,
103  const char *from, size_t fromlen, pg_locale_t locale);
104 #endif
105 
106 #endif /* _PG_LOCALE_ */
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:151
bool check_locale_monetary(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:307
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1128
#define locale_t
Definition: win32.h:333
char * locale_time
Definition: pg_locale.c:91
bool check_locale_numeric(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:319
union pg_locale_struct::@113 info
bool check_locale_messages(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:353
return result
Definition: formatting.c:1618
struct lconv * PGLC_localeconv(void)
Definition: pg_locale.c:483
unsigned int Oid
Definition: postgres_ext.h:31
GucSource
Definition: guc.h:105
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:264
void assign_locale_monetary(const char *newval, void *extra)
Definition: pg_locale.c:313
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1178
void assign_locale_messages(const char *newval, void *extra)
Definition: pg_locale.c:376
char * locale_monetary
Definition: pg_locale.c:89
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1265
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1423
char * localized_full_days[]
Definition: pg_locale.c:95
bool check_locale_time(char **newval, void **extra, GucSource source)
Definition: pg_locale.c:331
struct pg_locale_struct * pg_locale_t
Definition: pg_locale.h:87
char * locale_messages
Definition: pg_locale.c:88
void cache_locale_time(void)
Definition: pg_locale.c:786
void check_strxfrm_bug(void)
Definition: pg_locale.c:993
char * localized_full_months[]
Definition: pg_locale.c:97
void assign_locale_numeric(const char *newval, void *extra)
Definition: pg_locale.c:325
#define newval
char * locale_numeric
Definition: pg_locale.c:90
void assign_locale_time(const char *newval, void *extra)
Definition: pg_locale.c:337
static char * locale
Definition: initdb.c:123
int int32_t
Definition: crypt.c:108
char * localized_abbrev_days[]
Definition: pg_locale.c:94
char * localized_abbrev_months[]
Definition: pg_locale.c:96