PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_locale.h File Reference
#include "mb/pg_wchar.h"
Include dependency graph for pg_locale.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  collate_methods
 
struct  ctype_methods
 
struct  pg_locale_struct
 

Macros

#define LOCALE_NAME_BUFLEN   128
 
#define UNICODE_CASEMAP_LEN   3
 
#define UNICODE_CASEMAP_BUFSZ   (UNICODE_CASEMAP_LEN * MAX_MULTIBYTE_CHAR_LEN)
 

Typedefs

typedef struct pg_locale_structpg_locale_t
 

Functions

bool check_locale (int category, const char *locale, char **canonname)
 
charpg_perm_setlocale (int category, const char *locale)
 
struct lconvPGLC_localeconv (void)
 
void cache_locale_time (void)
 
void init_database_collation (void)
 
pg_locale_t pg_database_locale (void)
 
pg_locale_t pg_newlocale_from_collation (Oid collid)
 
charget_collation_actual_version (char collprovider, const char *collcollate)
 
size_t pg_strlower (char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale)
 
size_t pg_strtitle (char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale)
 
size_t pg_strupper (char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale)
 
size_t pg_strfold (char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale)
 
size_t pg_downcase_ident (char *dst, size_t dstsize, const char *src, size_t srclen)
 
int pg_strcoll (const char *arg1, const char *arg2, pg_locale_t locale)
 
int pg_strncoll (const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
 
bool pg_strxfrm_enabled (pg_locale_t locale)
 
size_t pg_strxfrm (char *dest, const char *src, size_t destsize, pg_locale_t locale)
 
size_t pg_strnxfrm (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
bool pg_strxfrm_prefix_enabled (pg_locale_t locale)
 
size_t pg_strxfrm_prefix (char *dest, const char *src, size_t destsize, pg_locale_t locale)
 
size_t pg_strnxfrm_prefix (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
bool pg_iswdigit (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswalpha (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswalnum (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswupper (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswlower (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswgraph (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswprint (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswpunct (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswspace (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswxdigit (pg_wchar wc, pg_locale_t locale)
 
bool pg_iswcased (pg_wchar wc, pg_locale_t locale)
 
pg_wchar pg_towupper (pg_wchar wc, pg_locale_t locale)
 
pg_wchar pg_towlower (pg_wchar wc, pg_locale_t locale)
 
const charpg_icu_unicode_version (void)
 
int builtin_locale_encoding (const char *locale)
 
const charbuiltin_validate_locale (int encoding, const char *locale)
 
void icu_validate_locale (const char *loc_str)
 
charicu_language_tag (const char *loc_str, int elevel)
 
void report_newlocale_failure (const char *localename)
 
size_t wchar2char (char *to, const wchar_t *from, size_t tolen, locale_t loc)
 

Variables

PGDLLIMPORT charlocale_messages
 
PGDLLIMPORT charlocale_monetary
 
PGDLLIMPORT charlocale_numeric
 
PGDLLIMPORT charlocale_time
 
PGDLLIMPORT int icu_validation_level
 
PGDLLIMPORT charlocalized_abbrev_days []
 
PGDLLIMPORT charlocalized_full_days []
 
PGDLLIMPORT charlocalized_abbrev_months []
 
PGDLLIMPORT charlocalized_full_months []
 

Macro Definition Documentation

◆ LOCALE_NAME_BUFLEN

#define LOCALE_NAME_BUFLEN   128

Definition at line 18 of file pg_locale.h.

◆ UNICODE_CASEMAP_BUFSZ

#define UNICODE_CASEMAP_BUFSZ   (UNICODE_CASEMAP_LEN * MAX_MULTIBYTE_CHAR_LEN)

Definition at line 32 of file pg_locale.h.

◆ UNICODE_CASEMAP_LEN

#define UNICODE_CASEMAP_LEN   3

Definition at line 31 of file pg_locale.h.

Typedef Documentation

◆ pg_locale_t

Definition at line 60 of file pg_locale.h.

Function Documentation

◆ builtin_locale_encoding()

int builtin_locale_encoding ( const char locale)
extern

Definition at line 1661 of file pg_locale.c.

1662{
1663 if (strcmp(locale, "C") == 0)
1664 return -1;
1665 else if (strcmp(locale, "C.UTF-8") == 0)
1666 return PG_UTF8;
1667 else if (strcmp(locale, "PG_UNICODE_FAST") == 0)
1668 return PG_UTF8;
1669
1670
1671 ereport(ERROR,
1673 errmsg("invalid locale name \"%s\" for builtin provider",
1674 locale)));
1675
1676 return 0; /* keep compiler quiet */
1677}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
#define PG_UTF8
Definition mbprint.c:43
static char * errmsg
static int fb(int x)

References ereport, errcode(), errmsg, ERROR, fb(), and PG_UTF8.

Referenced by builtin_validate_locale(), and DefineCollation().

◆ builtin_validate_locale()

const char * builtin_validate_locale ( int  encoding,
const char locale 
)
extern

Definition at line 1685 of file pg_locale.c.

1686{
1687 const char *canonical_name = NULL;
1689
1690 if (strcmp(locale, "C") == 0)
1691 canonical_name = "C";
1692 else if (strcmp(locale, "C.UTF-8") == 0 || strcmp(locale, "C.UTF8") == 0)
1693 canonical_name = "C.UTF-8";
1694 else if (strcmp(locale, "PG_UNICODE_FAST") == 0)
1695 canonical_name = "PG_UNICODE_FAST";
1696
1697 if (!canonical_name)
1698 ereport(ERROR,
1700 errmsg("invalid locale name \"%s\" for builtin provider",
1701 locale)));
1702
1705 ereport(ERROR,
1707 errmsg("encoding \"%s\" does not match locale \"%s\"",
1708 pg_encoding_to_char(encoding), locale)));
1709
1710 return canonical_name;
1711}
static char * encoding
Definition initdb.c:139
int builtin_locale_encoding(const char *locale)
Definition pg_locale.c:1661
#define pg_encoding_to_char
Definition pg_wchar.h:483

References builtin_locale_encoding(), encoding, ereport, errcode(), errmsg, ERROR, fb(), and pg_encoding_to_char.

Referenced by create_pg_locale_builtin(), createdb(), and DefineCollation().

◆ cache_locale_time()

void cache_locale_time ( void  )
extern

Definition at line 702 of file pg_locale.c.

703{
704 char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA];
705 char *bufptr;
707 struct tm *timeinfo;
708 struct tm timeinfobuf;
709 bool strftimefail = false;
710 int encoding;
711 int i;
712 locale_t locale;
713
714 /* did we do this already? */
716 return;
717
718 elog(DEBUG3, "cache_locale_time() executed; locale: \"%s\"", locale_time);
719
720 errno = ENOENT;
721#ifdef WIN32
723 if (locale == (locale_t) 0)
725#else
727#endif
728 if (!locale)
730
731 /* We use times close to current time as data for strftime(). */
732 timenow = time(NULL);
734
735 /* Store the strftime results in MAX_L10N_DATA-sized portions of buf[] */
736 bufptr = buf;
737
738 /*
739 * MAX_L10N_DATA is sufficient buffer space for every known locale, and
740 * POSIX defines no strftime() errors. (Buffer space exhaustion is not an
741 * error.) An implementation might report errors (e.g. ENOMEM) by
742 * returning 0 (or, less plausibly, a negative value) and setting errno.
743 * Report errno just in case the implementation did that, but clear it in
744 * advance of the calls so we don't emit a stale, unrelated errno.
745 */
746 errno = 0;
747
748 /* localized days */
749 for (i = 0; i < 7; i++)
750 {
751 timeinfo->tm_wday = i;
752 if (strftime_l(bufptr, MAX_L10N_DATA, "%a", timeinfo, locale) <= 0)
753 strftimefail = true;
754 bufptr += MAX_L10N_DATA;
755 if (strftime_l(bufptr, MAX_L10N_DATA, "%A", timeinfo, locale) <= 0)
756 strftimefail = true;
757 bufptr += MAX_L10N_DATA;
758 }
759
760 /* localized months */
761 for (i = 0; i < 12; i++)
762 {
763 timeinfo->tm_mon = i;
764 timeinfo->tm_mday = 1; /* make sure we don't have invalid date */
765 if (strftime_l(bufptr, MAX_L10N_DATA, "%b", timeinfo, locale) <= 0)
766 strftimefail = true;
767 bufptr += MAX_L10N_DATA;
768 if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0)
769 strftimefail = true;
770 bufptr += MAX_L10N_DATA;
771 }
772
773#ifdef WIN32
774 _free_locale(locale);
775#else
776 freelocale(locale);
777#endif
778
779 /*
780 * At this point we've done our best to clean up, and can throw errors, or
781 * call functions that might throw errors, with a clean conscience.
782 */
783 if (strftimefail)
784 elog(ERROR, "strftime_l() failed");
785
786#ifndef WIN32
787
788 /*
789 * As in PGLC_localeconv(), we must convert strftime()'s output from the
790 * encoding implied by LC_TIME to the database encoding. If we can't
791 * identify the LC_TIME encoding, just perform encoding validation.
792 */
794 if (encoding < 0)
796
797#else
798
799 /*
800 * On Windows, strftime_win32() always returns UTF8 data, so convert from
801 * that if necessary.
802 */
804
805#endif /* WIN32 */
806
807 bufptr = buf;
808
809 /* localized days */
810 for (i = 0; i < 7; i++)
811 {
813 bufptr += MAX_L10N_DATA;
815 bufptr += MAX_L10N_DATA;
816 }
819
820 /* localized months */
821 for (i = 0; i < 12; i++)
822 {
824 bufptr += MAX_L10N_DATA;
826 bufptr += MAX_L10N_DATA;
827 }
830
831 CurrentLCTimeValid = true;
832}
#define DEBUG3
Definition elog.h:29
#define elog(elevel,...)
Definition elog.h:228
int i
Definition isn.c:77
static struct pg_tm tm
Definition localtime.c:104
char * localized_full_months[12+1]
Definition pg_locale.c:104
static bool CurrentLCTimeValid
Definition pg_locale.c:110
char * locale_time
Definition pg_locale.c:90
static void cache_single_string(char **dst, const char *src, int encoding)
Definition pg_locale.c:679
#define MAX_L10N_DATA
Definition pg_locale.c:69
char * localized_abbrev_months[12+1]
Definition pg_locale.c:103
char * localized_full_days[7+1]
Definition pg_locale.c:102
char * localized_abbrev_days[7+1]
Definition pg_locale.c:101
void report_newlocale_failure(const char *localename)
static char buf[DEFAULT_XLOG_SEG_SIZE]
@ PG_SQL_ASCII
Definition pg_wchar.h:76
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition chklocale.c:301
#define locale_t
Definition win32_port.h:429
void _dosmaperr(unsigned long)
Definition win32error.c:177

References _dosmaperr(), buf, cache_single_string(), CurrentLCTimeValid, DEBUG3, elog, encoding, ERROR, fb(), i, locale_t, locale_time, localized_abbrev_days, localized_abbrev_months, localized_full_days, localized_full_months, MAX_L10N_DATA, pg_get_encoding_from_locale(), PG_SQL_ASCII, PG_UTF8, report_newlocale_failure(), and tm.

Referenced by DCH_from_char(), and DCH_to_char().

◆ check_locale()

bool check_locale ( int  category,
const char locale,
char **  canonname 
)
extern

Definition at line 275 of file pg_locale.c.

276{
277 char *save;
278 char *res;
279
280 /* Don't let Windows' non-ASCII locale names in. */
281 if (!pg_is_ascii(locale))
282 {
285 errmsg("locale name \"%s\" contains non-ASCII characters",
286 locale)));
287 return false;
288 }
289
290 if (canonname)
291 *canonname = NULL; /* in case of failure */
292
293 save = setlocale(category, NULL);
294 if (!save)
295 return false; /* won't happen, we hope */
296
297 /* save may be pointing at a modifiable scratch variable, see above. */
298 save = pstrdup(save);
299
300 /* set the locale with setlocale, to see if it accepts it. */
301 res = setlocale(category, locale);
302
303 /* save canonical name if requested. */
304 if (res && canonname)
305 *canonname = pstrdup(res);
306
307 /* restore old value. */
308 if (!setlocale(category, save))
309 elog(WARNING, "failed to restore old locale \"%s\"", save);
310 pfree(save);
311
312 /* Don't let Windows' non-ASCII locale names out. */
314 {
317 errmsg("locale name \"%s\" contains non-ASCII characters",
318 *canonname)));
320 *canonname = NULL;
321 return false;
322 }
323
324 return (res != NULL);
325}
#define WARNING
Definition elog.h:37
char * pstrdup(const char *in)
Definition mcxt.c:1910
void pfree(void *pointer)
Definition mcxt.c:1619
bool pg_is_ascii(const char *str)
Definition string.c:132
#define setlocale(a, b)
Definition win32_port.h:472

References elog, ereport, errcode(), errmsg, fb(), pg_locale_struct::locale, pfree(), pg_is_ascii(), pstrdup(), setlocale, and WARNING.

Referenced by check_locale_messages(), check_locale_monetary(), check_locale_numeric(), check_locale_time(), and createdb().

◆ get_collation_actual_version()

char * get_collation_actual_version ( char  collprovider,
const char collcollate 
)
extern

◆ icu_language_tag()

char * icu_language_tag ( const char loc_str,
int  elevel 
)
extern

Definition at line 1725 of file pg_locale.c.

1726{
1727#ifdef USE_ICU
1728 UErrorCode status;
1729 char *langtag;
1730 size_t buflen = 32; /* arbitrary starting buffer size */
1731 const bool strict = true;
1732
1733 /*
1734 * A BCP47 language tag doesn't have a clearly-defined upper limit (cf.
1735 * RFC5646 section 4.4). Additionally, in older ICU versions,
1736 * uloc_toLanguageTag() doesn't always return the ultimate length on the
1737 * first call, necessitating a loop.
1738 */
1739 langtag = palloc(buflen);
1740 while (true)
1741 {
1742 status = U_ZERO_ERROR;
1743 uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
1744
1745 /* try again if the buffer is not large enough */
1746 if ((status == U_BUFFER_OVERFLOW_ERROR ||
1748 buflen < MaxAllocSize)
1749 {
1750 buflen = Min(buflen * 2, MaxAllocSize);
1751 langtag = repalloc(langtag, buflen);
1752 continue;
1753 }
1754
1755 break;
1756 }
1757
1758 if (U_FAILURE(status))
1759 {
1760 pfree(langtag);
1761
1762 if (elevel > 0)
1763 ereport(elevel,
1765 errmsg("could not convert locale name \"%s\" to language tag: %s",
1766 loc_str, u_errorName(status))));
1767 return NULL;
1768 }
1769
1770 return langtag;
1771#else /* not USE_ICU */
1772 ereport(ERROR,
1774 errmsg("ICU is not supported in this build")));
1775 return NULL; /* keep compiler quiet */
1776#endif /* not USE_ICU */
1777}
#define Min(x, y)
Definition c.h:1091
#define MaxAllocSize
Definition fe_memutils.h:22
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1635
void * palloc(Size size)
Definition mcxt.c:1390

References ereport, errcode(), errmsg, ERROR, fb(), MaxAllocSize, Min, palloc(), pfree(), and repalloc().

Referenced by createdb(), DefineCollation(), and pg_import_system_collations().

◆ icu_validate_locale()

void icu_validate_locale ( const char loc_str)
extern

Definition at line 1783 of file pg_locale.c.

1784{
1785#ifdef USE_ICU
1787 UErrorCode status;
1788 char lang[ULOC_LANG_CAPACITY];
1789 bool found = false;
1790 int elevel = icu_validation_level;
1791
1792 /* no validation */
1793 if (elevel < 0)
1794 return;
1795
1796 /* downgrade to WARNING during pg_upgrade */
1797 if (IsBinaryUpgrade && elevel > WARNING)
1798 elevel = WARNING;
1799
1800 /* validate that we can extract the language */
1801 status = U_ZERO_ERROR;
1803 if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
1804 {
1805 ereport(elevel,
1807 errmsg("could not get language from ICU locale \"%s\": %s",
1808 loc_str, u_errorName(status)),
1809 errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
1810 "icu_validation_level", "disabled")));
1811 return;
1812 }
1813
1814 /* check for special language name */
1815 if (strcmp(lang, "") == 0 ||
1816 strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
1817 found = true;
1818
1819 /* search for matching language within ICU */
1820 for (int32_t i = 0; !found && i < uloc_countAvailable(); i++)
1821 {
1822 const char *otherloc = uloc_getAvailable(i);
1824
1825 status = U_ZERO_ERROR;
1827 if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
1828 continue;
1829
1830 if (strcmp(lang, otherlang) == 0)
1831 found = true;
1832 }
1833
1834 if (!found)
1835 ereport(elevel,
1837 errmsg("ICU locale \"%s\" has unknown language \"%s\"",
1838 loc_str, lang),
1839 errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
1840 "icu_validation_level", "disabled")));
1841
1842 /* check that it can be opened */
1845#else /* not USE_ICU */
1846 /* could get here if a collation was created by a build with ICU */
1847 ereport(ERROR,
1849 errmsg("ICU is not supported in this build")));
1850#endif /* not USE_ICU */
1851}
int errhint(const char *fmt,...) pg_attribute_printf(1
bool IsBinaryUpgrade
Definition globals.c:123
int icu_validation_level
Definition pg_locale.c:92

References ereport, errcode(), errhint(), errmsg, ERROR, fb(), i, icu_validation_level, IsBinaryUpgrade, and WARNING.

Referenced by createdb(), and DefineCollation().

◆ init_database_collation()

void init_database_collation ( void  )
extern

Definition at line 1131 of file pg_locale.c.

1132{
1133 HeapTuple tup;
1136
1138
1139 /* Fetch our pg_database row normally, via syscache */
1141 if (!HeapTupleIsValid(tup))
1142 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
1144
1145 if (dbform->datlocprovider == COLLPROVIDER_BUILTIN)
1148 else if (dbform->datlocprovider == COLLPROVIDER_ICU)
1151 else if (dbform->datlocprovider == COLLPROVIDER_LIBC)
1154 else
1155 /* shouldn't happen */
1156 PGLOCALE_SUPPORT_ERROR(dbform->datlocprovider);
1157
1158 result->is_default = true;
1159
1160 Assert((result->collate_is_c && result->collate == NULL) ||
1161 (!result->collate_is_c && result->collate != NULL));
1162
1163 Assert((result->ctype_is_c && result->ctype == NULL) ||
1164 (!result->ctype_is_c && result->ctype != NULL));
1165
1167
1169}
#define Assert(condition)
Definition c.h:943
uint32 result
Oid MyDatabaseId
Definition globals.c:96
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
MemoryContext TopMemoryContext
Definition mcxt.c:167
END_CATALOG_STRUCT typedef FormData_pg_database * Form_pg_database
pg_locale_t create_pg_locale_libc(Oid collid, MemoryContext context)
pg_locale_t create_pg_locale_builtin(Oid collid, MemoryContext context)
#define PGLOCALE_SUPPORT_ERROR(provider)
Definition pg_locale.c:60
pg_locale_t create_pg_locale_icu(Oid collid, MemoryContext context)
static pg_locale_t default_locale
Definition pg_locale.c:106
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References Assert, create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), default_locale, elog, ERROR, fb(), Form_pg_database, GETSTRUCT(), HeapTupleIsValid, MyDatabaseId, ObjectIdGetDatum(), PGLOCALE_SUPPORT_ERROR, ReleaseSysCache(), result, SearchSysCache1(), and TopMemoryContext.

Referenced by CheckMyDatabase().

◆ pg_database_locale()

pg_locale_t pg_database_locale ( void  )
extern

Definition at line 1175 of file pg_locale.c.

1176{
1178}
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition pg_locale.c:1189

References fb(), and pg_newlocale_from_collation().

Referenced by ltree_crc32_sz(), and ltree_label_match().

◆ pg_downcase_ident()

size_t pg_downcase_ident ( char dst,
size_t  dstsize,
const char src,
size_t  srclen 
)
extern

Definition at line 1363 of file pg_locale.c.

1364{
1365 pg_locale_t locale = default_locale;
1366
1367 if (locale == NULL || locale->ctype == NULL ||
1368 locale->ctype->downcase_ident == NULL)
1369 return strlower_c(dst, dstsize, src, srclen);
1370 else
1371 return locale->ctype->downcase_ident(dst, dstsize, src, srclen,
1372 locale);
1373}
static size_t strlower_c(char *dst, size_t dstsize, const char *src, size_t srclen)
Definition pg_locale.c:1265
size_t(* downcase_ident)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:113
const struct ctype_methods * ctype
Definition pg_locale.h:155

References pg_locale_struct::ctype, default_locale, ctype_methods::downcase_ident, fb(), and strlower_c().

Referenced by downcase_identifier().

◆ pg_icu_unicode_version()

const char * pg_icu_unicode_version ( void  )
extern

Definition at line 1647 of file pg_locale.c.

1648{
1649#ifdef USE_ICU
1650 return U_UNICODE_VERSION;
1651#else
1652 return NULL;
1653#endif
1654}

References fb().

Referenced by icu_unicode_version().

◆ pg_iswalnum()

bool pg_iswalnum ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1527 of file pg_locale.c.

1528{
1529 if (locale->ctype == NULL)
1530 return (wc <= (pg_wchar) 127 &&
1532 else
1533 return locale->ctype->wc_isalnum(wc, locale);
1534}
unsigned int pg_wchar
Definition mbprint.c:31
#define PG_ISALNUM
Definition pg_locale_c.h:21
static const unsigned char pg_char_properties[128]
Definition pg_locale_c.h:29
bool(* wc_isalnum)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:120

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISALNUM, and ctype_methods::wc_isalnum.

◆ pg_iswalpha()

bool pg_iswalpha ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1517 of file pg_locale.c.

1518{
1519 if (locale->ctype == NULL)
1520 return (wc <= (pg_wchar) 127 &&
1522 else
1523 return locale->ctype->wc_isalpha(wc, locale);
1524}
#define PG_ISALPHA
Definition pg_locale_c.h:20
bool(* wc_isalpha)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:119

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISALPHA, and ctype_methods::wc_isalpha.

◆ pg_iswcased()

bool pg_iswcased ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1609 of file pg_locale.c.

1610{
1611 /* for the C locale, Cased and Alpha are equivalent */
1612 if (locale->ctype == NULL)
1613 return (wc <= (pg_wchar) 127 &&
1615 else
1616 return locale->ctype->wc_iscased(wc, locale);
1617}
bool(* wc_iscased)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:128

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISALPHA, and ctype_methods::wc_iscased.

Referenced by like_fixed_prefix_ci().

◆ pg_iswdigit()

bool pg_iswdigit ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1507 of file pg_locale.c.

1508{
1509 if (locale->ctype == NULL)
1510 return (wc <= (pg_wchar) 127 &&
1512 else
1513 return locale->ctype->wc_isdigit(wc, locale);
1514}
#define PG_ISDIGIT
Definition pg_locale_c.h:19
bool(* wc_isdigit)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:118

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISDIGIT, and ctype_methods::wc_isdigit.

◆ pg_iswgraph()

bool pg_iswgraph ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1557 of file pg_locale.c.

1558{
1559 if (locale->ctype == NULL)
1560 return (wc <= (pg_wchar) 127 &&
1562 else
1563 return locale->ctype->wc_isgraph(wc, locale);
1564}
#define PG_ISGRAPH
Definition pg_locale_c.h:24
bool(* wc_isgraph)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:123

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISGRAPH, and ctype_methods::wc_isgraph.

◆ pg_iswlower()

bool pg_iswlower ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1547 of file pg_locale.c.

1548{
1549 if (locale->ctype == NULL)
1550 return (wc <= (pg_wchar) 127 &&
1552 else
1553 return locale->ctype->wc_islower(wc, locale);
1554}
#define PG_ISLOWER
Definition pg_locale_c.h:23
bool(* wc_islower)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:122

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISLOWER, and ctype_methods::wc_islower.

◆ pg_iswprint()

bool pg_iswprint ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1567 of file pg_locale.c.

1568{
1569 if (locale->ctype == NULL)
1570 return (wc <= (pg_wchar) 127 &&
1572 else
1573 return locale->ctype->wc_isprint(wc, locale);
1574}
#define PG_ISPRINT
Definition pg_locale_c.h:25
bool(* wc_isprint)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:124

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISPRINT, and ctype_methods::wc_isprint.

◆ pg_iswpunct()

bool pg_iswpunct ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1577 of file pg_locale.c.

1578{
1579 if (locale->ctype == NULL)
1580 return (wc <= (pg_wchar) 127 &&
1582 else
1583 return locale->ctype->wc_ispunct(wc, locale);
1584}
#define PG_ISPUNCT
Definition pg_locale_c.h:26
bool(* wc_ispunct)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:125

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISPUNCT, and ctype_methods::wc_ispunct.

◆ pg_iswspace()

bool pg_iswspace ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1587 of file pg_locale.c.

1588{
1589 if (locale->ctype == NULL)
1590 return (wc <= (pg_wchar) 127 &&
1592 else
1593 return locale->ctype->wc_isspace(wc, locale);
1594}
#define PG_ISSPACE
Definition pg_locale_c.h:27
bool(* wc_isspace)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:126

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISSPACE, and ctype_methods::wc_isspace.

◆ pg_iswupper()

bool pg_iswupper ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1537 of file pg_locale.c.

1538{
1539 if (locale->ctype == NULL)
1540 return (wc <= (pg_wchar) 127 &&
1542 else
1543 return locale->ctype->wc_isupper(wc, locale);
1544}
#define PG_ISUPPER
Definition pg_locale_c.h:22
bool(* wc_isupper)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:121

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISUPPER, and ctype_methods::wc_isupper.

◆ pg_iswxdigit()

bool pg_iswxdigit ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1597 of file pg_locale.c.

1598{
1599 if (locale->ctype == NULL)
1600 return (wc <= (pg_wchar) 127 &&
1601 ((pg_char_properties[wc] & PG_ISDIGIT) ||
1602 ((wc >= 'A' && wc <= 'F') ||
1603 (wc >= 'a' && wc <= 'f'))));
1604 else
1605 return locale->ctype->wc_isxdigit(wc, locale);
1606}
bool(* wc_isxdigit)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:127

References pg_locale_struct::ctype, fb(), pg_char_properties, PG_ISDIGIT, and ctype_methods::wc_isxdigit.

◆ pg_newlocale_from_collation()

pg_locale_t pg_newlocale_from_collation ( Oid  collid)
extern

Definition at line 1189 of file pg_locale.c.

1190{
1192 bool found;
1193
1195 return default_locale;
1196
1197 /*
1198 * Some callers expect C_COLLATION_OID to succeed even without catalog
1199 * access.
1200 */
1201 if (collid == C_COLLATION_OID)
1202 return &c_locale;
1203
1204 if (!OidIsValid(collid))
1205 elog(ERROR, "cache lookup failed for collation %u", collid);
1206
1208
1211
1212 if (CollationCache == NULL)
1213 {
1215 "collation cache",
1218 16, NULL);
1219 }
1220
1222 if (!found)
1223 {
1224 /*
1225 * Make sure cache entry is marked invalid, in case we fail before
1226 * setting things.
1227 */
1228 cache_entry->locale = NULL;
1229 }
1230
1231 if (cache_entry->locale == NULL)
1232 {
1234 }
1235
1238
1239 return cache_entry->locale;
1240}
#define OidIsValid(objectId)
Definition c.h:858
Oid collid
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
static pg_locale_t last_collation_cache_locale
Definition pg_locale.c:151
static struct pg_locale_struct c_locale
Definition pg_locale.c:112
static pg_locale_t create_pg_locale(Oid collid, MemoryContext context)
Definition pg_locale.c:1049
static MemoryContext CollationCacheContext
Definition pg_locale.c:143
static collation_cache_hash * CollationCache
Definition pg_locale.c:144
static Oid last_collation_cache_oid
Definition pg_locale.c:150
static void AssertCouldGetRelation(void)
Definition relcache.h:44
Definition pg_locale.c:121
const char * locale
Definition pg_locale.h:161

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, AssertCouldGetRelation(), c_locale, CollationCache, CollationCacheContext, collid, create_pg_locale(), default_locale, elog, ERROR, fb(), last_collation_cache_locale, last_collation_cache_oid, pg_locale_struct::locale, OidIsValid, and TopMemoryContext.

Referenced by bpchareq(), bpcharne(), btvarstrequalimage(), convert_string_datum(), DefineCollation(), Generic_Text_IC_like(), GenericMatchText(), hashbpchar(), hashbpcharextended(), hashtext(), hashtextextended(), like_fixed_prefix_ci(), make_greater_string(), match_pattern_prefix(), pg_database_locale(), pg_set_regex_collation(), spg_text_inner_consistent(), str_casefold(), str_initcap(), str_tolower(), str_toupper(), text_position(), text_position_setup(), text_starts_with(), texteq(), textne(), varstr_cmp(), and varstr_sortsupport().

◆ pg_perm_setlocale()

char * pg_perm_setlocale ( int  category,
const char locale 
)
extern

Definition at line 172 of file pg_locale.c.

173{
174 char *result;
175 const char *envvar;
176
177#ifndef WIN32
178 result = setlocale(category, locale);
179#else
180
181 /*
182 * On Windows, setlocale(LC_MESSAGES) does not work, so just assume that
183 * the given value is good and set it in the environment variables. We
184 * must ignore attempts to set to "", which means "keep using the old
185 * environment value".
186 */
187#ifdef LC_MESSAGES
188 if (category == LC_MESSAGES)
189 {
190 result = (char *) locale;
191 if (locale == NULL || locale[0] == '\0')
192 return result;
193 }
194 else
195#endif
196 result = setlocale(category, locale);
197#endif /* WIN32 */
198
199 if (result == NULL)
200 return result; /* fall out immediately on failure */
201
202 /*
203 * Use the right encoding in translated messages. Under ENABLE_NLS, let
204 * pg_bind_textdomain_codeset() figure it out. Under !ENABLE_NLS, message
205 * format strings are ASCII, but database-encoding strings may enter the
206 * message via %s. This makes the overall message encoding equal to the
207 * database encoding.
208 */
209 if (category == LC_CTYPE)
210 {
212
213 /* copy setlocale() return value before callee invokes it again */
216
217#ifdef ENABLE_NLS
219#else
221#endif
222 }
223
224 switch (category)
225 {
226 case LC_COLLATE:
227 envvar = "LC_COLLATE";
228 break;
229 case LC_CTYPE:
230 envvar = "LC_CTYPE";
231 break;
232#ifdef LC_MESSAGES
233 case LC_MESSAGES:
234 envvar = "LC_MESSAGES";
235#ifdef WIN32
236 result = IsoLocaleName(locale);
237 if (result == NULL)
238 result = (char *) locale;
239 elog(DEBUG3, "IsoLocaleName() executed; locale: \"%s\"", result);
240#endif /* WIN32 */
241 break;
242#endif /* LC_MESSAGES */
243 case LC_MONETARY:
244 envvar = "LC_MONETARY";
245 break;
246 case LC_NUMERIC:
247 envvar = "LC_NUMERIC";
248 break;
249 case LC_TIME:
250 envvar = "LC_TIME";
251 break;
252 default:
253 elog(FATAL, "unrecognized LC category: %d", category);
254 return NULL; /* keep compiler quiet */
255 }
256
257 if (setenv(envvar, result, 1) != 0)
258 return NULL;
259
260 return result;
261}
#define FATAL
Definition elog.h:42
int GetDatabaseEncoding(void)
Definition mbutils.c:1389
void SetMessageEncoding(int encoding)
Definition mbutils.c:1300
#define LOCALE_NAME_BUFLEN
Definition pg_locale.h:18
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
#define setenv(x, y, z)
Definition win32_port.h:542

References DEBUG3, elog, FATAL, fb(), GetDatabaseEncoding(), pg_locale_struct::locale, LOCALE_NAME_BUFLEN, result, setenv, setlocale, SetMessageEncoding(), and strlcpy().

Referenced by assign_locale_messages(), CheckMyDatabase(), and init_locale().

◆ pg_strcoll()

int pg_strcoll ( const char arg1,
const char arg2,
pg_locale_t  locale 
)
extern

Definition at line 1381 of file pg_locale.c.

1382{
1383 return locale->collate->strcoll(arg1, arg2, locale);
1384}
int(* strcoll)(const char *arg1, const char *arg2, pg_locale_t locale)
Definition pg_locale.h:70
const struct collate_methods * collate
Definition pg_locale.h:154

References pg_locale_struct::collate, fb(), and collate_methods::strcoll.

Referenced by varstrfastcmp_locale().

◆ pg_strfold()

size_t pg_strfold ( char dst,
size_t  dstsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
extern

Definition at line 1345 of file pg_locale.c.

1347{
1348 /* in the C locale, casefolding is the same as lowercasing */
1349 if (locale->ctype == NULL)
1350 return strlower_c(dst, dstsize, src, srclen);
1351 else
1352 return locale->ctype->strfold(dst, dstsize, src, srclen, locale);
1353}
size_t(* strfold)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:110

References pg_locale_struct::ctype, fb(), ctype_methods::strfold, and strlower_c().

Referenced by ltree_crc32_sz(), ltree_label_match(), and str_casefold().

◆ pg_strlower()

size_t pg_strlower ( char dst,
size_t  dstsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
extern

Definition at line 1315 of file pg_locale.c.

1317{
1318 if (locale->ctype == NULL)
1319 return strlower_c(dst, dstsize, src, srclen);
1320 else
1321 return locale->ctype->strlower(dst, dstsize, src, srclen, locale);
1322}
size_t(* strlower)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:101

References pg_locale_struct::ctype, fb(), ctype_methods::strlower, and strlower_c().

Referenced by str_tolower().

◆ pg_strncoll()

int pg_strncoll ( const char arg1,
size_t  len1,
const char arg2,
size_t  len2,
pg_locale_t  locale 
)
extern

Definition at line 1400 of file pg_locale.c.

1402{
1403 return locale->collate->strncoll(arg1, len1, arg2, len2, locale);
1404}
int(* strncoll)(const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
Definition pg_locale.h:66

References pg_locale_struct::collate, fb(), and collate_methods::strncoll.

Referenced by MatchText(), text_position_next_internal(), and varstr_cmp().

◆ pg_strnxfrm()

size_t pg_strnxfrm ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
extern

Definition at line 1454 of file pg_locale.c.

1456{
1457 return locale->collate->strnxfrm(dest, destsize, src, srclen, locale);
1458}
size_t(* strnxfrm)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:74

References pg_locale_struct::collate, fb(), and collate_methods::strnxfrm.

Referenced by hashbpchar(), hashbpcharextended(), hashtext(), and hashtextextended().

◆ pg_strnxfrm_prefix()

size_t pg_strnxfrm_prefix ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
extern

Definition at line 1500 of file pg_locale.c.

1502{
1503 return locale->collate->strnxfrm_prefix(dest, destsize, src, srclen, locale);
1504}
size_t(* strnxfrm_prefix)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:82

References pg_locale_struct::collate, fb(), and collate_methods::strnxfrm_prefix.

◆ pg_strtitle()

size_t pg_strtitle ( char dst,
size_t  dstsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
extern

Definition at line 1325 of file pg_locale.c.

1327{
1328 if (locale->ctype == NULL)
1329 return strtitle_c(dst, dstsize, src, srclen);
1330 else
1331 return locale->ctype->strtitle(dst, dstsize, src, srclen, locale);
1332}
static size_t strtitle_c(char *dst, size_t dstsize, const char *src, size_t srclen)
Definition pg_locale.c:1278
size_t(* strtitle)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:104

References pg_locale_struct::ctype, fb(), ctype_methods::strtitle, and strtitle_c().

Referenced by str_initcap().

◆ pg_strupper()

size_t pg_strupper ( char dst,
size_t  dstsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
extern

Definition at line 1335 of file pg_locale.c.

1337{
1338 if (locale->ctype == NULL)
1339 return strupper_c(dst, dstsize, src, srclen);
1340 else
1341 return locale->ctype->strupper(dst, dstsize, src, srclen, locale);
1342}
static size_t strupper_c(char *dst, size_t dstsize, const char *src, size_t srclen)
Definition pg_locale.c:1303
size_t(* strupper)(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.h:107

References pg_locale_struct::ctype, fb(), ctype_methods::strupper, and strupper_c().

Referenced by str_toupper().

◆ pg_strxfrm()

size_t pg_strxfrm ( char dest,
const char src,
size_t  destsize,
pg_locale_t  locale 
)
extern

Definition at line 1430 of file pg_locale.c.

1431{
1432 return locale->collate->strxfrm(dest, destsize, src, locale);
1433}
size_t(* strxfrm)(char *dest, size_t destsize, const char *src, pg_locale_t locale)
Definition pg_locale.h:78

References pg_locale_struct::collate, fb(), and collate_methods::strxfrm.

Referenced by convert_string_datum(), and varstr_abbrev_convert().

◆ pg_strxfrm_enabled()

bool pg_strxfrm_enabled ( pg_locale_t  locale)
extern

Definition at line 1414 of file pg_locale.c.

1415{
1416 /*
1417 * locale->collate->strnxfrm is still a required method, even if it may
1418 * have the wrong behavior, because the planner uses it for estimates in
1419 * some cases.
1420 */
1421 return locale->collate->strxfrm_is_safe;
1422}
bool strxfrm_is_safe
Definition pg_locale.h:95

References pg_locale_struct::collate, and collate_methods::strxfrm_is_safe.

Referenced by varstr_sortsupport().

◆ pg_strxfrm_prefix()

size_t pg_strxfrm_prefix ( char dest,
const char src,
size_t  destsize,
pg_locale_t  locale 
)
extern

Definition at line 1476 of file pg_locale.c.

1478{
1479 return locale->collate->strxfrm_prefix(dest, destsize, src, locale);
1480}
size_t(* strxfrm_prefix)(char *dest, size_t destsize, const char *src, pg_locale_t locale)
Definition pg_locale.h:86

References pg_locale_struct::collate, fb(), and collate_methods::strxfrm_prefix.

Referenced by varstr_abbrev_convert().

◆ pg_strxfrm_prefix_enabled()

bool pg_strxfrm_prefix_enabled ( pg_locale_t  locale)
extern

Definition at line 1465 of file pg_locale.c.

1466{
1467 return (locale->collate->strnxfrm_prefix != NULL);
1468}

References pg_locale_struct::collate, fb(), and collate_methods::strnxfrm_prefix.

Referenced by varstr_abbrev_convert().

◆ pg_towlower()

pg_wchar pg_towlower ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1633 of file pg_locale.c.

1634{
1635 if (locale->ctype == NULL)
1636 {
1637 if (wc <= (pg_wchar) 127)
1638 return pg_ascii_tolower((unsigned char) wc);
1639 return wc;
1640 }
1641 else
1642 return locale->ctype->wc_tolower(wc, locale);
1643}
static unsigned char pg_ascii_tolower(unsigned char ch)
Definition port.h:189
pg_wchar(* wc_tolower)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:130

References pg_locale_struct::ctype, fb(), pg_ascii_tolower(), and ctype_methods::wc_tolower.

◆ pg_towupper()

pg_wchar pg_towupper ( pg_wchar  wc,
pg_locale_t  locale 
)
extern

Definition at line 1620 of file pg_locale.c.

1621{
1622 if (locale->ctype == NULL)
1623 {
1624 if (wc <= (pg_wchar) 127)
1625 return pg_ascii_toupper((unsigned char) wc);
1626 return wc;
1627 }
1628 else
1629 return locale->ctype->wc_toupper(wc, locale);
1630}
static unsigned char pg_ascii_toupper(unsigned char ch)
Definition port.h:178
pg_wchar(* wc_toupper)(pg_wchar wc, pg_locale_t locale)
Definition pg_locale.h:129

References pg_locale_struct::ctype, fb(), pg_ascii_toupper(), and ctype_methods::wc_toupper.

◆ PGLC_localeconv()

struct lconv * PGLC_localeconv ( void  )
extern

Definition at line 506 of file pg_locale.c.

507{
508 static struct lconv CurrentLocaleConv;
509 static bool CurrentLocaleConvAllocated = false;
510 struct lconv *extlconv;
511 struct lconv tmp;
512 struct lconv worklconv = {0};
513
514 /* Did we do it already? */
516 return &CurrentLocaleConv;
517
518 /* Free any already-allocated storage */
520 {
523 }
524
525 /*
526 * Use thread-safe method of obtaining a copy of lconv from the operating
527 * system.
528 */
531 &tmp) != 0)
532 elog(ERROR,
533 "could not get lconv for LC_MONETARY = \"%s\", LC_NUMERIC = \"%s\": %m",
535
536 /* Must copy data now so we can re-encode it. */
537 extlconv = &tmp;
538 worklconv.decimal_point = strdup(extlconv->decimal_point);
539 worklconv.thousands_sep = strdup(extlconv->thousands_sep);
540 worklconv.grouping = strdup(extlconv->grouping);
541 worklconv.int_curr_symbol = strdup(extlconv->int_curr_symbol);
542 worklconv.currency_symbol = strdup(extlconv->currency_symbol);
543 worklconv.mon_decimal_point = strdup(extlconv->mon_decimal_point);
544 worklconv.mon_thousands_sep = strdup(extlconv->mon_thousands_sep);
545 worklconv.mon_grouping = strdup(extlconv->mon_grouping);
546 worklconv.positive_sign = strdup(extlconv->positive_sign);
547 worklconv.negative_sign = strdup(extlconv->negative_sign);
548 /* Copy scalar fields as well */
549 worklconv.int_frac_digits = extlconv->int_frac_digits;
550 worklconv.frac_digits = extlconv->frac_digits;
551 worklconv.p_cs_precedes = extlconv->p_cs_precedes;
552 worklconv.p_sep_by_space = extlconv->p_sep_by_space;
553 worklconv.n_cs_precedes = extlconv->n_cs_precedes;
554 worklconv.n_sep_by_space = extlconv->n_sep_by_space;
555 worklconv.p_sign_posn = extlconv->p_sign_posn;
556 worklconv.n_sign_posn = extlconv->n_sign_posn;
557
558 /* Free the contents of the object populated by pg_localeconv_r(). */
559 pg_localeconv_free(&tmp);
560
561 /* If any of the preceding strdup calls failed, complain now. */
565 errmsg("out of memory")));
566
567 PG_TRY();
568 {
569 int encoding;
570
571 /*
572 * Now we must perform encoding conversion from whatever's associated
573 * with the locales into the database encoding. If we can't identify
574 * the encoding implied by LC_NUMERIC or LC_MONETARY (ie we get -1),
575 * use PG_SQL_ASCII, which will result in just validating that the
576 * strings are OK in the database encoding.
577 */
579 if (encoding < 0)
581
582 db_encoding_convert(encoding, &worklconv.decimal_point);
583 db_encoding_convert(encoding, &worklconv.thousands_sep);
584 /* grouping is not text and does not require conversion */
585
587 if (encoding < 0)
589
590 db_encoding_convert(encoding, &worklconv.int_curr_symbol);
591 db_encoding_convert(encoding, &worklconv.currency_symbol);
592 db_encoding_convert(encoding, &worklconv.mon_decimal_point);
593 db_encoding_convert(encoding, &worklconv.mon_thousands_sep);
594 /* mon_grouping is not text and does not require conversion */
595 db_encoding_convert(encoding, &worklconv.positive_sign);
596 db_encoding_convert(encoding, &worklconv.negative_sign);
597 }
598 PG_CATCH();
599 {
601 PG_RE_THROW();
602 }
603 PG_END_TRY();
604
605 /*
606 * Everything is good, so save the results.
607 */
611 return &CurrentLocaleConv;
612}
#define PG_RE_THROW()
Definition elog.h:407
#define PG_TRY(...)
Definition elog.h:374
#define PG_END_TRY(...)
Definition elog.h:399
#define PG_CATCH(...)
Definition elog.h:384
char * locale_numeric
Definition pg_locale.c:89
static void db_encoding_convert(int encoding, char **str)
Definition pg_locale.c:476
static void free_struct_lconv(struct lconv *s)
Definition pg_locale.c:426
static bool CurrentLocaleConvValid
Definition pg_locale.c:109
static bool struct_lconv_is_valid(struct lconv *s)
Definition pg_locale.c:445
char * locale_monetary
Definition pg_locale.c:88
int pg_localeconv_r(const char *lc_monetary, const char *lc_numeric, struct lconv *output)
void pg_localeconv_free(struct lconv *lconv)

References CurrentLocaleConvValid, db_encoding_convert(), elog, encoding, ereport, errcode(), errmsg, ERROR, fb(), free_struct_lconv(), locale_monetary, locale_numeric, PG_CATCH, PG_END_TRY, pg_get_encoding_from_locale(), pg_localeconv_free(), pg_localeconv_r(), PG_RE_THROW, PG_SQL_ASCII, PG_TRY, and struct_lconv_is_valid().

Referenced by cash_in(), cash_numeric(), cash_out(), int4_cash(), int8_cash(), NUM_prepare_locale(), and numeric_cash().

◆ report_newlocale_failure()

void report_newlocale_failure ( const char localename)
extern

Definition at line 1126 of file pg_locale_libc.c.

1127{
1128 int save_errno;
1129
1130 /*
1131 * Windows doesn't provide any useful error indication from
1132 * _create_locale(), and BSD-derived platforms don't seem to feel they
1133 * need to set errno either (even though POSIX is pretty clear that
1134 * newlocale should do so). So, if errno hasn't been set, assume ENOENT
1135 * is what to report.
1136 */
1137 if (errno == 0)
1138 errno = ENOENT;
1139
1140 /*
1141 * ENOENT means "no such locale", not "no such file", so clarify that
1142 * errno with an errdetail message.
1143 */
1144 save_errno = errno; /* auxiliary funcs might change errno */
1145 ereport(ERROR,
1147 errmsg("could not create locale \"%s\": %m",
1148 localename),
1149 (save_errno == ENOENT ?
1150 errdetail("The operating system could not find any locale data for the locale name \"%s\".",
1151 localename) : 0)));
1152}
int errdetail(const char *fmt,...) pg_attribute_printf(1

References ereport, errcode(), errdetail(), errmsg, ERROR, and fb().

Referenced by cache_locale_time(), and make_libc_collator().

◆ wchar2char()

size_t wchar2char ( char to,
const wchar_t from,
size_t  tolen,
locale_t  loc 
)
extern

Definition at line 1204 of file pg_locale_libc.c.

1205{
1206 size_t result;
1207
1208 if (tolen == 0)
1209 return 0;
1210
1211#ifdef WIN32
1212
1213 /*
1214 * On Windows, the "Unicode" locales assume UTF16 not UTF8 encoding, and
1215 * for some reason mbstowcs and wcstombs won't do this for us, so we use
1216 * MultiByteToWideChar().
1217 */
1219 {
1220 result = WideCharToMultiByte(CP_UTF8, 0, from, -1, to, tolen,
1221 NULL, NULL);
1222 /* A zero return is failure */
1223 if (result <= 0)
1224 result = -1;
1225 else
1226 {
1227 Assert(result <= tolen);
1228 /* Microsoft counts the zero terminator in the result */
1229 result--;
1230 }
1231 }
1232 else
1233#endif /* WIN32 */
1234 if (loc == (locale_t) 0)
1235 {
1236 /* Use wcstombs directly for the default locale */
1237 result = wcstombs(to, from, tolen);
1238 }
1239 else
1240 {
1241 /* Use wcstombs_l for nondefault locales */
1242 result = wcstombs_l(to, from, tolen, loc);
1243 }
1244
1245 return result;
1246}
static size_t wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)

References Assert, fb(), GetDatabaseEncoding(), locale_t, PG_UTF8, result, and wcstombs_l().

Referenced by set_backtrace(), strlower_libc_mb(), strtitle_libc_mb(), and strupper_libc_mb().

Variable Documentation

◆ icu_validation_level

PGDLLIMPORT int icu_validation_level
extern

Definition at line 92 of file pg_locale.c.

Referenced by createdb(), DefineCollation(), and icu_validate_locale().

◆ locale_messages

PGDLLIMPORT char* locale_messages
extern

Definition at line 87 of file pg_locale.c.

◆ locale_monetary

PGDLLIMPORT char* locale_monetary
extern

Definition at line 88 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_numeric

PGDLLIMPORT char* locale_numeric
extern

Definition at line 89 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_time

PGDLLIMPORT char* locale_time
extern

Definition at line 90 of file pg_locale.c.

Referenced by cache_locale_time().

◆ localized_abbrev_days

PGDLLIMPORT char* localized_abbrev_days[]
extern

Definition at line 101 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_abbrev_months

PGDLLIMPORT char* localized_abbrev_months[]
extern

Definition at line 103 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_full_days

PGDLLIMPORT char* localized_full_days[]
extern

Definition at line 102 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_full_months

PGDLLIMPORT char* localized_full_months[]
extern

Definition at line 104 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().