| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * LATIN2 and WIN1250 |
| 4 | * |
| 5 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 6 | * Portions Copyright (c) 1994, Regents of the University of California |
| 7 | * |
| 8 | * IDENTIFICATION |
| 9 | * src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c |
| 10 | * |
| 11 | *------------------------------------------------------------------------- |
| 12 | */ |
| 13 | |
| 14 | #include "postgres.h" |
| 15 | #include "fmgr.h" |
| 16 | #include "mb/pg_wchar.h" |
| 17 | |
| 18 | PG_MODULE_MAGIC; |
| 19 | |
| 20 | PG_FUNCTION_INFO_V1(latin2_to_mic); |
| 21 | PG_FUNCTION_INFO_V1(mic_to_latin2); |
| 22 | PG_FUNCTION_INFO_V1(win1250_to_mic); |
| 23 | PG_FUNCTION_INFO_V1(mic_to_win1250); |
| 24 | PG_FUNCTION_INFO_V1(latin2_to_win1250); |
| 25 | PG_FUNCTION_INFO_V1(win1250_to_latin2); |
| 26 | |
| 27 | /* ---------- |
| 28 | * conv_proc( |
| 29 | * INTEGER, -- source encoding id |
| 30 | * INTEGER, -- destination encoding id |
| 31 | * CSTRING, -- source string (null terminated C string) |
| 32 | * CSTRING, -- destination string (null terminated C string) |
| 33 | * INTEGER -- source string length |
| 34 | * ) returns VOID; |
| 35 | * ---------- |
| 36 | */ |
| 37 | |
| 38 | /* WIN1250 to ISO-8859-2 */ |
| 39 | static const unsigned char win1250_2_iso88592[] = { |
| 40 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 41 | 0x88, 0x89, 0xA9, 0x8B, 0xA6, 0xAB, 0xAE, 0xAC, |
| 42 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 43 | 0x98, 0x99, 0xB9, 0x9B, 0xB6, 0xBB, 0xBE, 0xBC, |
| 44 | 0xA0, 0xB7, 0xA2, 0xA3, 0xA4, 0xA1, 0x00, 0xA7, |
| 45 | 0xA8, 0x00, 0xAA, 0x00, 0x00, 0xAD, 0x00, 0xAF, |
| 46 | 0xB0, 0x00, 0xB2, 0xB3, 0xB4, 0x00, 0x00, 0x00, |
| 47 | 0xB8, 0xB1, 0xBA, 0x00, 0xA5, 0xBD, 0xB5, 0xBF, |
| 48 | 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, |
| 49 | 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, |
| 50 | 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, |
| 51 | 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, |
| 52 | 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, |
| 53 | 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, |
| 54 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, |
| 55 | 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF |
| 56 | }; |
| 57 | |
| 58 | /* ISO-8859-2 to WIN1250 */ |
| 59 | static const unsigned char iso88592_2_win1250[] = { |
| 60 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 61 | 0x88, 0x89, 0x00, 0x8B, 0x00, 0x00, 0x00, 0x00, |
| 62 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 63 | 0x98, 0x99, 0x00, 0x9B, 0x00, 0x00, 0x00, 0x00, |
| 64 | 0xA0, 0xA5, 0xA2, 0xA3, 0xA4, 0xBC, 0x8C, 0xA7, |
| 65 | 0xA8, 0x8A, 0xAA, 0x8D, 0x8F, 0xAD, 0x8E, 0xAF, |
| 66 | 0xB0, 0xB9, 0xB2, 0xB3, 0xB4, 0xBE, 0x9C, 0xA1, |
| 67 | 0xB8, 0x9A, 0xBA, 0x9D, 0x9F, 0xBD, 0x9E, 0xBF, |
| 68 | 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, |
| 69 | 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, |
| 70 | 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, |
| 71 | 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, |
| 72 | 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, |
| 73 | 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, |
| 74 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, |
| 75 | 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | Datum |
| 80 | latin2_to_mic(PG_FUNCTION_ARGS) |
| 81 | { |
| 82 | unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); |
| 83 | unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); |
| 84 | int len = PG_GETARG_INT32(4); |
| 85 | |
| 86 | CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_MULE_INTERNAL); |
| 87 | |
| 88 | latin2mic(src, dest, len, LC_ISO8859_2, PG_LATIN2); |
| 89 | |
| 90 | PG_RETURN_VOID(); |
| 91 | } |
| 92 | |
| 93 | Datum |
| 94 | mic_to_latin2(PG_FUNCTION_ARGS) |
| 95 | { |
| 96 | unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); |
| 97 | unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); |
| 98 | int len = PG_GETARG_INT32(4); |
| 99 | |
| 100 | CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN2); |
| 101 | |
| 102 | mic2latin(src, dest, len, LC_ISO8859_2, PG_LATIN2); |
| 103 | |
| 104 | PG_RETURN_VOID(); |
| 105 | } |
| 106 | |
| 107 | Datum |
| 108 | win1250_to_mic(PG_FUNCTION_ARGS) |
| 109 | { |
| 110 | unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); |
| 111 | unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); |
| 112 | int len = PG_GETARG_INT32(4); |
| 113 | |
| 114 | CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_MULE_INTERNAL); |
| 115 | |
| 116 | latin2mic_with_table(src, dest, len, LC_ISO8859_2, PG_WIN1250, |
| 117 | win1250_2_iso88592); |
| 118 | |
| 119 | PG_RETURN_VOID(); |
| 120 | } |
| 121 | |
| 122 | Datum |
| 123 | mic_to_win1250(PG_FUNCTION_ARGS) |
| 124 | { |
| 125 | unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); |
| 126 | unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); |
| 127 | int len = PG_GETARG_INT32(4); |
| 128 | |
| 129 | CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1250); |
| 130 | |
| 131 | mic2latin_with_table(src, dest, len, LC_ISO8859_2, PG_WIN1250, |
| 132 | iso88592_2_win1250); |
| 133 | |
| 134 | PG_RETURN_VOID(); |
| 135 | } |
| 136 | |
| 137 | Datum |
| 138 | latin2_to_win1250(PG_FUNCTION_ARGS) |
| 139 | { |
| 140 | unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); |
| 141 | unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); |
| 142 | int len = PG_GETARG_INT32(4); |
| 143 | |
| 144 | CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_WIN1250); |
| 145 | |
| 146 | local2local(src, dest, len, PG_LATIN2, PG_WIN1250, iso88592_2_win1250); |
| 147 | |
| 148 | PG_RETURN_VOID(); |
| 149 | } |
| 150 | |
| 151 | Datum |
| 152 | win1250_to_latin2(PG_FUNCTION_ARGS) |
| 153 | { |
| 154 | unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); |
| 155 | unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); |
| 156 | int len = PG_GETARG_INT32(4); |
| 157 | |
| 158 | CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_LATIN2); |
| 159 | |
| 160 | local2local(src, dest, len, PG_WIN1250, PG_LATIN2, win1250_2_iso88592); |
| 161 | |
| 162 | PG_RETURN_VOID(); |
| 163 | } |
| 164 | |