PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_locale_builtin.c File Reference
#include "postgres.h"
#include "catalog/pg_database.h"
#include "catalog/pg_collation.h"
#include "common/unicode_case.h"
#include "common/unicode_category.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/pg_locale.h"
#include "utils/syscache.h"
Include dependency graph for pg_locale_builtin.c:

Go to the source code of this file.

Data Structures

struct  WordBoundaryState
 

Functions

pg_locale_t create_pg_locale_builtin (Oid collid, MemoryContext context)
 
charget_collation_actual_version_builtin (const char *collcollate)
 
static char32_t to_char32 (pg_wchar wc)
 
static pg_wchar to_pg_wchar (char32_t c32)
 
static size_t initcap_wbnext (void *state)
 
static size_t strlower_builtin (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strtitle_builtin (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strupper_builtin (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strfold_builtin (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static bool wc_isdigit_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isalpha_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isalnum_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isupper_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_islower_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isgraph_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isprint_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_ispunct_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isspace_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isxdigit_builtin (pg_wchar wc, pg_locale_t locale)
 
static bool wc_iscased_builtin (pg_wchar wc, pg_locale_t locale)
 
static pg_wchar wc_toupper_builtin (pg_wchar wc, pg_locale_t locale)
 
static pg_wchar wc_tolower_builtin (pg_wchar wc, pg_locale_t locale)
 

Variables

static const struct ctype_methods ctype_methods_builtin
 

Function Documentation

◆ 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}
#define TextDatumGetCString(d)
Definition builtins.h:99
uint32 result
Oid collid
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
Oid MyDatabaseId
Definition globals.c:96
#define HeapTupleIsValid(tuple)
Definition htup.h:78
int GetDatabaseEncoding(void)
Definition mbutils.c:1389
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition mcxt.c:1897
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
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
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

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

◆ 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}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
static char * errmsg

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

Referenced by get_collation_actual_version().

◆ initcap_wbnext()

static size_t initcap_wbnext ( void state)
static

Definition at line 59 of file pg_locale_builtin.c.

60{
62
63 while (wbstate->offset < wbstate->len)
64 {
65 char32_t u = utf8_to_unicode((const unsigned char *) wbstate->str +
66 wbstate->offset);
67 bool curr_alnum = pg_u_isalnum(u, wbstate->posix);
68
69 if (!wbstate->init || curr_alnum != wbstate->prev_alnum)
70 {
71 size_t prev_offset = wbstate->offset;
72
73 wbstate->init = true;
74 wbstate->offset += unicode_utf8len(u);
75 wbstate->prev_alnum = curr_alnum;
76 return prev_offset;
77 }
78
79 wbstate->offset += unicode_utf8len(u);
80 }
81
82 return wbstate->len;
83}
static char32_t utf8_to_unicode(const unsigned char *c)
Definition mbprint.c:53
static int unicode_utf8len(char32_t c)
Definition pg_wchar.h:460
bool pg_u_isalnum(char32_t code, bool posix)

References fb(), pg_u_isalnum(), unicode_utf8len(), and utf8_to_unicode().

Referenced by strtitle_builtin().

◆ strfold_builtin()

static size_t strfold_builtin ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 120 of file pg_locale_builtin.c.

122{
123 return unicode_strfold(dest, destsize, src, srclen,
124 locale->builtin.casemap_full);
125}
struct pg_locale_struct::@172::@174 builtin
size_t unicode_strfold(char *dst, size_t dstsize, const char *src, size_t srclen, bool full)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, fb(), and unicode_strfold().

◆ strlower_builtin()

static size_t strlower_builtin ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 86 of file pg_locale_builtin.c.

88{
89 return unicode_strlower(dest, destsize, src, srclen,
90 locale->builtin.casemap_full);
91}
size_t unicode_strlower(char *dst, size_t dstsize, const char *src, size_t srclen, bool full)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, fb(), and unicode_strlower().

◆ strtitle_builtin()

static size_t strtitle_builtin ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 94 of file pg_locale_builtin.c.

96{
97 struct WordBoundaryState wbstate = {
98 .str = src,
99 .len = srclen,
100 .offset = 0,
101 .posix = !locale->builtin.casemap_full,
102 .init = false,
103 .prev_alnum = false,
104 };
105
106 return unicode_strtitle(dest, destsize, src, srclen,
107 locale->builtin.casemap_full,
109}
static size_t initcap_wbnext(void *state)
size_t unicode_strtitle(char *dst, size_t dstsize, const char *src, size_t srclen, bool full, WordBoundaryNext wbnext, void *wbstate)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, fb(), initcap_wbnext(), WordBoundaryState::str, and unicode_strtitle().

◆ strupper_builtin()

static size_t strupper_builtin ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 112 of file pg_locale_builtin.c.

114{
115 return unicode_strupper(dest, destsize, src, srclen,
116 locale->builtin.casemap_full);
117}
size_t unicode_strupper(char *dst, size_t dstsize, const char *src, size_t srclen, bool full)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, fb(), and unicode_strupper().

◆ to_char32()

◆ to_pg_wchar()

static pg_wchar to_pg_wchar ( char32_t  c32)
inlinestatic

Definition at line 48 of file pg_locale_builtin.c.

49{
51 return (pg_wchar) c32;
52}
unsigned int pg_wchar
Definition mbprint.c:31

References Assert, fb(), GetDatabaseEncoding(), and PG_UTF8.

Referenced by wc_tolower_builtin(), and wc_toupper_builtin().

◆ wc_isalnum_builtin()

static bool wc_isalnum_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 140 of file pg_locale_builtin.c.

141{
142 return pg_u_isalnum(to_char32(wc), !locale->builtin.casemap_full);
143}
static char32_t to_char32(pg_wchar wc)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, pg_u_isalnum(), and to_char32().

◆ wc_isalpha_builtin()

static bool wc_isalpha_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 134 of file pg_locale_builtin.c.

135{
136 return pg_u_isalpha(to_char32(wc));
137}
bool pg_u_isalpha(char32_t code)

References pg_u_isalpha(), and to_char32().

◆ wc_iscased_builtin()

static bool wc_iscased_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 188 of file pg_locale_builtin.c.

189{
190 return pg_u_prop_cased(to_char32(wc));
191}
bool pg_u_prop_cased(char32_t code)

References pg_u_prop_cased(), and to_char32().

◆ wc_isdigit_builtin()

static bool wc_isdigit_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 128 of file pg_locale_builtin.c.

129{
130 return pg_u_isdigit(to_char32(wc), !locale->builtin.casemap_full);
131}
bool pg_u_isdigit(char32_t code, bool posix)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, pg_u_isdigit(), and to_char32().

◆ wc_isgraph_builtin()

static bool wc_isgraph_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 158 of file pg_locale_builtin.c.

159{
160 return pg_u_isgraph(to_char32(wc));
161}
bool pg_u_isgraph(char32_t code)

References pg_u_isgraph(), and to_char32().

◆ wc_islower_builtin()

static bool wc_islower_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 152 of file pg_locale_builtin.c.

153{
154 return pg_u_islower(to_char32(wc));
155}
bool pg_u_islower(char32_t code)

References pg_u_islower(), and to_char32().

◆ wc_isprint_builtin()

static bool wc_isprint_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 164 of file pg_locale_builtin.c.

165{
166 return pg_u_isprint(to_char32(wc));
167}
bool pg_u_isprint(char32_t code)

References pg_u_isprint(), and to_char32().

◆ wc_ispunct_builtin()

static bool wc_ispunct_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 170 of file pg_locale_builtin.c.

171{
172 return pg_u_ispunct(to_char32(wc), !locale->builtin.casemap_full);
173}
bool pg_u_ispunct(char32_t code, bool posix)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, pg_u_ispunct(), and to_char32().

◆ wc_isspace_builtin()

static bool wc_isspace_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 176 of file pg_locale_builtin.c.

177{
178 return pg_u_isspace(to_char32(wc));
179}
bool pg_u_isspace(char32_t code)

References pg_u_isspace(), and to_char32().

◆ wc_isupper_builtin()

static bool wc_isupper_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 146 of file pg_locale_builtin.c.

147{
148 return pg_u_isupper(to_char32(wc));
149}
bool pg_u_isupper(char32_t code)

References pg_u_isupper(), and to_char32().

◆ wc_isxdigit_builtin()

static bool wc_isxdigit_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 182 of file pg_locale_builtin.c.

183{
184 return pg_u_isxdigit(to_char32(wc), !locale->builtin.casemap_full);
185}
bool pg_u_isxdigit(char32_t code, bool posix)

References pg_locale_struct::builtin, pg_locale_struct::casemap_full, pg_u_isxdigit(), and to_char32().

◆ wc_tolower_builtin()

static pg_wchar wc_tolower_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 200 of file pg_locale_builtin.c.

201{
203}
static pg_wchar to_pg_wchar(char32_t c32)
char32_t unicode_lowercase_simple(char32_t code)

References to_char32(), to_pg_wchar(), and unicode_lowercase_simple().

◆ wc_toupper_builtin()

static pg_wchar wc_toupper_builtin ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 194 of file pg_locale_builtin.c.

195{
197}
char32_t unicode_uppercase_simple(char32_t code)

References to_char32(), to_pg_wchar(), and unicode_uppercase_simple().

Variable Documentation

◆ ctype_methods_builtin

const struct ctype_methods ctype_methods_builtin
static
Initial value:
= {
.strlower = strlower_builtin,
.strtitle = strtitle_builtin,
.strupper = strupper_builtin,
.strfold = strfold_builtin,
.downcase_ident = NULL,
.wc_isdigit = wc_isdigit_builtin,
.wc_isalpha = wc_isalpha_builtin,
.wc_isalnum = wc_isalnum_builtin,
.wc_isupper = wc_isupper_builtin,
.wc_islower = wc_islower_builtin,
.wc_isgraph = wc_isgraph_builtin,
.wc_isprint = wc_isprint_builtin,
.wc_ispunct = wc_ispunct_builtin,
.wc_isspace = wc_isspace_builtin,
.wc_isxdigit = wc_isxdigit_builtin,
.wc_iscased = wc_iscased_builtin,
.wc_tolower = wc_tolower_builtin,
.wc_toupper = wc_toupper_builtin,
}
static pg_wchar wc_toupper_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_isgraph_builtin(pg_wchar wc, pg_locale_t locale)
static size_t strtitle_builtin(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static pg_wchar wc_tolower_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_islower_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_isprint_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_ispunct_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_iscased_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_isdigit_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_isupper_builtin(pg_wchar wc, pg_locale_t locale)
static size_t strfold_builtin(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static bool wc_isspace_builtin(pg_wchar wc, pg_locale_t locale)
static size_t strlower_builtin(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static bool wc_isalpha_builtin(pg_wchar wc, pg_locale_t locale)
static size_t strupper_builtin(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static bool wc_isxdigit_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_isalnum_builtin(pg_wchar wc, pg_locale_t locale)

Definition at line 205 of file pg_locale_builtin.c.

205 {
206 .strlower = strlower_builtin,
207 .strtitle = strtitle_builtin,
208 .strupper = strupper_builtin,
209 .strfold = strfold_builtin,
210 /* uses plain ASCII semantics for historical reasons */
211 .downcase_ident = NULL,
212 .wc_isdigit = wc_isdigit_builtin,
213 .wc_isalpha = wc_isalpha_builtin,
214 .wc_isalnum = wc_isalnum_builtin,
215 .wc_isupper = wc_isupper_builtin,
216 .wc_islower = wc_islower_builtin,
217 .wc_isgraph = wc_isgraph_builtin,
218 .wc_isprint = wc_isprint_builtin,
219 .wc_ispunct = wc_ispunct_builtin,
220 .wc_isspace = wc_isspace_builtin,
221 .wc_isxdigit = wc_isxdigit_builtin,
222 .wc_iscased = wc_iscased_builtin,
223 .wc_tolower = wc_tolower_builtin,
224 .wc_toupper = wc_toupper_builtin,
225};

Referenced by create_pg_locale_builtin().