1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Use C99-designated initializer syntax for arrays related to encodings

This updates the following lookup arrays to use C99-designated
initializer syntax, indexed based on the enum pg_enc:
pg_enc2icu_tbl[]
pg_enc2name_tbl[]
pg_wchar_table[]

This is more readable, and removes problems with ordering mistakes as
this removes dependencies between the arrays and their lookup index in
the enum pg_enc.  So, adding new encodings becomes easier, even if this
does not happen often.

Author: Jelte Fennema-Nio
Reviewed-by: Jian He, Japin Li
Discussion: https://postgr.es/m/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw@mail.gmail.com
This commit is contained in:
Michael Paquier
2024-02-29 09:54:25 +09:00
parent e8aecc5c2c
commit ada87a4d95
3 changed files with 122 additions and 126 deletions

View File

@@ -297,7 +297,6 @@ static const pg_encname pg_encname_tbl[] =
/* ----------
* These are "official" encoding names.
* XXX must be sorted by the same order as enum pg_enc (in mb/pg_wchar.h)
* ----------
*/
#ifndef WIN32
@@ -308,48 +307,48 @@ static const pg_encname pg_encname_tbl[] =
const pg_enc2name pg_enc2name_tbl[] =
{
DEF_ENC2NAME(SQL_ASCII, 0),
DEF_ENC2NAME(EUC_JP, 20932),
DEF_ENC2NAME(EUC_CN, 20936),
DEF_ENC2NAME(EUC_KR, 51949),
DEF_ENC2NAME(EUC_TW, 0),
DEF_ENC2NAME(EUC_JIS_2004, 20932),
DEF_ENC2NAME(UTF8, 65001),
DEF_ENC2NAME(MULE_INTERNAL, 0),
DEF_ENC2NAME(LATIN1, 28591),
DEF_ENC2NAME(LATIN2, 28592),
DEF_ENC2NAME(LATIN3, 28593),
DEF_ENC2NAME(LATIN4, 28594),
DEF_ENC2NAME(LATIN5, 28599),
DEF_ENC2NAME(LATIN6, 0),
DEF_ENC2NAME(LATIN7, 0),
DEF_ENC2NAME(LATIN8, 0),
DEF_ENC2NAME(LATIN9, 28605),
DEF_ENC2NAME(LATIN10, 0),
DEF_ENC2NAME(WIN1256, 1256),
DEF_ENC2NAME(WIN1258, 1258),
DEF_ENC2NAME(WIN866, 866),
DEF_ENC2NAME(WIN874, 874),
DEF_ENC2NAME(KOI8R, 20866),
DEF_ENC2NAME(WIN1251, 1251),
DEF_ENC2NAME(WIN1252, 1252),
DEF_ENC2NAME(ISO_8859_5, 28595),
DEF_ENC2NAME(ISO_8859_6, 28596),
DEF_ENC2NAME(ISO_8859_7, 28597),
DEF_ENC2NAME(ISO_8859_8, 28598),
DEF_ENC2NAME(WIN1250, 1250),
DEF_ENC2NAME(WIN1253, 1253),
DEF_ENC2NAME(WIN1254, 1254),
DEF_ENC2NAME(WIN1255, 1255),
DEF_ENC2NAME(WIN1257, 1257),
DEF_ENC2NAME(KOI8U, 21866),
DEF_ENC2NAME(SJIS, 932),
DEF_ENC2NAME(BIG5, 950),
DEF_ENC2NAME(GBK, 936),
DEF_ENC2NAME(UHC, 949),
DEF_ENC2NAME(GB18030, 54936),
DEF_ENC2NAME(JOHAB, 0),
DEF_ENC2NAME(SHIFT_JIS_2004, 932)
[PG_SQL_ASCII] = DEF_ENC2NAME(SQL_ASCII, 0),
[PG_EUC_JP] = DEF_ENC2NAME(EUC_JP, 20932),
[PG_EUC_CN] = DEF_ENC2NAME(EUC_CN, 20936),
[PG_EUC_KR] = DEF_ENC2NAME(EUC_KR, 51949),
[PG_EUC_TW] = DEF_ENC2NAME(EUC_TW, 0),
[PG_EUC_JIS_2004] = DEF_ENC2NAME(EUC_JIS_2004, 20932),
[PG_UTF8] = DEF_ENC2NAME(UTF8, 65001),
[PG_MULE_INTERNAL] = DEF_ENC2NAME(MULE_INTERNAL, 0),
[PG_LATIN1] = DEF_ENC2NAME(LATIN1, 28591),
[PG_LATIN2] = DEF_ENC2NAME(LATIN2, 28592),
[PG_LATIN3] = DEF_ENC2NAME(LATIN3, 28593),
[PG_LATIN4] = DEF_ENC2NAME(LATIN4, 28594),
[PG_LATIN5] = DEF_ENC2NAME(LATIN5, 28599),
[PG_LATIN6] = DEF_ENC2NAME(LATIN6, 0),
[PG_LATIN7] = DEF_ENC2NAME(LATIN7, 0),
[PG_LATIN8] = DEF_ENC2NAME(LATIN8, 0),
[PG_LATIN9] = DEF_ENC2NAME(LATIN9, 28605),
[PG_LATIN10] = DEF_ENC2NAME(LATIN10, 0),
[PG_WIN1256] = DEF_ENC2NAME(WIN1256, 1256),
[PG_WIN1258] = DEF_ENC2NAME(WIN1258, 1258),
[PG_WIN866] = DEF_ENC2NAME(WIN866, 866),
[PG_WIN874] = DEF_ENC2NAME(WIN874, 874),
[PG_KOI8R] = DEF_ENC2NAME(KOI8R, 20866),
[PG_WIN1251] = DEF_ENC2NAME(WIN1251, 1251),
[PG_WIN1252] = DEF_ENC2NAME(WIN1252, 1252),
[PG_ISO_8859_5] = DEF_ENC2NAME(ISO_8859_5, 28595),
[PG_ISO_8859_6] = DEF_ENC2NAME(ISO_8859_6, 28596),
[PG_ISO_8859_7] = DEF_ENC2NAME(ISO_8859_7, 28597),
[PG_ISO_8859_8] = DEF_ENC2NAME(ISO_8859_8, 28598),
[PG_WIN1250] = DEF_ENC2NAME(WIN1250, 1250),
[PG_WIN1253] = DEF_ENC2NAME(WIN1253, 1253),
[PG_WIN1254] = DEF_ENC2NAME(WIN1254, 1254),
[PG_WIN1255] = DEF_ENC2NAME(WIN1255, 1255),
[PG_WIN1257] = DEF_ENC2NAME(WIN1257, 1257),
[PG_KOI8U] = DEF_ENC2NAME(KOI8U, 21866),
[PG_SJIS] = DEF_ENC2NAME(SJIS, 932),
[PG_BIG5] = DEF_ENC2NAME(BIG5, 950),
[PG_GBK] = DEF_ENC2NAME(GBK, 936),
[PG_UHC] = DEF_ENC2NAME(UHC, 949),
[PG_GB18030] = DEF_ENC2NAME(GB18030, 54936),
[PG_JOHAB] = DEF_ENC2NAME(JOHAB, 0),
[PG_SHIFT_JIS_2004] = DEF_ENC2NAME(SHIFT_JIS_2004, 932),
};
/* ----------
@@ -414,41 +413,41 @@ const pg_enc2gettext pg_enc2gettext_tbl[] =
*/
static const char *const pg_enc2icu_tbl[] =
{
NULL, /* PG_SQL_ASCII */
"EUC-JP", /* PG_EUC_JP */
"EUC-CN", /* PG_EUC_CN */
"EUC-KR", /* PG_EUC_KR */
"EUC-TW", /* PG_EUC_TW */
NULL, /* PG_EUC_JIS_2004 */
"UTF-8", /* PG_UTF8 */
NULL, /* PG_MULE_INTERNAL */
"ISO-8859-1", /* PG_LATIN1 */
"ISO-8859-2", /* PG_LATIN2 */
"ISO-8859-3", /* PG_LATIN3 */
"ISO-8859-4", /* PG_LATIN4 */
"ISO-8859-9", /* PG_LATIN5 */
"ISO-8859-10", /* PG_LATIN6 */
"ISO-8859-13", /* PG_LATIN7 */
"ISO-8859-14", /* PG_LATIN8 */
"ISO-8859-15", /* PG_LATIN9 */
NULL, /* PG_LATIN10 */
"CP1256", /* PG_WIN1256 */
"CP1258", /* PG_WIN1258 */
"CP866", /* PG_WIN866 */
NULL, /* PG_WIN874 */
"KOI8-R", /* PG_KOI8R */
"CP1251", /* PG_WIN1251 */
"CP1252", /* PG_WIN1252 */
"ISO-8859-5", /* PG_ISO_8859_5 */
"ISO-8859-6", /* PG_ISO_8859_6 */
"ISO-8859-7", /* PG_ISO_8859_7 */
"ISO-8859-8", /* PG_ISO_8859_8 */
"CP1250", /* PG_WIN1250 */
"CP1253", /* PG_WIN1253 */
"CP1254", /* PG_WIN1254 */
"CP1255", /* PG_WIN1255 */
"CP1257", /* PG_WIN1257 */
"KOI8-U", /* PG_KOI8U */
[PG_SQL_ASCII] = NULL,
[PG_EUC_JP] = "EUC-JP",
[PG_EUC_CN] = "EUC-CN",
[PG_EUC_KR] = "EUC-KR",
[PG_EUC_TW] = "EUC-TW",
[PG_EUC_JIS_2004] = NULL,
[PG_UTF8] = "UTF-8",
[PG_MULE_INTERNAL] = NULL,
[PG_LATIN1] = "ISO-8859-1",
[PG_LATIN2] = "ISO-8859-2",
[PG_LATIN3] = "ISO-8859-3",
[PG_LATIN4] = "ISO-8859-4",
[PG_LATIN5] = "ISO-8859-9",
[PG_LATIN6] = "ISO-8859-10",
[PG_LATIN7] = "ISO-8859-13",
[PG_LATIN8] = "ISO-8859-14",
[PG_LATIN9] = "ISO-8859-15",
[PG_LATIN10] = NULL,
[PG_WIN1256] = "CP1256",
[PG_WIN1258] = "CP1258",
[PG_WIN866] = "CP866",
[PG_WIN874] = NULL,
[PG_KOI8R] = "KOI8-R",
[PG_WIN1251] = "CP1251",
[PG_WIN1252] = "CP1252",
[PG_ISO_8859_5] = "ISO-8859-5",
[PG_ISO_8859_6] = "ISO-8859-6",
[PG_ISO_8859_7] = "ISO-8859-7",
[PG_ISO_8859_8] = "ISO-8859-8",
[PG_WIN1250] = "CP1250",
[PG_WIN1253] = "CP1253",
[PG_WIN1254] = "CP1254",
[PG_WIN1255] = "CP1255",
[PG_WIN1257] = "CP1257",
[PG_KOI8U] = "KOI8-U",
};
StaticAssertDecl(lengthof(pg_enc2icu_tbl) == PG_ENCODING_BE_LAST + 1,