PostgreSQL Source Code git master
Loading...
Searching...
No Matches
encnames.c File Reference
#include "c.h"
#include <ctype.h>
#include <unistd.h>
#include "mb/pg_wchar.h"
Include dependency graph for encnames.c:

Go to the source code of this file.

Data Structures

struct  pg_encname
 

Macros

#define DEF_ENC2NAME(name, codepage)   { #name, PG_##name }
 

Typedefs

typedef struct pg_encname pg_encname
 

Functions

 StaticAssertDecl (lengthof(pg_enc2icu_tbl)==PG_ENCODING_BE_LAST+1, "pg_enc2icu_tbl incomplete")
 
bool is_encoding_supported_by_icu (int encoding)
 
const charget_encoding_name_for_icu (int encoding)
 
int pg_valid_client_encoding (const char *name)
 
int pg_valid_server_encoding (const char *name)
 
int pg_valid_server_encoding_id (int encoding)
 
static charclean_encoding_name (const char *key, char *newkey)
 
int pg_char_to_encoding (const char *name)
 
const charpg_encoding_to_char (int encoding)
 

Variables

static const pg_encname pg_encname_tbl []
 
const pg_enc2name pg_enc2name_tbl []
 
const charpg_enc2gettext_tbl []
 
static const char *const pg_enc2icu_tbl []
 

Macro Definition Documentation

◆ DEF_ENC2NAME

#define DEF_ENC2NAME (   name,
  codepage 
)    { #name, PG_##name }

Definition at line 300 of file encnames.c.

Typedef Documentation

◆ pg_encname

Function Documentation

◆ clean_encoding_name()

static char * clean_encoding_name ( const char key,
char newkey 
)
static

Definition at line 516 of file encnames.c.

517{
518 const char *p;
519 char *np;
520
521 for (p = key, np = newkey; *p != '\0'; p++)
522 {
523 if (isalnum((unsigned char) *p))
524 {
525 if (*p >= 'A' && *p <= 'Z')
526 *np++ = *p + 'a' - 'A';
527 else
528 *np++ = *p;
529 }
530 }
531 *np = '\0';
532 return newkey;
533}
static int fb(int x)

References fb().

Referenced by pg_char_to_encoding().

◆ get_encoding_name_for_icu()

const char * get_encoding_name_for_icu ( int  encoding)

Definition at line 464 of file encnames.c.

465{
467 return NULL;
468 return pg_enc2icu_tbl[encoding];
469}
static const char *const pg_enc2icu_tbl[]
Definition encnames.c:407
static char * encoding
Definition initdb.c:139
#define PG_VALID_BE_ENCODING(_enc)
Definition pg_wchar.h:134

References encoding, fb(), pg_enc2icu_tbl, and PG_VALID_BE_ENCODING.

◆ is_encoding_supported_by_icu()

bool is_encoding_supported_by_icu ( int  encoding)

Definition at line 453 of file encnames.c.

454{
456 return false;
457 return (pg_enc2icu_tbl[encoding] != NULL);
458}

References encoding, fb(), pg_enc2icu_tbl, and PG_VALID_BE_ENCODING.

Referenced by check_icu_locale_encoding(), createdb(), DefineCollation(), and lookup_collation().

◆ pg_char_to_encoding()

int pg_char_to_encoding ( const char name)

Definition at line 541 of file encnames.c.

542{
543 unsigned int nel = lengthof(pg_encname_tbl);
544 const pg_encname *base = pg_encname_tbl,
545 *last = base + nel - 1,
546 *position;
547 int result;
548 char buff[NAMEDATALEN],
549 *key;
550
551 if (name == NULL || *name == '\0')
552 return -1;
553
554 if (strlen(name) >= NAMEDATALEN)
555 return -1; /* it's certainly not in the table */
556
558
559 while (last >= base)
560 {
561 position = base + ((last - base) >> 1);
562 result = key[0] - position->name[0];
563
564 if (result == 0)
565 {
566 result = strcmp(key, position->name);
567 if (result == 0)
568 return position->encoding;
569 }
570 if (result < 0)
571 last = position - 1;
572 else
573 base = position + 1;
574 }
575 return -1;
576}
#define lengthof(array)
Definition c.h:873
uint32 result
static char * clean_encoding_name(const char *key, char *newkey)
Definition encnames.c:516
static const pg_encname pg_encname_tbl[]
Definition encnames.c:39
#define NAMEDATALEN
const char * name

References clean_encoding_name(), fb(), lengthof, name, NAMEDATALEN, pg_encname_tbl, and result.

◆ pg_encoding_to_char()

const char * pg_encoding_to_char ( int  encoding)

Definition at line 579 of file encnames.c.

580{
582 {
584
585 Assert(encoding == p->encoding);
586 return p->name;
587 }
588 return "";
589}
#define Assert(condition)
Definition c.h:943
const pg_enc2name pg_enc2name_tbl[]
Definition encnames.c:305
#define PG_VALID_ENCODING(_enc)
Definition pg_wchar.h:140
pg_enc encoding
Definition pg_wchar.h:195
const char * name
Definition pg_wchar.h:194

References Assert, encoding, pg_enc2name::encoding, pg_enc2name::name, pg_enc2name_tbl, and PG_VALID_ENCODING.

◆ pg_valid_client_encoding()

int pg_valid_client_encoding ( const char name)

Definition at line 477 of file encnames.c.

478{
479 int enc;
480
481 if ((enc = pg_char_to_encoding(name)) < 0)
482 return -1;
483
485 return -1;
486
487 return enc;
488}
#define PG_VALID_FE_ENCODING(_enc)
Definition pg_wchar.h:144
#define pg_char_to_encoding
Definition pg_wchar.h:482

References enc, name, pg_char_to_encoding, and PG_VALID_FE_ENCODING.

Referenced by check_client_encoding().

◆ pg_valid_server_encoding()

int pg_valid_server_encoding ( const char name)

Definition at line 491 of file encnames.c.

492{
493 int enc;
494
495 if ((enc = pg_char_to_encoding(name)) < 0)
496 return -1;
497
499 return -1;
500
501 return enc;
502}

References enc, name, pg_char_to_encoding, and PG_VALID_BE_ENCODING.

◆ pg_valid_server_encoding_id()

int pg_valid_server_encoding_id ( int  encoding)

Definition at line 505 of file encnames.c.

506{
508}

References encoding, and PG_VALID_BE_ENCODING.

◆ StaticAssertDecl()

StaticAssertDecl ( lengthof(pg_enc2icu_tbl = =PG_ENCODING_BE_LAST+1,
"pg_enc2icu_tbl incomplete"   
)

Variable Documentation

◆ pg_enc2gettext_tbl

const char* pg_enc2gettext_tbl[]

Definition at line 354 of file encnames.c.

355{
356 [PG_SQL_ASCII] = "US-ASCII",
357 [PG_UTF8] = "UTF-8",
358 [PG_LATIN1] = "LATIN1",
359 [PG_LATIN2] = "LATIN2",
360 [PG_LATIN3] = "LATIN3",
361 [PG_LATIN4] = "LATIN4",
362 [PG_ISO_8859_5] = "ISO-8859-5",
363 [PG_ISO_8859_6] = "ISO_8859-6",
364 [PG_ISO_8859_7] = "ISO-8859-7",
365 [PG_ISO_8859_8] = "ISO-8859-8",
366 [PG_LATIN5] = "LATIN5",
367 [PG_LATIN6] = "LATIN6",
368 [PG_LATIN7] = "LATIN7",
369 [PG_LATIN8] = "LATIN8",
370 [PG_LATIN9] = "LATIN-9",
371 [PG_LATIN10] = "LATIN10",
372 [PG_KOI8R] = "KOI8-R",
373 [PG_KOI8U] = "KOI8-U",
374 [PG_WIN1250] = "CP1250",
375 [PG_WIN1251] = "CP1251",
376 [PG_WIN1252] = "CP1252",
377 [PG_WIN1253] = "CP1253",
378 [PG_WIN1254] = "CP1254",
379 [PG_WIN1255] = "CP1255",
380 [PG_WIN1256] = "CP1256",
381 [PG_WIN1257] = "CP1257",
382 [PG_WIN1258] = "CP1258",
383 [PG_WIN866] = "CP866",
384 [PG_WIN874] = "CP874",
385 [PG_EUC_CN] = "EUC-CN",
386 [PG_EUC_JP] = "EUC-JP",
387 [PG_EUC_KR] = "EUC-KR",
388 [PG_EUC_TW] = "EUC-TW",
389 [PG_EUC_JIS_2004] = "EUC-JP",
390 [PG_SJIS] = "SHIFT-JIS",
391 [PG_BIG5] = "BIG5",
392 [PG_GBK] = "GBK",
393 [PG_UHC] = "UHC",
394 [PG_GB18030] = "GB18030",
395 [PG_JOHAB] = "JOHAB",
396 [PG_SHIFT_JIS_2004] = "SHIFT_JISX0213",
397};
#define PG_UTF8
Definition mbprint.c:43
@ PG_WIN1254
Definition pg_wchar.h:107
@ PG_LATIN4
Definition pg_wchar.h:87
@ 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_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_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

◆ pg_enc2icu_tbl

const char* const pg_enc2icu_tbl[]
static

Definition at line 407 of file encnames.c.

408{
409 [PG_SQL_ASCII] = NULL,
410 [PG_EUC_JP] = "EUC-JP",
411 [PG_EUC_CN] = "EUC-CN",
412 [PG_EUC_KR] = "EUC-KR",
413 [PG_EUC_TW] = "EUC-TW",
415 [PG_UTF8] = "UTF-8",
416 [PG_LATIN1] = "ISO-8859-1",
417 [PG_LATIN2] = "ISO-8859-2",
418 [PG_LATIN3] = "ISO-8859-3",
419 [PG_LATIN4] = "ISO-8859-4",
420 [PG_LATIN5] = "ISO-8859-9",
421 [PG_LATIN6] = "ISO-8859-10",
422 [PG_LATIN7] = "ISO-8859-13",
423 [PG_LATIN8] = "ISO-8859-14",
424 [PG_LATIN9] = "ISO-8859-15",
425 [PG_LATIN10] = NULL,
426 [PG_WIN1256] = "CP1256",
427 [PG_WIN1258] = "CP1258",
428 [PG_WIN866] = "CP866",
429 [PG_WIN874] = NULL,
430 [PG_KOI8R] = "KOI8-R",
431 [PG_WIN1251] = "CP1251",
432 [PG_WIN1252] = "CP1252",
433 [PG_ISO_8859_5] = "ISO-8859-5",
434 [PG_ISO_8859_6] = "ISO-8859-6",
435 [PG_ISO_8859_7] = "ISO-8859-7",
436 [PG_ISO_8859_8] = "ISO-8859-8",
437 [PG_WIN1250] = "CP1250",
438 [PG_WIN1253] = "CP1253",
439 [PG_WIN1254] = "CP1254",
440 [PG_WIN1255] = "CP1255",
441 [PG_WIN1257] = "CP1257",
442 [PG_KOI8U] = "KOI8-U",
443};

Referenced by get_encoding_name_for_icu(), and is_encoding_supported_by_icu().

◆ pg_enc2name_tbl

const pg_enc2name pg_enc2name_tbl[]

Definition at line 305 of file encnames.c.

306{
308 [PG_EUC_JP] = DEF_ENC2NAME(EUC_JP, 20932),
309 [PG_EUC_CN] = DEF_ENC2NAME(EUC_CN, 20936),
310 [PG_EUC_KR] = DEF_ENC2NAME(EUC_KR, 51949),
313 [PG_UTF8] = DEF_ENC2NAME(UTF8, 65001),
314 [PG_LATIN1] = DEF_ENC2NAME(LATIN1, 28591),
315 [PG_LATIN2] = DEF_ENC2NAME(LATIN2, 28592),
316 [PG_LATIN3] = DEF_ENC2NAME(LATIN3, 28593),
317 [PG_LATIN4] = DEF_ENC2NAME(LATIN4, 28594),
318 [PG_LATIN5] = DEF_ENC2NAME(LATIN5, 28599),
322 [PG_LATIN9] = DEF_ENC2NAME(LATIN9, 28605),
326 [PG_WIN866] = DEF_ENC2NAME(WIN866, 866),
327 [PG_WIN874] = DEF_ENC2NAME(WIN874, 874),
328 [PG_KOI8R] = DEF_ENC2NAME(KOI8R, 20866),
340 [PG_KOI8U] = DEF_ENC2NAME(KOI8U, 21866),
341 [PG_SJIS] = DEF_ENC2NAME(SJIS, 932),
342 [PG_BIG5] = DEF_ENC2NAME(BIG5, 950),
343 [PG_GBK] = DEF_ENC2NAME(GBK, 936),
344 [PG_UHC] = DEF_ENC2NAME(UHC, 949),
345 [PG_GB18030] = DEF_ENC2NAME(GB18030, 54936),
348};
#define DEF_ENC2NAME(name, codepage)
Definition encnames.c:300

Referenced by check_encoding_conversion_args(), InitializeClientEncoding(), pg_any_to_server(), pg_encoding_to_char(), pg_unicode_to_server(), report_invalid_encoding_int(), report_untranslatable_char(), SetClientEncoding(), SetDatabaseEncoding(), SetMessageEncoding(), and test_enc_setup().

◆ pg_encname_tbl

const pg_encname pg_encname_tbl[]
static

Definition at line 39 of file encnames.c.

40{
41 {
42 "abc", PG_WIN1258
43 }, /* alias for WIN1258 */
44 {
45 "alt", PG_WIN866
46 }, /* IBM866 */
47 {
48 "big5", PG_BIG5
49 }, /* Big5; Chinese for Taiwan multibyte set */
50 {
51 "euccn", PG_EUC_CN
52 }, /* EUC-CN; Extended Unix Code for simplified
53 * Chinese */
54 {
55 "eucjis2004", PG_EUC_JIS_2004
56 }, /* EUC-JIS-2004; Extended UNIX Code fixed
57 * Width for Japanese, standard JIS X 0213 */
58 {
59 "eucjp", PG_EUC_JP
60 }, /* EUC-JP; Extended UNIX Code fixed Width for
61 * Japanese, standard OSF */
62 {
63 "euckr", PG_EUC_KR
64 }, /* EUC-KR; Extended Unix Code for Korean , KS
65 * X 1001 standard */
66 {
67 "euctw", PG_EUC_TW
68 }, /* EUC-TW; Extended Unix Code for
69 *
70 * traditional Chinese */
71 {
72 "gb18030", PG_GB18030
73 }, /* GB18030;GB18030 */
74 {
75 "gbk", PG_GBK
76 }, /* GBK; Chinese Windows CodePage 936
77 * simplified Chinese */
78 {
79 "iso88591", PG_LATIN1
80 }, /* ISO-8859-1; RFC1345,KXS2 */
81 {
82 "iso885910", PG_LATIN6
83 }, /* ISO-8859-10; RFC1345,KXS2 */
84 {
85 "iso885913", PG_LATIN7
86 }, /* ISO-8859-13; RFC1345,KXS2 */
87 {
88 "iso885914", PG_LATIN8
89 }, /* ISO-8859-14; RFC1345,KXS2 */
90 {
91 "iso885915", PG_LATIN9
92 }, /* ISO-8859-15; RFC1345,KXS2 */
93 {
94 "iso885916", PG_LATIN10
95 }, /* ISO-8859-16; RFC1345,KXS2 */
96 {
97 "iso88592", PG_LATIN2
98 }, /* ISO-8859-2; RFC1345,KXS2 */
99 {
100 "iso88593", PG_LATIN3
101 }, /* ISO-8859-3; RFC1345,KXS2 */
102 {
103 "iso88594", PG_LATIN4
104 }, /* ISO-8859-4; RFC1345,KXS2 */
105 {
106 "iso88595", PG_ISO_8859_5
107 }, /* ISO-8859-5; RFC1345,KXS2 */
108 {
109 "iso88596", PG_ISO_8859_6
110 }, /* ISO-8859-6; RFC1345,KXS2 */
111 {
112 "iso88597", PG_ISO_8859_7
113 }, /* ISO-8859-7; RFC1345,KXS2 */
114 {
115 "iso88598", PG_ISO_8859_8
116 }, /* ISO-8859-8; RFC1345,KXS2 */
117 {
118 "iso88599", PG_LATIN5
119 }, /* ISO-8859-9; RFC1345,KXS2 */
120 {
121 "johab", PG_JOHAB
122 }, /* JOHAB; Extended Unix Code for simplified
123 * Chinese */
124 {
125 "koi8", PG_KOI8R
126 }, /* _dirty_ alias for KOI8-R (backward
127 * compatibility) */
128 {
129 "koi8r", PG_KOI8R
130 }, /* KOI8-R; RFC1489 */
131 {
132 "koi8u", PG_KOI8U
133 }, /* KOI8-U; RFC2319 */
134 {
135 "latin1", PG_LATIN1
136 }, /* alias for ISO-8859-1 */
137 {
138 "latin10", PG_LATIN10
139 }, /* alias for ISO-8859-16 */
140 {
141 "latin2", PG_LATIN2
142 }, /* alias for ISO-8859-2 */
143 {
144 "latin3", PG_LATIN3
145 }, /* alias for ISO-8859-3 */
146 {
147 "latin4", PG_LATIN4
148 }, /* alias for ISO-8859-4 */
149 {
150 "latin5", PG_LATIN5
151 }, /* alias for ISO-8859-9 */
152 {
153 "latin6", PG_LATIN6
154 }, /* alias for ISO-8859-10 */
155 {
156 "latin7", PG_LATIN7
157 }, /* alias for ISO-8859-13 */
158 {
159 "latin8", PG_LATIN8
160 }, /* alias for ISO-8859-14 */
161 {
162 "latin9", PG_LATIN9
163 }, /* alias for ISO-8859-15 */
164 {
165 "mskanji", PG_SJIS
166 }, /* alias for Shift_JIS */
167 {
168 "shiftjis", PG_SJIS
169 }, /* Shift_JIS; JIS X 0202-1991 */
170
171 {
172 "shiftjis2004", PG_SHIFT_JIS_2004
173 }, /* SHIFT-JIS-2004; Shift JIS for Japanese,
174 * standard JIS X 0213 */
175 {
176 "sjis", PG_SJIS
177 }, /* alias for Shift_JIS */
178 {
179 "sqlascii", PG_SQL_ASCII
180 },
181 {
182 "tcvn", PG_WIN1258
183 }, /* alias for WIN1258 */
184 {
185 "tcvn5712", PG_WIN1258
186 }, /* alias for WIN1258 */
187 {
188 "uhc", PG_UHC
189 }, /* UHC; Korean Windows CodePage 949 */
190 {
191 "unicode", PG_UTF8
192 }, /* alias for UTF8 */
193 {
194 "utf8", PG_UTF8
195 }, /* alias for UTF8 */
196 {
197 "vscii", PG_WIN1258
198 }, /* alias for WIN1258 */
199 {
200 "win", PG_WIN1251
201 }, /* _dirty_ alias for windows-1251 (backward
202 * compatibility) */
203 {
204 "win1250", PG_WIN1250
205 }, /* alias for Windows-1250 */
206 {
207 "win1251", PG_WIN1251
208 }, /* alias for Windows-1251 */
209 {
210 "win1252", PG_WIN1252
211 }, /* alias for Windows-1252 */
212 {
213 "win1253", PG_WIN1253
214 }, /* alias for Windows-1253 */
215 {
216 "win1254", PG_WIN1254
217 }, /* alias for Windows-1254 */
218 {
219 "win1255", PG_WIN1255
220 }, /* alias for Windows-1255 */
221 {
222 "win1256", PG_WIN1256
223 }, /* alias for Windows-1256 */
224 {
225 "win1257", PG_WIN1257
226 }, /* alias for Windows-1257 */
227 {
228 "win1258", PG_WIN1258
229 }, /* alias for Windows-1258 */
230 {
231 "win866", PG_WIN866
232 }, /* IBM866 */
233 {
234 "win874", PG_WIN874
235 }, /* alias for Windows-874 */
236 {
237 "win932", PG_SJIS
238 }, /* alias for Shift_JIS */
239 {
240 "win936", PG_GBK
241 }, /* alias for GBK */
242 {
243 "win949", PG_UHC
244 }, /* alias for UHC */
245 {
246 "win950", PG_BIG5
247 }, /* alias for BIG5 */
248 {
249 "windows1250", PG_WIN1250
250 }, /* Windows-1251; Microsoft */
251 {
252 "windows1251", PG_WIN1251
253 }, /* Windows-1251; Microsoft */
254 {
255 "windows1252", PG_WIN1252
256 }, /* Windows-1252; Microsoft */
257 {
258 "windows1253", PG_WIN1253
259 }, /* Windows-1253; Microsoft */
260 {
261 "windows1254", PG_WIN1254
262 }, /* Windows-1254; Microsoft */
263 {
264 "windows1255", PG_WIN1255
265 }, /* Windows-1255; Microsoft */
266 {
267 "windows1256", PG_WIN1256
268 }, /* Windows-1256; Microsoft */
269 {
270 "windows1257", PG_WIN1257
271 }, /* Windows-1257; Microsoft */
272 {
273 "windows1258", PG_WIN1258
274 }, /* Windows-1258; Microsoft */
275 {
276 "windows866", PG_WIN866
277 }, /* IBM866 */
278 {
279 "windows874", PG_WIN874
280 }, /* Windows-874; Microsoft */
281 {
282 "windows932", PG_SJIS
283 }, /* alias for Shift_JIS */
284 {
285 "windows936", PG_GBK
286 }, /* alias for GBK */
287 {
288 "windows949", PG_UHC
289 }, /* alias for UHC */
290 {
291 "windows950", PG_BIG5
292 } /* alias for BIG5 */
293};

Referenced by pg_char_to_encoding().