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, ssize_t srclen, pg_locale_t locale)
 
static size_t strtitle_builtin (char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
static size_t strupper_builtin (char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
static size_t strfold_builtin (char *dest, size_t destsize, const char *src, ssize_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 229 of file pg_locale_builtin.c.

230{
231 const char *locstr;
232 pg_locale_t result;
233
235 {
236 HeapTuple tp;
237 Datum datum;
238
240 if (!HeapTupleIsValid(tp))
241 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
245 ReleaseSysCache(tp);
246 }
247 else
248 {
249 HeapTuple tp;
250 Datum datum;
251
253 if (!HeapTupleIsValid(tp))
254 elog(ERROR, "cache lookup failed for collation %u", collid);
258 ReleaseSysCache(tp);
259 }
260
262
263 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
264
265 result->builtin.locale = MemoryContextStrdup(context, locstr);
266 result->builtin.casemap_full = (strcmp(locstr, "PG_UNICODE_FAST") == 0);
267 result->deterministic = true;
268 result->collate_is_c = true;
269 result->ctype_is_c = (strcmp(locstr, "C") == 0);
270 if (!result->ctype_is_c)
271 result->ctype = &ctype_methods_builtin;
272
273 return result;
274}
#define TextDatumGetCString(d)
Definition builtins.h:98
Oid collid
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
Oid MyDatabaseId
Definition globals.c:94
#define HeapTupleIsValid(tuple)
Definition htup.h:78
int GetDatabaseEncoding(void)
Definition mbutils.c:1264
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition mcxt.c:1768
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
const char * builtin_validate_locale(int encoding, const char *locale)
Definition pg_locale.c:1691
static const struct ctype_methods ctype_methods_builtin
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
const struct ctype_methods * ctype
Definition pg_locale.h:146
struct pg_locale_struct::@167::@169 builtin
const char * locale
Definition pg_locale.h:152
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:625

References pg_locale_struct::builtin, builtin_validate_locale(), pg_locale_struct::casemap_full, pg_locale_struct::collate_is_c, collid, pg_locale_struct::ctype, pg_locale_struct::ctype_is_c, ctype_methods_builtin, pg_locale_struct::deterministic, elog, ERROR, fb(), GetDatabaseEncoding(), HeapTupleIsValid, pg_locale_struct::locale, MemoryContextAllocZero(), MemoryContextStrdup(), MyDatabaseId, ObjectIdGetDatum(), ReleaseSysCache(), 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 277 of file pg_locale_builtin.c.

278{
279 /*
280 * The only two supported locales (C and C.UTF-8) are both based on memcmp
281 * and are not expected to change, but track the version anyway.
282 *
283 * Note that the character semantics may change for some locales, but the
284 * collation version only tracks changes to sort order.
285 */
286 if (strcmp(collcollate, "C") == 0)
287 return "1";
288 else if (strcmp(collcollate, "C.UTF-8") == 0)
289 return "1";
290 else if (strcmp(collcollate, "PG_UNICODE_FAST") == 0)
291 return "1";
292 else
295 errmsg("invalid locale name \"%s\" for builtin provider",
296 collcollate)));
297
298 return NULL; /* keep compiler quiet */
299}
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150

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 wbstate->str[wbstate->offset] != '\0')
65 {
66 char32_t u = utf8_to_unicode((const unsigned char *) wbstate->str +
67 wbstate->offset);
68 bool curr_alnum = pg_u_isalnum(u, wbstate->posix);
69
70 if (!wbstate->init || curr_alnum != wbstate->prev_alnum)
71 {
72 size_t prev_offset = wbstate->offset;
73
74 wbstate->init = true;
75 wbstate->offset += unicode_utf8len(u);
76 wbstate->prev_alnum = curr_alnum;
77 return prev_offset;
78 }
79
80 wbstate->offset += unicode_utf8len(u);
81 }
82
83 return wbstate->len;
84}
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:607
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,
ssize_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 121 of file pg_locale_builtin.c.

123{
124 return unicode_strfold(dest, destsize, src, srclen,
125 locale->builtin.casemap_full);
126}
size_t unicode_strfold(char *dst, size_t dstsize, const char *src, ssize_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,
ssize_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 87 of file pg_locale_builtin.c.

89{
90 return unicode_strlower(dest, destsize, src, srclen,
91 locale->builtin.casemap_full);
92}
size_t unicode_strlower(char *dst, size_t dstsize, const char *src, ssize_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,
ssize_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 95 of file pg_locale_builtin.c.

97{
98 struct WordBoundaryState wbstate = {
99 .str = src,
100 .len = srclen,
101 .offset = 0,
102 .posix = !locale->builtin.casemap_full,
103 .init = false,
104 .prev_alnum = false,
105 };
106
107 return unicode_strtitle(dest, destsize, src, srclen,
108 locale->builtin.casemap_full,
110}
static size_t initcap_wbnext(void *state)
size_t unicode_strtitle(char *dst, size_t dstsize, const char *src, ssize_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,
ssize_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 113 of file pg_locale_builtin.c.

115{
116 return unicode_strupper(dest, destsize, src, srclen,
117 locale->builtin.casemap_full);
118}
size_t unicode_strupper(char *dst, size_t dstsize, const char *src, ssize_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 141 of file pg_locale_builtin.c.

142{
143 return pg_u_isalnum(to_char32(wc), !locale->builtin.casemap_full);
144}
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 135 of file pg_locale_builtin.c.

136{
137 return pg_u_isalpha(to_char32(wc));
138}
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 189 of file pg_locale_builtin.c.

190{
191 return pg_u_prop_cased(to_char32(wc));
192}
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 129 of file pg_locale_builtin.c.

130{
131 return pg_u_isdigit(to_char32(wc), !locale->builtin.casemap_full);
132}
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 159 of file pg_locale_builtin.c.

160{
161 return pg_u_isgraph(to_char32(wc));
162}
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 153 of file pg_locale_builtin.c.

154{
155 return pg_u_islower(to_char32(wc));
156}
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 165 of file pg_locale_builtin.c.

166{
167 return pg_u_isprint(to_char32(wc));
168}
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 171 of file pg_locale_builtin.c.

172{
173 return pg_u_ispunct(to_char32(wc), !locale->builtin.casemap_full);
174}
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 177 of file pg_locale_builtin.c.

178{
179 return pg_u_isspace(to_char32(wc));
180}
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 147 of file pg_locale_builtin.c.

148{
149 return pg_u_isupper(to_char32(wc));
150}
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 183 of file pg_locale_builtin.c.

184{
185 return pg_u_isxdigit(to_char32(wc), !locale->builtin.casemap_full);
186}
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 201 of file pg_locale_builtin.c.

202{
204}
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 195 of file pg_locale_builtin.c.

196{
198}
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 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 size_t strupper_builtin(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
static size_t strlower_builtin(char *dest, size_t destsize, const char *src, ssize_t srclen, 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, ssize_t srclen, pg_locale_t locale)
static bool wc_isspace_builtin(pg_wchar wc, pg_locale_t locale)
static bool wc_isalpha_builtin(pg_wchar wc, 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)
static size_t strtitle_builtin(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)

Definition at line 206 of file pg_locale_builtin.c.

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

Referenced by create_pg_locale_builtin().