codekingpro/portable-devtools
114k
1/*-----------------------------------------------------------------------2 *3 * PostgreSQL locale utilities4 *5 * src/include/utils/pg_locale.h6 *7 * Copyright (c) 2002-2023, PostgreSQL Global Development Group8 *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#endif18#ifdef USE_ICU19#include <unicode/ucol.h>20#endif21 22#ifdef USE_ICU23/*24 * ucol_strcollUTF8() was introduced in ICU 50, but it is buggy before ICU 53.25 * (see26 * <https://www.postgresql.org/message-id/flat/f1438ec6-22aa-4029-9a3b-26f79d330e72%40manitou-mail.org>)27 */28#if U_ICU_VERSION_MAJOR_NUM >= 5329#define HAVE_UCOL_STRCOLLUTF8 130#else31#undef HAVE_UCOL_STRCOLLUTF832#endif33#endif34 35/* use for libc locale names */36#define LOCALE_NAME_BUFLEN 12837 38/* GUC settings */39extern PGDLLIMPORT char *locale_messages;40extern PGDLLIMPORT char *locale_monetary;41extern PGDLLIMPORT char *locale_numeric;42extern PGDLLIMPORT char *locale_time;43extern PGDLLIMPORT int icu_validation_level;44 45/* lc_time localization cache */46extern PGDLLIMPORT char *localized_abbrev_days[];47extern PGDLLIMPORT char *localized_full_days[];48extern PGDLLIMPORT char *localized_abbrev_months[];49extern PGDLLIMPORT char *localized_full_months[];50 51/* is the databases's LC_CTYPE the C locale? */52extern PGDLLIMPORT bool database_ctype_is_c;53 54extern bool check_locale(int category, const char *locale, char **canonname);55extern char *pg_perm_setlocale(int category, const char *locale);56 57extern bool lc_collate_is_c(Oid collation);58extern bool lc_ctype_is_c(Oid collation);59 60/*61 * Return the POSIX lconv struct (contains number/money formatting62 * information) with locale information for all categories.63 */64extern struct lconv *PGLC_localeconv(void);65 66extern void cache_locale_time(void);67 68 69/*70 * We define our own wrapper around locale_t so we can keep the same71 * function signatures for all builds, while not having to create a72 * fake version of the standard type locale_t in the global namespace.73 * pg_locale_t is occasionally checked for truth, so make it a pointer.74 */75struct pg_locale_struct76{77 char provider;78 bool deterministic;79 union80 {81#ifdef HAVE_LOCALE_T82 locale_t lt;83#endif84#ifdef USE_ICU85 struct86 {87 const char *locale;88 UCollator *ucol;89 } icu;90#endif91 int dummy; /* in case we have neither LOCALE_T nor ICU */92 } info;93};94 95typedef struct pg_locale_struct *pg_locale_t;96 97extern PGDLLIMPORT struct pg_locale_struct default_locale;98 99extern void make_icu_collator(const char *iculocstr,100 const char *icurules,101 struct pg_locale_struct *resultp);102 103extern bool pg_locale_deterministic(pg_locale_t locale);104extern pg_locale_t pg_newlocale_from_collation(Oid collid);105 106extern char *get_collation_actual_version(char collprovider, const char *collcollate);107extern int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale);108extern int pg_strncoll(const char *arg1, size_t len1,109 const char *arg2, size_t len2, pg_locale_t locale);110extern bool pg_strxfrm_enabled(pg_locale_t locale);111extern size_t pg_strxfrm(char *dest, const char *src, size_t destsize,112 pg_locale_t locale);113extern size_t pg_strnxfrm(char *dest, size_t destsize, const char *src,114 size_t srclen, pg_locale_t locale);115extern bool pg_strxfrm_prefix_enabled(pg_locale_t locale);116extern size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,117 pg_locale_t locale);118extern size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,119 size_t srclen, pg_locale_t locale);120 121extern void icu_validate_locale(const char *loc_str);122extern char *icu_language_tag(const char *loc_str, int elevel);123 124#ifdef USE_ICU125extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);126extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar);127#endif128 129/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */130extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,131 pg_locale_t locale);132extern size_t char2wchar(wchar_t *to, size_t tolen,133 const char *from, size_t fromlen, pg_locale_t locale);134 135#endif /* _PG_LOCALE_ */136 