PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_wchar.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_wchar.h
4 * multibyte-character support
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/mb/pg_wchar.h
10 *
11 * NOTES
12 * This is used both by the backend and by frontends, but should not be
13 * included by libpq client programs. In particular, a libpq client
14 * should not assume that the encoding IDs used by the version of libpq
15 * it's linked to match up with the IDs declared here.
16 * To help prevent mistakes, relevant functions that are exported by
17 * libpq have a physically different name when being referenced
18 * statically.
19 *
20 *-------------------------------------------------------------------------
21 */
22#ifndef PG_WCHAR_H
23#define PG_WCHAR_H
24
25/*
26 * The pg_wchar type
27 */
28typedef unsigned int pg_wchar;
29
30/*
31 * Maximum byte length of multibyte characters in any backend encoding
32 */
33#define MAX_MULTIBYTE_CHAR_LEN 4
34
35/*
36 * various definitions for EUC
37 */
38#define SS2 0x8e /* single shift 2 (JIS0201) */
39#define SS3 0x8f /* single shift 3 (JIS0212) */
40
41/*
42 * EUC_TW planes
43 */
44#define LC_CNS11643_1 0x95 /* CNS 11643-1992 Plane 1 */
45#define LC_CNS11643_2 0x96 /* CNS 11643-1992 Plane 2 */
46#define LC_CNS11643_3 0xf6 /* CNS 11643-1992 Plane 3 */
47#define LC_CNS11643_4 0xf7 /* CNS 11643-1992 Plane 4 */
48#define LC_CNS11643_5 0xf8 /* CNS 11643-1992 Plane 5 */
49#define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */
50#define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */
51
52/*
53 * SJIS validation macros
54 */
55#define ISSJISHEAD(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc))
56#define ISSJISTAIL(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
57
58/*
59 * PostgreSQL encoding identifiers
60 *
61 * WARNING: If you add some encoding don't forget to update
62 * the pg_enc2name_tbl[] array (in src/common/encnames.c),
63 * the pg_enc2gettext_tbl[] array (in src/common/encnames.c) and
64 * the pg_wchar_table[] array (in src/common/wchar.c) and to check
65 * PG_ENCODING_BE_LAST macro.
66 *
67 * PG_SQL_ASCII is default encoding and must be = 0.
68 *
69 * XXX We must avoid renumbering any backend encoding until libpq's major
70 * version number is increased beyond 5; it turns out that the backend
71 * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and
72 * psql are concerned.
73 */
74typedef enum pg_enc
75{
76 PG_SQL_ASCII = 0, /* SQL/ASCII */
77 PG_EUC_JP, /* EUC for Japanese */
78 PG_EUC_CN, /* EUC for Chinese */
79 PG_EUC_KR, /* EUC for Korean */
80 PG_EUC_TW, /* EUC for Taiwan */
81 PG_EUC_JIS_2004, /* EUC-JIS-2004 */
82 PG_UTF8, /* Unicode UTF8 */
83 PG_UNUSED_1, /* (Was Mule internal code) */
84 PG_LATIN1, /* ISO-8859-1 Latin 1 */
85 PG_LATIN2, /* ISO-8859-2 Latin 2 */
86 PG_LATIN3, /* ISO-8859-3 Latin 3 */
87 PG_LATIN4, /* ISO-8859-4 Latin 4 */
88 PG_LATIN5, /* ISO-8859-9 Latin 5 */
89 PG_LATIN6, /* ISO-8859-10 Latin6 */
90 PG_LATIN7, /* ISO-8859-13 Latin7 */
91 PG_LATIN8, /* ISO-8859-14 Latin8 */
92 PG_LATIN9, /* ISO-8859-15 Latin9 */
93 PG_LATIN10, /* ISO-8859-16 Latin10 */
94 PG_WIN1256, /* windows-1256 */
95 PG_WIN1258, /* Windows-1258 */
96 PG_WIN866, /* (MS-DOS CP866) */
97 PG_WIN874, /* windows-874 */
98 PG_KOI8R, /* KOI8-R */
99 PG_WIN1251, /* windows-1251 */
100 PG_WIN1252, /* windows-1252 */
101 PG_ISO_8859_5, /* ISO-8859-5 */
102 PG_ISO_8859_6, /* ISO-8859-6 */
103 PG_ISO_8859_7, /* ISO-8859-7 */
104 PG_ISO_8859_8, /* ISO-8859-8 */
105 PG_WIN1250, /* windows-1250 */
106 PG_WIN1253, /* windows-1253 */
107 PG_WIN1254, /* windows-1254 */
108 PG_WIN1255, /* windows-1255 */
109 PG_WIN1257, /* windows-1257 */
110 PG_KOI8U, /* KOI8-U */
111 /* PG_ENCODING_BE_LAST points to the above entry */
112
113 /* followings are for client encoding only */
114 PG_SJIS, /* Shift JIS (Windows-932) */
115 PG_BIG5, /* Big5 (Windows-950) */
116 PG_GBK, /* GBK (Windows-936) */
117 PG_UHC, /* UHC (Windows-949) */
118 PG_GB18030, /* GB18030 */
119 PG_JOHAB, /* EUC for Korean JOHAB */
120 PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */
121 _PG_LAST_ENCODING_ /* mark only */
122
124
125#define PG_ENCODING_BE_LAST PG_KOI8U
126
127#define PG_UNUSED_ENCODING(_enc) \
128 ((_enc) == PG_UNUSED_1)
129
130/*
131 * Please use these tests before access to pg_enc2name_tbl[]
132 * or to other places...
133 */
134#define PG_VALID_BE_ENCODING(_enc) \
135 ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST && !PG_UNUSED_ENCODING(_enc))
136
137#define PG_ENCODING_IS_CLIENT_ONLY(_enc) \
138 ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_)
139
140#define PG_VALID_ENCODING(_enc) \
141 ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_ && !PG_UNUSED_ENCODING(_enc))
142
143/* On FE are possible all encodings */
144#define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc)
145
146/*
147 * When converting strings between different encodings, we assume that space
148 * for converted result is 4-to-1 growth in the worst case. The rate for
149 * currently supported encoding pairs are within 3 (SJIS JIS X0201 half width
150 * kana -> UTF8 is the worst case). So "4" should be enough for the moment.
151 *
152 * Note that this is not the same as the maximum character width in any
153 * particular encoding.
154 */
155#define MAX_CONVERSION_GROWTH 4
156
157/*
158 * Maximum byte length of a string that's required in any encoding to convert
159 * at least one character to any other encoding. In other words, if you feed
160 * MAX_CONVERSION_INPUT_LENGTH bytes to any encoding conversion function, it
161 * is guaranteed to be able to convert something without needing more input
162 * (assuming the input is valid).
163 *
164 * Currently, the maximum case is the conversion UTF8 -> SJIS JIS X0201 half
165 * width kana, where a pair of UTF-8 characters is converted into a single
166 * SHIFT_JIS_2004 character (the reverse of the worst case for
167 * MAX_CONVERSION_GROWTH). It needs 6 bytes of input. In theory, a
168 * user-defined conversion function might have more complicated cases, although
169 * for the reverse mapping you would probably also need to bump up
170 * MAX_CONVERSION_GROWTH. But there is no need to be stingy here, so make it
171 * generous.
172 */
173#define MAX_CONVERSION_INPUT_LENGTH 16
174
175/*
176 * Maximum byte length of the string equivalent to any one Unicode code point,
177 * in any backend encoding. The current value assumes that a 4-byte UTF-8
178 * character might expand by MAX_CONVERSION_GROWTH, which is a huge
179 * overestimate. But in current usage we don't allocate large multiples of
180 * this, so there's little point in being stingy.
181 */
182#define MAX_UNICODE_EQUIVALENT_STRING 16
183
184/*
185 * Table for mapping an encoding number to official encoding name and
186 * possibly other subsidiary data. Be careful to check encoding number
187 * before accessing a table entry!
188 *
189 * if (PG_VALID_ENCODING(encoding))
190 * pg_enc2name_tbl[ encoding ];
191 */
192typedef struct pg_enc2name
193{
194 const char *name;
196#ifdef WIN32
197 unsigned codepage; /* codepage for WIN32 */
198#endif
200
202
203/*
204 * Encoding names for gettext
205 */
206extern PGDLLIMPORT const char *pg_enc2gettext_tbl[];
207
208/*
209 * pg_wchar stuff
210 */
211typedef int (*mb2wchar_with_len_converter) (const unsigned char *from,
212 pg_wchar *to,
213 int len);
214
216 unsigned char *to,
217 int len);
218
219typedef int (*mblen_converter) (const unsigned char *mbstr);
220
221typedef int (*mbdisplaylen_converter) (const unsigned char *mbstr);
222
223typedef bool (*mbcharacter_incrementer) (unsigned char *mbstr, int len);
224
225typedef int (*mbchar_verifier) (const unsigned char *mbstr, int len);
226
227typedef int (*mbstr_verifier) (const unsigned char *mbstr, int len);
228
229typedef struct
230{
232 * string to a wchar */
234 * to a multibyte */
235 mblen_converter mblen; /* get byte length of a char */
236 mbdisplaylen_converter dsplen; /* get display width of a char */
237 mbchar_verifier mbverifychar; /* verify multibyte character */
238 mbstr_verifier mbverifystr; /* verify multibyte string */
239 int maxmblen; /* max bytes for a char in this encoding */
241
243
244/*
245 * Data structures for conversions between UTF-8 and other encodings
246 * (UtfToLocal() and LocalToUtf()). In these data structures, characters of
247 * either encoding are represented by uint32 words; hence we can only support
248 * characters up to 4 bytes long. For example, the byte sequence 0xC2 0x89
249 * would be represented by 0x0000C289, and 0xE8 0xA2 0xB4 by 0x00E8A2B4.
250 *
251 * There are three possible ways a character can be mapped:
252 *
253 * 1. Using a radix tree, from source to destination code.
254 * 2. Using a sorted array of source -> destination code pairs. This
255 * method is used for "combining" characters. There are so few of
256 * them that building a radix tree would be wasteful.
257 * 3. Using a conversion function.
258 */
259
260/*
261 * Radix tree for character conversion.
262 *
263 * Logically, this is actually four different radix trees, for 1-byte,
264 * 2-byte, 3-byte and 4-byte inputs. The 1-byte tree is a simple lookup
265 * table from source to target code. The 2-byte tree consists of two levels:
266 * one lookup table for the first byte, where the value in the lookup table
267 * points to a lookup table for the second byte. And so on.
268 *
269 * Physically, all the trees are stored in one big array, in 'chars16' or
270 * 'chars32', depending on the maximum value that needs to be represented. For
271 * each level in each tree, we also store lower and upper bound of allowed
272 * values - values outside those bounds are considered invalid, and are left
273 * out of the tables.
274 *
275 * In the intermediate levels of the trees, the values stored are offsets
276 * into the chars[16|32] array.
277 *
278 * In the beginning of the chars[16|32] array, there is always a number of
279 * zeros, so that you safely follow an index from an intermediate table
280 * without explicitly checking for a zero. Following a zero any number of
281 * times will always bring you to the dummy, all-zeros table in the
282 * beginning. This helps to shave some cycles when looking up values.
283 */
284typedef struct
285{
286 /*
287 * Array containing all the values. Only one of chars16 or chars32 is
288 * used, depending on how wide the values we need to represent are.
289 */
292
293 /* Radix tree for 1-byte inputs */
294 uint32 b1root; /* offset of table in the chars[16|32] array */
295 uint8 b1_lower; /* min allowed value for a single byte input */
296 uint8 b1_upper; /* max allowed value for a single byte input */
297
298 /* Radix tree for 2-byte inputs */
299 uint32 b2root; /* offset of 1st byte's table */
300 uint8 b2_1_lower; /* min/max allowed value for 1st input byte */
302 uint8 b2_2_lower; /* min/max allowed value for 2nd input byte */
304
305 /* Radix tree for 3-byte inputs */
306 uint32 b3root; /* offset of 1st byte's table */
307 uint8 b3_1_lower; /* min/max allowed value for 1st input byte */
309 uint8 b3_2_lower; /* min/max allowed value for 2nd input byte */
311 uint8 b3_3_lower; /* min/max allowed value for 3rd input byte */
313
314 /* Radix tree for 4-byte inputs */
315 uint32 b4root; /* offset of 1st byte's table */
316 uint8 b4_1_lower; /* min/max allowed value for 1st input byte */
318 uint8 b4_2_lower; /* min/max allowed value for 2nd input byte */
320 uint8 b4_3_lower; /* min/max allowed value for 3rd input byte */
322 uint8 b4_4_lower; /* min/max allowed value for 4th input byte */
324
326
327/*
328 * UTF-8 to local code conversion map (for combined characters)
329 */
330typedef struct
331{
332 uint32 utf1; /* UTF-8 code 1 */
333 uint32 utf2; /* UTF-8 code 2 */
334 uint32 code; /* local code */
336
337/*
338 * local code to UTF-8 conversion map (for combined characters)
339 */
340typedef struct
341{
342 uint32 code; /* local code */
343 uint32 utf1; /* UTF-8 code 1 */
344 uint32 utf2; /* UTF-8 code 2 */
346
347/*
348 * callback function for algorithmic encoding conversions (in either direction)
349 *
350 * if function returns zero, it does not know how to convert the code
351 */
353
354/*
355 * Support macro for encoding conversion functions to validate their
356 * arguments. (This could be made more compact if we included fmgr.h
357 * here, but we don't want to do that because this header file is also
358 * used by frontends.)
359 */
360#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
361 check_encoding_conversion_args(PG_GETARG_INT32(0), \
362 PG_GETARG_INT32(1), \
363 PG_GETARG_INT32(4), \
364 (srcencoding), \
365 (destencoding))
366
367
368/*
369 * Some handy functions for Unicode-specific tests.
370 */
371static inline bool
373{
374 return (c > 0 && c <= 0x10FFFF);
375}
376
377static inline bool
379{
380 return (c >= 0xD800 && c <= 0xDBFF);
381}
382
383static inline bool
385{
386 return (c >= 0xDC00 && c <= 0xDFFF);
387}
388
389static inline char32_t
390surrogate_pair_to_codepoint(char16_t first, char16_t second)
391{
392 return ((first & 0x3FF) << 10) + 0x10000 + (second & 0x3FF);
393}
394
395/*
396 * Convert a UTF-8 character to a Unicode code point.
397 * This is a one-character version of pg_utf2wchar_with_len.
398 *
399 * No error checks here, c must point to a long-enough string.
400 */
401static inline char32_t
402utf8_to_unicode(const unsigned char *c)
403{
404 if ((*c & 0x80) == 0)
405 return (char32_t) c[0];
406 else if ((*c & 0xe0) == 0xc0)
407 return (char32_t) (((c[0] & 0x1f) << 6) |
408 (c[1] & 0x3f));
409 else if ((*c & 0xf0) == 0xe0)
410 return (char32_t) (((c[0] & 0x0f) << 12) |
411 ((c[1] & 0x3f) << 6) |
412 (c[2] & 0x3f));
413 else if ((*c & 0xf8) == 0xf0)
414 return (char32_t) (((c[0] & 0x07) << 18) |
415 ((c[1] & 0x3f) << 12) |
416 ((c[2] & 0x3f) << 6) |
417 (c[3] & 0x3f));
418 else
419 /* that is an invalid code on purpose */
420 return 0xffffffff;
421}
422
423/*
424 * Map a Unicode code point to UTF-8. utf8string must have at least
425 * unicode_utf8len(c) bytes available.
426 */
427static inline unsigned char *
428unicode_to_utf8(char32_t c, unsigned char *utf8string)
429{
430 if (c <= 0x7F)
431 {
432 utf8string[0] = c;
433 }
434 else if (c <= 0x7FF)
435 {
436 utf8string[0] = 0xC0 | ((c >> 6) & 0x1F);
437 utf8string[1] = 0x80 | (c & 0x3F);
438 }
439 else if (c <= 0xFFFF)
440 {
441 utf8string[0] = 0xE0 | ((c >> 12) & 0x0F);
442 utf8string[1] = 0x80 | ((c >> 6) & 0x3F);
443 utf8string[2] = 0x80 | (c & 0x3F);
444 }
445 else
446 {
447 utf8string[0] = 0xF0 | ((c >> 18) & 0x07);
448 utf8string[1] = 0x80 | ((c >> 12) & 0x3F);
449 utf8string[2] = 0x80 | ((c >> 6) & 0x3F);
450 utf8string[3] = 0x80 | (c & 0x3F);
451 }
452
453 return utf8string;
454}
455
456/*
457 * Number of bytes needed to represent the given char in UTF8.
458 */
459static inline int
461{
462 if (c <= 0x7F)
463 return 1;
464 else if (c <= 0x7FF)
465 return 2;
466 else if (c <= 0xFFFF)
467 return 3;
468 else
469 return 4;
470}
471
472/*
473 * The functions in this list are exported by libpq, and we need to be sure
474 * that we know which calls are satisfied by libpq and which are satisfied
475 * by static linkage to libpgcommon. (This is because we might be using a
476 * libpq.so that's of a different major version and has encoding IDs that
477 * differ from the current version's.) The nominal function names are what
478 * are actually used in and exported by libpq, while the names exported by
479 * libpgcommon.a and libpgcommon_srv.a end in "_private".
480 */
481#if defined(USE_PRIVATE_ENCODING_FUNCS) || !defined(FRONTEND)
482#define pg_char_to_encoding pg_char_to_encoding_private
483#define pg_encoding_to_char pg_encoding_to_char_private
484#define pg_valid_server_encoding pg_valid_server_encoding_private
485#define pg_valid_server_encoding_id pg_valid_server_encoding_id_private
486#define pg_utf_mblen pg_utf_mblen_private
487#endif
488
489/*
490 * These functions are considered part of libpq's exported API and
491 * are also declared in libpq-fe.h.
492 */
493extern int pg_char_to_encoding(const char *name);
494extern const char *pg_encoding_to_char(int encoding);
496
497/*
498 * These functions are available to frontend code that links with libpgcommon
499 * (in addition to the ones just above). The constant tables declared
500 * earlier in this file are also available from libpgcommon.
501 */
502extern void pg_encoding_set_invalid(int encoding, char *dst);
503extern int pg_encoding_mblen(int encoding, const char *mbstr);
504extern int pg_encoding_mblen_or_incomplete(int encoding, const char *mbstr,
505 size_t remaining);
506extern int pg_encoding_mblen_bounded(int encoding, const char *mbstr);
507extern int pg_encoding_dsplen(int encoding, const char *mbstr);
508extern int pg_encoding_verifymbchar(int encoding, const char *mbstr, int len);
509extern int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len);
510extern int pg_encoding_max_length(int encoding);
511extern int pg_valid_client_encoding(const char *name);
512extern int pg_valid_server_encoding(const char *name);
514extern const char *get_encoding_name_for_icu(int encoding);
515
516extern bool pg_utf8_islegal(const unsigned char *source, int length);
517extern int pg_utf_mblen(const unsigned char *s);
518
519/*
520 * The remaining functions are backend-only.
521 */
522extern int pg_mb2wchar(const char *from, pg_wchar *to);
523extern int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len);
525 const char *from, pg_wchar *to, int len);
526extern int pg_wchar2mb(const pg_wchar *from, char *to);
527extern int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len);
529 const pg_wchar *from, char *to, int len);
530extern int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2);
531extern int pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n);
532extern int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n);
533extern size_t pg_wchar_strlen(const pg_wchar *str);
534extern int pg_mblen_cstr(const char *mbstr);
535extern int pg_mblen_range(const char *mbstr, const char *end);
536extern int pg_mblen_with_len(const char *mbstr, int limit);
537extern int pg_mblen_unbounded(const char *mbstr);
538
539/* deprecated */
540extern int pg_mblen(const char *mbstr);
541
542extern int pg_dsplen(const char *mbstr);
543extern int pg_mbstrlen(const char *mbstr);
544extern int pg_mbstrlen_with_len(const char *mbstr, int limit);
545extern int pg_mbcliplen(const char *mbstr, int len, int limit);
546extern int pg_encoding_mbcliplen(int encoding, const char *mbstr,
547 int len, int limit);
548extern int pg_mbcharcliplen(const char *mbstr, int len, int limit);
549extern int pg_database_encoding_max_length(void);
551
552extern int PrepareClientEncoding(int encoding);
553extern int SetClientEncoding(int encoding);
554extern void InitializeClientEncoding(void);
555extern int pg_get_client_encoding(void);
556extern const char *pg_get_client_encoding_name(void);
557
558extern void SetDatabaseEncoding(int encoding);
559extern int GetDatabaseEncoding(void);
560extern const char *GetDatabaseEncodingName(void);
561extern void SetMessageEncoding(int encoding);
562extern int GetMessageEncoding(void);
563
564#ifdef ENABLE_NLS
565extern int pg_bind_textdomain_codeset(const char *domainname);
566#endif
567
568extern unsigned char *pg_do_encoding_conversion(unsigned char *src, int len,
569 int src_encoding,
570 int dest_encoding);
571extern int pg_do_encoding_conversion_buf(Oid proc,
572 int src_encoding,
573 int dest_encoding,
574 unsigned char *src, int srclen,
575 unsigned char *dest, int destlen,
576 bool noError);
577
578extern char *pg_client_to_server(const char *s, int len);
579extern char *pg_server_to_client(const char *s, int len);
580extern char *pg_any_to_server(const char *s, int len, int encoding);
581extern char *pg_server_to_any(const char *s, int len, int encoding);
582
583extern void pg_unicode_to_server(char32_t c, unsigned char *s);
584extern bool pg_unicode_to_server_noerror(char32_t c, unsigned char *s);
585
586extern unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc);
587extern unsigned short CNStoBIG5(unsigned short cns, unsigned char lc);
588
589extern int UtfToLocal(const unsigned char *utf, int len,
590 unsigned char *iso,
591 const pg_mb_radix_tree *map,
592 const pg_utf_to_local_combined *cmap, int cmapsize,
594 int encoding, bool noError);
595extern int LocalToUtf(const unsigned char *iso, int len,
596 unsigned char *utf,
597 const pg_mb_radix_tree *map,
598 const pg_local_to_utf_combined *cmap, int cmapsize,
600 int encoding, bool noError);
601
602extern bool pg_verifymbstr(const char *mbstr, int len, bool noError);
603extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
604 bool noError);
605extern int pg_verify_mbstr_len(int encoding, const char *mbstr, int len,
606 bool noError);
607
609 int dest_encoding,
610 int len,
613
614pg_noreturn extern void report_invalid_encoding(int encoding, const char *mbstr, int len);
616 const char *mbstr, int len);
617
618extern int local2local(const unsigned char *l, unsigned char *p, int len,
620 const unsigned char *tab, bool noError);
621
622#ifdef WIN32
623extern WCHAR *pgwin32_message_to_UTF16(const char *str, int len, int *utf16len);
624#endif
625
626#endif /* PG_WCHAR_H */
#define PGDLLIMPORT
Definition c.h:1421
uint8_t uint8
Definition c.h:622
#define pg_noreturn
Definition c.h:190
uint16_t uint16
Definition c.h:623
uint32_t uint32
Definition c.h:624
const char * str
int remaining
Definition informix.c:692
static char * encoding
Definition initdb.c:139
unsigned int pg_wchar
Definition mbprint.c:31
const void size_t len
static rewind_source * source
Definition pg_rewind.c:89
int pg_encoding_mblen_bounded(int encoding, const char *mbstr)
Definition wchar.c:1966
bool pg_utf8_islegal(const unsigned char *source, int length)
Definition wchar.c:1789
char * pg_client_to_server(const char *s, int len)
Definition mbutils.c:671
int GetDatabaseEncoding(void)
Definition mbutils.c:1388
int pg_encoding_wchar2mb_with_len(int encoding, const pg_wchar *from, char *to, int len)
Definition mbutils.c:1026
int UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_mb_radix_tree *map, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition conv.c:269
#define pg_utf_mblen
Definition pg_wchar.h:486
pg_enc
Definition pg_wchar.h:75
@ PG_WIN1254
Definition pg_wchar.h:107
@ PG_LATIN4
Definition pg_wchar.h:87
@ _PG_LAST_ENCODING_
Definition pg_wchar.h:121
@ PG_LATIN9
Definition pg_wchar.h:92
@ PG_JOHAB
Definition pg_wchar.h:119
@ PG_GB18030
Definition pg_wchar.h:118
@ PG_SQL_ASCII
Definition pg_wchar.h:76
@ PG_KOI8R
Definition pg_wchar.h:98
@ PG_ISO_8859_6
Definition pg_wchar.h:102
@ PG_WIN1253
Definition pg_wchar.h:106
@ PG_KOI8U
Definition pg_wchar.h:110
@ PG_LATIN6
Definition pg_wchar.h:89
@ PG_LATIN5
Definition pg_wchar.h:88
@ PG_EUC_CN
Definition pg_wchar.h:78
@ PG_UHC
Definition pg_wchar.h:117
@ PG_LATIN2
Definition pg_wchar.h:85
@ PG_ISO_8859_5
Definition pg_wchar.h:101
@ PG_LATIN10
Definition pg_wchar.h:93
@ PG_WIN1250
Definition pg_wchar.h:105
@ PG_ISO_8859_7
Definition pg_wchar.h:103
@ PG_SJIS
Definition pg_wchar.h:114
@ PG_LATIN8
Definition pg_wchar.h:91
@ PG_UNUSED_1
Definition pg_wchar.h:83
@ PG_EUC_JP
Definition pg_wchar.h:77
@ PG_GBK
Definition pg_wchar.h:116
@ PG_LATIN3
Definition pg_wchar.h:86
@ PG_WIN1256
Definition pg_wchar.h:94
@ PG_LATIN1
Definition pg_wchar.h:84
@ PG_EUC_TW
Definition pg_wchar.h:80
@ PG_WIN1258
Definition pg_wchar.h:95
@ PG_SHIFT_JIS_2004
Definition pg_wchar.h:120
@ PG_WIN1252
Definition pg_wchar.h:100
@ PG_LATIN7
Definition pg_wchar.h:90
@ PG_UTF8
Definition pg_wchar.h:82
@ PG_WIN1255
Definition pg_wchar.h:108
@ PG_WIN1257
Definition pg_wchar.h:109
@ PG_WIN1251
Definition pg_wchar.h:99
@ PG_EUC_KR
Definition pg_wchar.h:79
@ PG_WIN866
Definition pg_wchar.h:96
@ PG_ISO_8859_8
Definition pg_wchar.h:104
@ PG_WIN874
Definition pg_wchar.h:97
@ PG_EUC_JIS_2004
Definition pg_wchar.h:81
@ PG_BIG5
Definition pg_wchar.h:115
int pg_mblen_cstr(const char *mbstr)
Definition mbutils.c:1045
uint32(* utf_local_conversion_func)(uint32 code)
Definition pg_wchar.h:352
static bool is_utf16_surrogate_first(char32_t c)
Definition pg_wchar.h:378
int(* wchar2mb_with_len_converter)(const pg_wchar *from, unsigned char *to, int len)
Definition pg_wchar.h:215
static unsigned char * unicode_to_utf8(char32_t c, unsigned char *utf8string)
Definition pg_wchar.h:428
int pg_verify_mbstr_len(int encoding, const char *mbstr, int len, bool noError)
Definition mbutils.c:1723
void InitializeClientEncoding(void)
Definition mbutils.c:290
int pg_dsplen(const char *mbstr)
Definition mbutils.c:1158
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1185
mbcharacter_incrementer pg_database_encoding_character_incrementer(void)
Definition mbutils.c:1649
void pg_encoding_set_invalid(int encoding, char *dst)
Definition wchar.c:1851
int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len)
Definition mbutils.c:1019
int pg_encoding_mblen_or_incomplete(int encoding, const char *mbstr, size_t remaining)
Definition wchar.c:1946
static bool is_utf16_surrogate_second(char32_t c)
Definition pg_wchar.h:384
int pg_mb2wchar(const char *from, pg_wchar *to)
Definition mbutils.c:990
bool(* mbcharacter_incrementer)(unsigned char *mbstr, int len)
Definition pg_wchar.h:223
char * pg_any_to_server(const char *s, int len, int encoding)
Definition mbutils.c:687
int(* mbchar_verifier)(const unsigned char *mbstr, int len)
Definition pg_wchar.h:225
int pg_mblen_unbounded(const char *mbstr)
Definition mbutils.c:1137
const char * get_encoding_name_for_icu(int encoding)
Definition encnames.c:464
int pg_mbcharcliplen(const char *mbstr, int len, int limit)
Definition mbutils.c:1253
static char32_t surrogate_pair_to_codepoint(char16_t first, char16_t second)
Definition pg_wchar.h:390
bool pg_unicode_to_server_noerror(char32_t c, unsigned char *s)
Definition mbutils.c:937
int pg_mblen_range(const char *mbstr, const char *end)
Definition mbutils.c:1084
unsigned char * pg_do_encoding_conversion(unsigned char *src, int len, int src_encoding, int dest_encoding)
Definition mbutils.c:365
unsigned short CNStoBIG5(unsigned short cns, unsigned char lc)
Definition big5.c:344
size_t pg_wchar_strlen(const pg_wchar *str)
Definition wstrncmp.c:70
int pg_wchar2mb(const pg_wchar *from, char *to)
Definition mbutils.c:1012
PGDLLIMPORT const pg_enc2name pg_enc2name_tbl[]
Definition encnames.c:305
int pg_mbstrlen(const char *mbstr)
Definition mbutils.c:1165
bool pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
Definition mbutils.c:1692
PGDLLIMPORT const char * pg_enc2gettext_tbl[]
Definition encnames.c:354
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
Definition mbutils.c:1682
int LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_mb_radix_tree *map, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition conv.c:479
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition mbutils.c:1211
int GetMessageEncoding(void)
Definition mbutils.c:1434
int pg_mblen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1108
int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)
Definition mbutils.c:478
const char * GetDatabaseEncodingName(void)
Definition mbutils.c:1394
int SetClientEncoding(int encoding)
Definition mbutils.c:217
void SetMessageEncoding(int encoding)
Definition mbutils.c:1299
char * pg_server_to_client(const char *s, int len)
Definition mbutils.c:749
unsigned int pg_wchar
Definition pg_wchar.h:28
static char32_t utf8_to_unicode(const unsigned char *c)
Definition pg_wchar.h:402
void check_encoding_conversion_args(int src_encoding, int dest_encoding, int len, int expected_src_encoding, int expected_dest_encoding)
Definition mbutils.c:1795
int pg_database_encoding_max_length(void)
Definition mbutils.c:1672
int PrepareClientEncoding(int encoding)
Definition mbutils.c:119
int pg_valid_client_encoding(const char *name)
Definition encnames.c:477
static bool is_valid_unicode_codepoint(char32_t c)
Definition pg_wchar.h:372
int pg_encoding_dsplen(int encoding, const char *mbstr)
Definition wchar.c:1975
int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2)
Definition wstrcmp.c:41
unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc)
Definition big5.c:291
#define pg_encoding_to_char
Definition pg_wchar.h:483
#define pg_valid_server_encoding_id
Definition pg_wchar.h:485
int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)
Definition wchar.c:2001
int pg_get_client_encoding(void)
Definition mbutils.c:345
pg_noreturn void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition mbutils.c:1824
void pg_unicode_to_server(char32_t c, unsigned char *s)
Definition mbutils.c:875
#define pg_valid_server_encoding
Definition pg_wchar.h:484
bool is_encoding_supported_by_icu(int encoding)
Definition encnames.c:453
pg_noreturn void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition mbutils.c:1869
int(* mb2wchar_with_len_converter)(const unsigned char *from, pg_wchar *to, int len)
Definition pg_wchar.h:211
char * pg_server_to_any(const char *s, int len, int encoding)
Definition mbutils.c:760
#define pg_char_to_encoding
Definition pg_wchar.h:482
static int unicode_utf8len(char32_t c)
Definition pg_wchar.h:460
int(* mbstr_verifier)(const unsigned char *mbstr, int len)
Definition pg_wchar.h:227
int local2local(const unsigned char *l, unsigned char *p, int len, int src_encoding, int dest_encoding, const unsigned char *tab, bool noError)
Definition conv.c:33
int pg_encoding_max_length(int encoding)
Definition wchar.c:2012
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition wchar.c:1934
PGDLLIMPORT const pg_wchar_tbl pg_wchar_table[]
Definition wchar.c:1864
int pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n)
Definition wstrncmp.c:40
void SetDatabaseEncoding(int encoding)
Definition mbutils.c:1289
int pg_encoding_mbcliplen(int encoding, const char *mbstr, int len, int limit)
Definition mbutils.c:1221
const char * pg_get_client_encoding_name(void)
Definition mbutils.c:354
int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n)
Definition wstrncmp.c:55
int pg_encoding_verifymbchar(int encoding, const char *mbstr, int len)
Definition wchar.c:1988
int pg_encoding_mb2wchar_with_len(int encoding, const char *from, pg_wchar *to, int len)
Definition mbutils.c:1004
int(* mbdisplaylen_converter)(const unsigned char *mbstr)
Definition pg_wchar.h:221
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
Definition mbutils.c:997
int pg_mblen(const char *mbstr)
Definition mbutils.c:1151
int(* mblen_converter)(const unsigned char *mbstr)
Definition pg_wchar.h:219
unsigned int Oid
char * c
static int fb(int x)
char * s1
char * s2
pg_enc encoding
Definition pg_wchar.h:195
const char * name
Definition pg_wchar.h:194
const uint32 * chars32
Definition pg_wchar.h:291
const uint16 * chars16
Definition pg_wchar.h:290
mbstr_verifier mbverifystr
Definition pg_wchar.h:238
wchar2mb_with_len_converter wchar2mb_with_len
Definition pg_wchar.h:233
mb2wchar_with_len_converter mb2wchar_with_len
Definition pg_wchar.h:231
mblen_converter mblen
Definition pg_wchar.h:235
mbdisplaylen_converter dsplen
Definition pg_wchar.h:236
mbchar_verifier mbverifychar
Definition pg_wchar.h:237
const char * name