pg_locale.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef _PG_LOCALE_
  12. #define _PG_LOCALE_
  13. #if defined(LOCALE_T_IN_XLOCALE) || defined(WCSTOMBS_L_IN_XLOCALE)
  14. #include <xlocale.h>
  15. #endif
  16. #ifdef USE_ICU
  17. #include <unicode/ucol.h>
  18. #endif
  19. #include "utils/guc.h"
  20. #ifdef USE_ICU
  21. /*
  22. * ucol_strcollUTF8() was introduced in ICU 50, but it is buggy before ICU 53.
  23. * (see
  24. * <https://www.postgresql.org/message-id/flat/f1438ec6-22aa-4029-9a3b-26f79d330e72%40manitou-mail.org>)
  25. */
  26. #if U_ICU_VERSION_MAJOR_NUM >= 53
  27. #define HAVE_UCOL_STRCOLLUTF8 1
  28. #else
  29. #undef HAVE_UCOL_STRCOLLUTF8
  30. #endif
  31. #endif
  32. /* use for libc locale names */
  33. #define LOCALE_NAME_BUFLEN 128
  34. /* GUC settings */
  35. extern PGDLLIMPORT char *locale_messages;
  36. extern PGDLLIMPORT char *locale_monetary;
  37. extern PGDLLIMPORT char *locale_numeric;
  38. extern PGDLLIMPORT char *locale_time;
  39. /* lc_time localization cache */
  40. extern PGDLLIMPORT char *localized_abbrev_days[];
  41. extern PGDLLIMPORT char *localized_full_days[];
  42. extern PGDLLIMPORT char *localized_abbrev_months[];
  43. extern PGDLLIMPORT char *localized_full_months[];
  44. /* is the databases's LC_CTYPE the C locale? */
  45. extern PGDLLIMPORT bool database_ctype_is_c;
  46. extern bool check_locale_messages(char **newval, void **extra, GucSource source);
  47. extern void assign_locale_messages(const char *newval, void *extra);
  48. extern bool check_locale_monetary(char **newval, void **extra, GucSource source);
  49. extern void assign_locale_monetary(const char *newval, void *extra);
  50. extern bool check_locale_numeric(char **newval, void **extra, GucSource source);
  51. extern void assign_locale_numeric(const char *newval, void *extra);
  52. extern bool check_locale_time(char **newval, void **extra, GucSource source);
  53. extern void assign_locale_time(const char *newval, void *extra);
  54. extern bool check_locale(int category, const char *locale, char **canonname);
  55. extern char *pg_perm_setlocale(int category, const char *locale);
  56. extern void check_strxfrm_bug(void);
  57. extern bool lc_collate_is_c(Oid collation);
  58. extern bool lc_ctype_is_c(Oid collation);
  59. /*
  60. * Return the POSIX lconv struct (contains number/money formatting
  61. * information) with locale information for all categories.
  62. */
  63. extern struct lconv *PGLC_localeconv(void);
  64. extern void cache_locale_time(void);
  65. /*
  66. * We define our own wrapper around locale_t so we can keep the same
  67. * function signatures for all builds, while not having to create a
  68. * fake version of the standard type locale_t in the global namespace.
  69. * pg_locale_t is occasionally checked for truth, so make it a pointer.
  70. */
  71. struct pg_locale_struct
  72. {
  73. char provider;
  74. bool deterministic;
  75. union
  76. {
  77. #ifdef HAVE_LOCALE_T
  78. locale_t lt;
  79. #endif
  80. #ifdef USE_ICU
  81. struct
  82. {
  83. const char *locale;
  84. UCollator *ucol;
  85. } icu;
  86. #endif
  87. int dummy; /* in case we have neither LOCALE_T nor ICU */
  88. } info;
  89. };
  90. typedef struct pg_locale_struct *pg_locale_t;
  91. extern PGDLLIMPORT struct pg_locale_struct default_locale;
  92. extern void make_icu_collator(const char *iculocstr,
  93. struct pg_locale_struct *resultp);
  94. extern pg_locale_t pg_newlocale_from_collation(Oid collid);
  95. extern char *get_collation_actual_version(char collprovider, const char *collcollate);
  96. #ifdef USE_ICU
  97. extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
  98. extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar);
  99. #endif
  100. extern void check_icu_locale(const char *icu_locale);
  101. /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
  102. extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
  103. pg_locale_t locale);
  104. extern size_t char2wchar(wchar_t *to, size_t tolen,
  105. const char *from, size_t fromlen, pg_locale_t locale);
  106. #endif /* _PG_LOCALE_ */