PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_locale.c File Reference
#include "postgres.h"
#include <time.h>
#include "access/htup_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_database.h"
#include "common/hashfn.h"
#include "common/string.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/guc_hooks.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/pg_locale_c.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
#include "lib/simplehash.h"
Include dependency graph for pg_locale.c:

Go to the source code of this file.

Data Structures

struct  collation_cache_entry
 

Macros

#define PGLOCALE_SUPPORT_ERROR(provider)    elog(ERROR, "unsupported collprovider for %s: %c", __func__, provider)
 
#define TEXTBUFLEN   1024
 
#define MAX_L10N_DATA   80
 
#define SH_PREFIX   collation_cache
 
#define SH_ELEMENT_TYPE   collation_cache_entry
 
#define SH_KEY_TYPE   Oid
 
#define SH_KEY   collid
 
#define SH_HASH_KEY(tb, key)   murmurhash32((uint32) key)
 
#define SH_EQUAL(tb, a, b)   (a == b)
 
#define SH_GET_HASH(tb, a)   a->hash
 
#define SH_SCOPE   static inline
 
#define SH_STORE_HASH
 
#define SH_DECLARE
 
#define SH_DEFINE
 

Functions

pg_locale_t create_pg_locale_builtin (Oid collid, MemoryContext context)
 
charget_collation_actual_version_builtin (const char *collcollate)
 
pg_locale_t create_pg_locale_icu (Oid collid, MemoryContext context)
 
pg_locale_t create_pg_locale_libc (Oid collid, MemoryContext context)
 
charget_collation_actual_version_libc (const char *collcollate)
 
charpg_perm_setlocale (int category, const char *locale)
 
bool check_locale (int category, const char *locale, char **canonname)
 
bool check_locale_monetary (char **newval, void **extra, GucSource source)
 
void assign_locale_monetary (const char *newval, void *extra)
 
bool check_locale_numeric (char **newval, void **extra, GucSource source)
 
void assign_locale_numeric (const char *newval, void *extra)
 
bool check_locale_time (char **newval, void **extra, GucSource source)
 
void assign_locale_time (const char *newval, void *extra)
 
bool check_locale_messages (char **newval, void **extra, GucSource source)
 
void assign_locale_messages (const char *newval, void *extra)
 
static void free_struct_lconv (struct lconv *s)
 
static bool struct_lconv_is_valid (struct lconv *s)
 
static void db_encoding_convert (int encoding, char **str)
 
struct lconvPGLC_localeconv (void)
 
static void cache_single_string (char **dst, const char *src, int encoding)
 
void cache_locale_time (void)
 
static pg_locale_t create_pg_locale (Oid collid, MemoryContext context)
 
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)
 
static size_t strlower_c (char *dst, size_t dstsize, const char *src, size_t srclen)
 
static size_t strtitle_c (char *dst, size_t dstsize, const char *src, size_t srclen)
 
static size_t strupper_c (char *dst, size_t dstsize, const char *src, size_t srclen)
 
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)
 
charicu_language_tag (const char *loc_str, int elevel)
 
void icu_validate_locale (const char *loc_str)
 

Variables

charlocale_messages
 
charlocale_monetary
 
charlocale_numeric
 
charlocale_time
 
int icu_validation_level = WARNING
 
charlocalized_abbrev_days [7+1]
 
charlocalized_full_days [7+1]
 
charlocalized_abbrev_months [12+1]
 
charlocalized_full_months [12+1]
 
static pg_locale_t default_locale = NULL
 
static bool CurrentLocaleConvValid = false
 
static bool CurrentLCTimeValid = false
 
static struct pg_locale_struct c_locale
 
static MemoryContext CollationCacheContext = NULL
 
static collation_cache_hashCollationCache = NULL
 
static Oid last_collation_cache_oid = InvalidOid
 
static pg_locale_t last_collation_cache_locale = NULL
 

Macro Definition Documentation

◆ MAX_L10N_DATA

#define MAX_L10N_DATA   80

Definition at line 69 of file pg_locale.c.

◆ PGLOCALE_SUPPORT_ERROR

#define PGLOCALE_SUPPORT_ERROR (   provider)     elog(ERROR, "unsupported collprovider for %s: %c", __func__, provider)

Definition at line 60 of file pg_locale.c.

61 : %c", __func__, provider)
char * c

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 139 of file pg_locale.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 140 of file pg_locale.c.

◆ SH_ELEMENT_TYPE

#define SH_ELEMENT_TYPE   collation_cache_entry

Definition at line 131 of file pg_locale.c.

◆ SH_EQUAL

#define SH_EQUAL (   tb,
  a,
  b 
)    (a == b)

Definition at line 135 of file pg_locale.c.

◆ SH_GET_HASH

#define SH_GET_HASH (   tb,
  a 
)    a->hash

Definition at line 136 of file pg_locale.c.

◆ SH_HASH_KEY

#define SH_HASH_KEY (   tb,
  key 
)    murmurhash32((uint32) key)

Definition at line 134 of file pg_locale.c.

◆ SH_KEY

#define SH_KEY   collid

Definition at line 133 of file pg_locale.c.

◆ SH_KEY_TYPE

#define SH_KEY_TYPE   Oid

Definition at line 132 of file pg_locale.c.

◆ SH_PREFIX

#define SH_PREFIX   collation_cache

Definition at line 130 of file pg_locale.c.

◆ SH_SCOPE

#define SH_SCOPE   static inline

Definition at line 137 of file pg_locale.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 138 of file pg_locale.c.

◆ TEXTBUFLEN

#define TEXTBUFLEN   1024

Definition at line 67 of file pg_locale.c.

Function Documentation

◆ assign_locale_messages()

void assign_locale_messages ( const char newval,
void extra 
)

Definition at line 409 of file pg_locale.c.

410{
411 /*
412 * LC_MESSAGES category does not exist everywhere, but accept it anyway.
413 * We ignore failure, as per comment above.
414 */
415#ifdef LC_MESSAGES
417#endif
418}
#define newval
char * pg_perm_setlocale(int category, const char *locale)
Definition pg_locale.c:172
static int fb(int x)

References fb(), newval, and pg_perm_setlocale().

◆ assign_locale_monetary()

void assign_locale_monetary ( const char newval,
void extra 
)

Definition at line 346 of file pg_locale.c.

347{
349}
static bool CurrentLocaleConvValid
Definition pg_locale.c:109

References CurrentLocaleConvValid.

◆ assign_locale_numeric()

void assign_locale_numeric ( const char newval,
void extra 
)

Definition at line 358 of file pg_locale.c.

359{
361}

References CurrentLocaleConvValid.

◆ assign_locale_time()

void assign_locale_time ( const char newval,
void extra 
)

Definition at line 370 of file pg_locale.c.

371{
372 CurrentLCTimeValid = false;
373}
static bool CurrentLCTimeValid
Definition pg_locale.c:110

References CurrentLCTimeValid.

◆ builtin_locale_encoding()

int builtin_locale_encoding ( const char locale)

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

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 
)

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  )

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
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().

◆ cache_single_string()

static void cache_single_string ( char **  dst,
const char src,
int  encoding 
)
static

Definition at line 679 of file pg_locale.c.

680{
681 char *ptr;
682 char *olddst;
683
684 /* Convert the string to the database encoding, or validate it's OK */
685 ptr = pg_any_to_server(src, strlen(src), encoding);
686
687 /* Store the string in long-lived storage, replacing any previous value */
688 olddst = *dst;
690 if (olddst)
691 pfree(olddst);
692
693 /* Might as well clean up any palloc'd conversion result, too */
694 if (ptr != src)
695 pfree(ptr);
696}
char * pg_any_to_server(const char *s, int len, int encoding)
Definition mbutils.c:687
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition mcxt.c:1897
void pfree(void *pointer)
Definition mcxt.c:1619
MemoryContext TopMemoryContext
Definition mcxt.c:167

References encoding, fb(), MemoryContextStrdup(), pfree(), pg_any_to_server(), and TopMemoryContext.

Referenced by cache_locale_time().

◆ check_locale()

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

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
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().

◆ check_locale_messages()

bool check_locale_messages ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 386 of file pg_locale.c.

387{
388 if (**newval == '\0')
389 {
390 if (source == PGC_S_DEFAULT)
391 return true;
392 else
393 return false;
394 }
395
396 /*
397 * LC_MESSAGES category does not exist everywhere, but accept it anyway
398 *
399 * On Windows, we can't even check the value, so accept blindly
400 */
401#if defined(LC_MESSAGES) && !defined(WIN32)
403#else
404 return true;
405#endif
406}
@ PGC_S_DEFAULT
Definition guc.h:113
bool check_locale(int category, const char *locale, char **canonname)
Definition pg_locale.c:275
static rewind_source * source
Definition pg_rewind.c:89

References check_locale(), fb(), newval, PGC_S_DEFAULT, and source.

◆ check_locale_monetary()

bool check_locale_monetary ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 340 of file pg_locale.c.

341{
343}

References check_locale(), fb(), and newval.

◆ check_locale_numeric()

bool check_locale_numeric ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 352 of file pg_locale.c.

353{
355}

References check_locale(), fb(), and newval.

◆ check_locale_time()

bool check_locale_time ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 364 of file pg_locale.c.

365{
366 return check_locale(LC_TIME, *newval, NULL);
367}

References check_locale(), fb(), and newval.

◆ create_pg_locale()

static pg_locale_t create_pg_locale ( Oid  collid,
MemoryContext  context 
)
static

Definition at line 1049 of file pg_locale.c.

1050{
1051 HeapTuple tp;
1054 Datum datum;
1055 bool isnull;
1056
1058 if (!HeapTupleIsValid(tp))
1059 elog(ERROR, "cache lookup failed for collation %u", collid);
1061
1062 if (collform->collprovider == COLLPROVIDER_BUILTIN)
1064 else if (collform->collprovider == COLLPROVIDER_ICU)
1066 else if (collform->collprovider == COLLPROVIDER_LIBC)
1068 else
1069 /* shouldn't happen */
1070 PGLOCALE_SUPPORT_ERROR(collform->collprovider);
1071
1072 result->is_default = false;
1073
1074 Assert((result->collate_is_c && result->collate == NULL) ||
1075 (!result->collate_is_c && result->collate != NULL));
1076
1077 Assert((result->ctype_is_c && result->ctype == NULL) ||
1078 (!result->ctype_is_c && result->ctype != NULL));
1079
1081 &isnull);
1082 if (!isnull)
1083 {
1084 char *actual_versionstr;
1085 char *collversionstr;
1086
1088
1089 if (collform->collprovider == COLLPROVIDER_LIBC)
1091 else
1093
1095 TextDatumGetCString(datum));
1096 if (!actual_versionstr)
1097 {
1098 /*
1099 * This could happen when specifying a version in CREATE COLLATION
1100 * but the provider does not support versioning, or manually
1101 * creating a mess in the catalogs.
1102 */
1103 ereport(ERROR,
1104 (errmsg("collation \"%s\" has no actual version, but a version was recorded",
1105 NameStr(collform->collname))));
1106 }
1107
1110 (errmsg("collation \"%s\" has version mismatch",
1111 NameStr(collform->collname)),
1112 errdetail("The collation in the database was created using version %s, "
1113 "but the operating system provides version %s.",
1115 errhint("Rebuild all objects affected by this collation and run "
1116 "ALTER COLLATION %s REFRESH VERSION, "
1117 "or build PostgreSQL with the right library version.",
1119 NameStr(collform->collname)))));
1120 }
1121
1122 ReleaseSysCache(tp);
1123
1124 return result;
1125}
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:835
#define Assert(condition)
Definition c.h:943
uint32 result
Oid collid
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3599
END_CATALOG_STRUCT typedef FormData_pg_collation * Form_pg_collation
pg_locale_t create_pg_locale_libc(Oid collid, MemoryContext context)
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition pg_locale.c:1247
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 Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References Assert, collid, create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), elog, ereport, errdetail(), errhint(), errmsg, ERROR, fb(), Form_pg_collation, get_collation_actual_version(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, NameStr, ObjectIdGetDatum(), PGLOCALE_SUPPORT_ERROR, quote_qualified_identifier(), ReleaseSysCache(), result, SearchSysCache1(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), TextDatumGetCString, and WARNING.

Referenced by pg_newlocale_from_collation().

◆ create_pg_locale_builtin()

pg_locale_t create_pg_locale_builtin ( Oid  collid,
MemoryContext  context 
)
extern

Definition at line 228 of file pg_locale_builtin.c.

229{
230 const char *locstr;
232
234 {
235 HeapTuple tp;
236 Datum datum;
237
239 if (!HeapTupleIsValid(tp))
240 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
244 ReleaseSysCache(tp);
245 }
246 else
247 {
248 HeapTuple tp;
249 Datum datum;
250
252 if (!HeapTupleIsValid(tp))
253 elog(ERROR, "cache lookup failed for collation %u", collid);
257 ReleaseSysCache(tp);
258 }
259
261
262 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
263
264 result->builtin.locale = MemoryContextStrdup(context, locstr);
265 result->builtin.casemap_full = (strcmp(locstr, "PG_UNICODE_FAST") == 0);
266 result->deterministic = true;
267 result->collate_is_c = true;
268 result->ctype_is_c = (strcmp(locstr, "C") == 0);
269 if (!result->ctype_is_c)
271
272 return result;
273}
Oid MyDatabaseId
Definition globals.c:96
int GetDatabaseEncoding(void)
Definition mbutils.c:1389
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1269
const char * builtin_validate_locale(int encoding, const char *locale)
Definition pg_locale.c:1685
static const struct ctype_methods ctype_methods_builtin

References builtin_validate_locale(), collid, ctype_methods_builtin, elog, ERROR, fb(), GetDatabaseEncoding(), HeapTupleIsValid, MemoryContextAllocZero(), MemoryContextStrdup(), MyDatabaseId, ObjectIdGetDatum(), ReleaseSysCache(), result, SearchSysCache1(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ create_pg_locale_icu()

pg_locale_t create_pg_locale_icu ( Oid  collid,
MemoryContext  context 
)
extern

Definition at line 322 of file pg_locale_icu.c.

323{
324#ifdef USE_ICU
325 bool deterministic;
326 const char *iculocstr;
327 const char *icurules = NULL;
329 locale_t loc = (locale_t) 0;
331
333 {
334 HeapTuple tp;
335 Datum datum;
336 bool isnull;
337
339 if (!HeapTupleIsValid(tp))
340 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
341
342 /* default database collation is always deterministic */
343 deterministic = true;
347 datum = SysCacheGetAttr(DATABASEOID, tp,
349 if (!isnull)
351
352 /* libc only needed for default locale and single-byte encoding */
354 {
355 const char *ctype;
356
359 ctype = TextDatumGetCString(datum);
360
361 loc = make_libc_ctype_locale(ctype);
362 }
363
364 ReleaseSysCache(tp);
365 }
366 else
367 {
369 HeapTuple tp;
370 Datum datum;
371 bool isnull;
372
374 if (!HeapTupleIsValid(tp))
375 elog(ERROR, "cache lookup failed for collation %u", collid);
377 deterministic = collform->collisdeterministic;
381 datum = SysCacheGetAttr(COLLOID, tp,
383 if (!isnull)
385
386 ReleaseSysCache(tp);
387 }
388
390
391 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
392 result->icu.locale = MemoryContextStrdup(context, iculocstr);
393 result->icu.ucol = collator;
394 result->icu.lt = loc;
395 result->deterministic = deterministic;
396 result->collate_is_c = false;
397 result->ctype_is_c = false;
399 {
400 result->icu.ucasemap = pg_ucasemap_open(iculocstr);
403 }
404 else
405 {
406 result->collate = &collate_methods_icu;
407 result->ctype = &ctype_methods_icu;
408 }
409
410 return result;
411#else
412 /* could get here if a collation was created by a build with ICU */
415 errmsg("ICU is not supported in this build")));
416
417 return NULL;
418#endif
419}
int pg_database_encoding_max_length(void)
Definition mbutils.c:1673

References collid, elog, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_collation, GetDatabaseEncoding(), GETSTRUCT(), HeapTupleIsValid, locale_t, MemoryContextAllocZero(), MemoryContextStrdup(), MyDatabaseId, ObjectIdGetDatum(), pg_database_encoding_max_length(), PG_UTF8, ReleaseSysCache(), result, SearchSysCache1(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ create_pg_locale_libc()

pg_locale_t create_pg_locale_libc ( Oid  collid,
MemoryContext  context 
)
extern

Definition at line 734 of file pg_locale_libc.c.

735{
736 const char *collate;
737 const char *ctype;
738 locale_t loc;
740
742 {
743 HeapTuple tp;
744 Datum datum;
745
747 if (!HeapTupleIsValid(tp))
748 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
751 collate = TextDatumGetCString(datum);
754 ctype = TextDatumGetCString(datum);
755
756 ReleaseSysCache(tp);
757 }
758 else
759 {
760 HeapTuple tp;
761 Datum datum;
762
764 if (!HeapTupleIsValid(tp))
765 elog(ERROR, "cache lookup failed for collation %u", collid);
766
769 collate = TextDatumGetCString(datum);
772 ctype = TextDatumGetCString(datum);
773
774 ReleaseSysCache(tp);
775 }
776
777
778 loc = make_libc_collator(collate, ctype);
779
780 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
781 result->deterministic = true;
782 result->collate_is_c = (strcmp(collate, "C") == 0) ||
783 (strcmp(collate, "POSIX") == 0);
784 result->ctype_is_c = (strcmp(ctype, "C") == 0) ||
785 (strcmp(ctype, "POSIX") == 0);
786 result->lt = loc;
787 if (!result->collate_is_c)
788 {
789#ifdef WIN32
792 else
793#endif
794 result->collate = &collate_methods_libc;
795 }
796 if (!result->ctype_is_c)
797 {
800 else if (pg_database_encoding_max_length() > 1)
802 else
804 }
805
806 return result;
807}
static const struct ctype_methods ctype_methods_libc_other_mb
static const struct ctype_methods ctype_methods_libc_utf8
static locale_t make_libc_collator(const char *collate, const char *ctype)
static const struct collate_methods collate_methods_libc
static const struct ctype_methods ctype_methods_libc_sb

References collate_methods_libc, collid, ctype_methods_libc_other_mb, ctype_methods_libc_sb, ctype_methods_libc_utf8, elog, ERROR, fb(), GetDatabaseEncoding(), HeapTupleIsValid, locale_t, make_libc_collator(), MemoryContextAllocZero(), MyDatabaseId, ObjectIdGetDatum(), pg_database_encoding_max_length(), PG_UTF8, ReleaseSysCache(), result, SearchSysCache1(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ db_encoding_convert()

static void db_encoding_convert ( int  encoding,
char **  str 
)
static

Definition at line 476 of file pg_locale.c.

477{
478 char *pstr;
479 char *mstr;
480
481 /* convert the string to the database encoding */
483 if (pstr == *str)
484 return; /* no conversion happened */
485
486 /* need it malloc'd not palloc'd */
487 mstr = strdup(pstr);
488 if (mstr == NULL)
491 errmsg("out of memory")));
492
493 /* replace old string */
494 free(*str);
495 *str = mstr;
496
497 pfree(pstr);
498}
const char * str
#define free(a)

References encoding, ereport, errcode(), errmsg, ERROR, fb(), free, pfree(), pg_any_to_server(), and str.

Referenced by PGLC_localeconv().

◆ free_struct_lconv()

static void free_struct_lconv ( struct lconv s)
static

Definition at line 426 of file pg_locale.c.

427{
428 free(s->decimal_point);
429 free(s->thousands_sep);
430 free(s->grouping);
431 free(s->int_curr_symbol);
432 free(s->currency_symbol);
433 free(s->mon_decimal_point);
434 free(s->mon_thousands_sep);
435 free(s->mon_grouping);
436 free(s->positive_sign);
437 free(s->negative_sign);
438}

References free.

Referenced by PGLC_localeconv().

◆ get_collation_actual_version()

char * get_collation_actual_version ( char  collprovider,
const char collcollate 
)

◆ get_collation_actual_version_builtin()

char * get_collation_actual_version_builtin ( const char collcollate)
extern

Definition at line 276 of file pg_locale_builtin.c.

277{
278 /*
279 * The only two supported locales (C and C.UTF-8) are both based on memcmp
280 * and are not expected to change, but track the version anyway.
281 *
282 * Note that the character semantics may change for some locales, but the
283 * collation version only tracks changes to sort order.
284 */
285 if (strcmp(collcollate, "C") == 0)
286 return "1";
287 else if (strcmp(collcollate, "C.UTF-8") == 0)
288 return "1";
289 else if (strcmp(collcollate, "PG_UNICODE_FAST") == 0)
290 return "1";
291 else
294 errmsg("invalid locale name \"%s\" for builtin provider",
295 collcollate)));
296
297 return NULL; /* keep compiler quiet */
298}

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

Referenced by get_collation_actual_version().

◆ get_collation_actual_version_libc()

char * get_collation_actual_version_libc ( const char collcollate)
extern

Definition at line 973 of file pg_locale_libc.c.

974{
975 char *collversion = NULL;
976
977 if (pg_strcasecmp("C", collcollate) != 0 &&
978 pg_strncasecmp("C.", collcollate, 2) != 0 &&
979 pg_strcasecmp("POSIX", collcollate) != 0)
980 {
981#if defined(__GLIBC__)
982 /* Use the glibc version because we don't have anything better. */
984#elif defined(LC_VERSION_MASK)
985 locale_t loc;
986
987 /* Look up FreeBSD collation version. */
989 if (loc)
990 {
993 freelocale(loc);
994 }
995 else
997 (errmsg("could not load locale \"%s\"", collcollate)));
998#elif defined(WIN32)
999 /*
1000 * If we are targeting Windows Vista and above, we can ask for a name
1001 * given a collation name (earlier versions required a location code
1002 * that we don't have).
1003 */
1004 NLSVERSIONINFOEX version = {sizeof(NLSVERSIONINFOEX)};
1006
1010 {
1011 /*
1012 * GetNLSVersionEx() wants a language tag such as "en-US", not a
1013 * locale name like "English_United States.1252". Until those
1014 * values can be prevented from entering the system, or 100%
1015 * reliably converted to the more useful tag format, tolerate the
1016 * resulting error and report that we have no version data.
1017 */
1019 return NULL;
1020
1021 ereport(ERROR,
1022 (errmsg("could not get collation version for locale \"%s\": error code %lu",
1024 GetLastError())));
1025 }
1026 collversion = psprintf("%lu.%lu,%lu.%lu",
1027 (version.dwNLSVersion >> 8) & 0xFFFF,
1028 version.dwNLSVersion & 0xFF,
1029 (version.dwDefinedVersion >> 8) & 0xFFFF,
1030 version.dwDefinedVersion & 0xFF);
1031#endif
1032 }
1033
1034 return collversion;
1035}
int pg_strcasecmp(const char *s1, const char *s2)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
char * psprintf(const char *fmt,...)
Definition psprintf.c:43

References ereport, errmsg, ERROR, fb(), locale_t, pg_strcasecmp(), pg_strncasecmp(), psprintf(), and pstrdup().

Referenced by get_collation_actual_version().

◆ icu_language_tag()

char * icu_language_tag ( const char loc_str,
int  elevel 
)

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)

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}
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  )

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}
END_CATALOG_STRUCT typedef FormData_pg_database * Form_pg_database
static pg_locale_t default_locale
Definition pg_locale.c:106

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  )

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 
)

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  )

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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)

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
#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 
)

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
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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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)

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 
)

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)

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 
)

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 
)

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  )

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 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().

◆ strlower_c()

static size_t strlower_c ( char dst,
size_t  dstsize,
const char src,
size_t  srclen 
)
static

Definition at line 1265 of file pg_locale.c.

1266{
1267 int i;
1268
1269 for (i = 0; i < srclen && i < dstsize; i++)
1270 dst[i] = pg_ascii_tolower(src[i]);
1271 if (i < dstsize)
1272 dst[i] = '\0';
1273 return srclen;
1274}

References fb(), i, and pg_ascii_tolower().

Referenced by pg_downcase_ident(), pg_strfold(), and pg_strlower().

◆ strtitle_c()

static size_t strtitle_c ( char dst,
size_t  dstsize,
const char src,
size_t  srclen 
)
static

Definition at line 1278 of file pg_locale.c.

1279{
1280 bool wasalnum = false;
1281 int i;
1282
1283 for (i = 0; i < srclen && i < dstsize; i++)
1284 {
1285 char c = src[i];
1286
1287 if (wasalnum)
1288 dst[i] = pg_ascii_tolower(c);
1289 else
1290 dst[i] = pg_ascii_toupper(c);
1291
1292 wasalnum = ((c >= '0' && c <= '9') ||
1293 (c >= 'A' && c <= 'Z') ||
1294 (c >= 'a' && c <= 'z'));
1295 }
1296 if (i < dstsize)
1297 dst[i] = '\0';
1298 return srclen;
1299}

References fb(), i, pg_ascii_tolower(), and pg_ascii_toupper().

Referenced by pg_strtitle().

◆ struct_lconv_is_valid()

static bool struct_lconv_is_valid ( struct lconv s)
static

Definition at line 445 of file pg_locale.c.

446{
447 if (s->decimal_point == NULL)
448 return false;
449 if (s->thousands_sep == NULL)
450 return false;
451 if (s->grouping == NULL)
452 return false;
453 if (s->int_curr_symbol == NULL)
454 return false;
455 if (s->currency_symbol == NULL)
456 return false;
457 if (s->mon_decimal_point == NULL)
458 return false;
459 if (s->mon_thousands_sep == NULL)
460 return false;
461 if (s->mon_grouping == NULL)
462 return false;
463 if (s->positive_sign == NULL)
464 return false;
465 if (s->negative_sign == NULL)
466 return false;
467 return true;
468}

References fb().

Referenced by PGLC_localeconv().

◆ strupper_c()

static size_t strupper_c ( char dst,
size_t  dstsize,
const char src,
size_t  srclen 
)
static

Definition at line 1303 of file pg_locale.c.

1304{
1305 int i;
1306
1307 for (i = 0; i < srclen && i < dstsize; i++)
1308 dst[i] = pg_ascii_toupper(src[i]);
1309 if (i < dstsize)
1310 dst[i] = '\0';
1311 return srclen;
1312}

References fb(), i, and pg_ascii_toupper().

Referenced by pg_strupper().

Variable Documentation

◆ c_locale

struct pg_locale_struct c_locale
static
Initial value:
= {
.deterministic = true,
.collate_is_c = true,
.ctype_is_c = true,
}

Definition at line 112 of file pg_locale.c.

112 {
113 .deterministic = true,
114 .collate_is_c = true,
115 .ctype_is_c = true,
116};

Referenced by pg_newlocale_from_collation().

◆ CollationCache

collation_cache_hash* CollationCache = NULL
static

Definition at line 144 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ CollationCacheContext

MemoryContext CollationCacheContext = NULL
static

Definition at line 143 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ CurrentLCTimeValid

bool CurrentLCTimeValid = false
static

Definition at line 110 of file pg_locale.c.

Referenced by assign_locale_time(), and cache_locale_time().

◆ CurrentLocaleConvValid

bool CurrentLocaleConvValid = false
static

Definition at line 109 of file pg_locale.c.

Referenced by assign_locale_monetary(), assign_locale_numeric(), and PGLC_localeconv().

◆ default_locale

pg_locale_t default_locale = NULL
static

◆ icu_validation_level

int icu_validation_level = WARNING

Definition at line 92 of file pg_locale.c.

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

◆ last_collation_cache_locale

pg_locale_t last_collation_cache_locale = NULL
static

Definition at line 151 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ last_collation_cache_oid

Oid last_collation_cache_oid = InvalidOid
static

Definition at line 150 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ locale_messages

char* locale_messages

Definition at line 87 of file pg_locale.c.

◆ locale_monetary

char* locale_monetary

Definition at line 88 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_numeric

char* locale_numeric

Definition at line 89 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_time

char* locale_time

Definition at line 90 of file pg_locale.c.

Referenced by cache_locale_time().

◆ localized_abbrev_days

char* localized_abbrev_days[7+1]

Definition at line 101 of file pg_locale.c.

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

◆ localized_abbrev_months

char* localized_abbrev_months[12+1]

Definition at line 103 of file pg_locale.c.

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

◆ localized_full_days

char* localized_full_days[7+1]

Definition at line 102 of file pg_locale.c.

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

◆ localized_full_months

char* localized_full_months[12+1]

Definition at line 104 of file pg_locale.c.

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