PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
utf8_and_iso8859.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#include "../../Unicode/iso8859_10_to_utf8.map"
#include "../../Unicode/iso8859_13_to_utf8.map"
#include "../../Unicode/iso8859_14_to_utf8.map"
#include "../../Unicode/iso8859_15_to_utf8.map"
#include "../../Unicode/iso8859_2_to_utf8.map"
#include "../../Unicode/iso8859_3_to_utf8.map"
#include "../../Unicode/iso8859_4_to_utf8.map"
#include "../../Unicode/iso8859_5_to_utf8.map"
#include "../../Unicode/iso8859_6_to_utf8.map"
#include "../../Unicode/iso8859_7_to_utf8.map"
#include "../../Unicode/iso8859_8_to_utf8.map"
#include "../../Unicode/iso8859_9_to_utf8.map"
#include "../../Unicode/utf8_to_iso8859_10.map"
#include "../../Unicode/utf8_to_iso8859_13.map"
#include "../../Unicode/utf8_to_iso8859_14.map"
#include "../../Unicode/utf8_to_iso8859_15.map"
#include "../../Unicode/utf8_to_iso8859_16.map"
#include "../../Unicode/utf8_to_iso8859_2.map"
#include "../../Unicode/utf8_to_iso8859_3.map"
#include "../../Unicode/utf8_to_iso8859_4.map"
#include "../../Unicode/utf8_to_iso8859_5.map"
#include "../../Unicode/utf8_to_iso8859_6.map"
#include "../../Unicode/utf8_to_iso8859_7.map"
#include "../../Unicode/utf8_to_iso8859_8.map"
#include "../../Unicode/utf8_to_iso8859_9.map"
#include "../../Unicode/iso8859_16_to_utf8.map"
Include dependency graph for utf8_and_iso8859.c:

Go to the source code of this file.

Data Structures

struct  pg_conv_map
 

Functions

 PG_MODULE_MAGIC_EXT (.name="utf8_and_iso8859",.version=PG_VERSION)
 
 PG_FUNCTION_INFO_V1 (iso8859_to_utf8)
 
 PG_FUNCTION_INFO_V1 (utf8_to_iso8859)
 
Datum iso8859_to_utf8 (PG_FUNCTION_ARGS)
 
Datum utf8_to_iso8859 (PG_FUNCTION_ARGS)
 

Variables

static const pg_conv_map maps []
 

Function Documentation

◆ iso8859_to_utf8()

Datum iso8859_to_utf8 ( PG_FUNCTION_ARGS  )

Definition at line 103 of file utf8_and_iso8859.c.

104{
105 int encoding = PG_GETARG_INT32(0);
106 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
107 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
108 int len = PG_GETARG_INT32(4);
109 bool noError = PG_GETARG_BOOL(5);
110 int i;
111
113
114 for (i = 0; i < lengthof(maps); i++)
115 {
116 if (encoding == maps[i].encoding)
117 {
118 int converted;
119
120 converted = LocalToUtf(src, len, dest,
121 maps[i].map1,
122 NULL, 0,
123 NULL,
124 encoding,
125 noError);
126 PG_RETURN_INT32(converted);
127 }
128 }
129
131 (errcode(ERRCODE_INTERNAL_ERROR),
132 errmsg("unexpected encoding ID %d for ISO 8859 character sets",
133 encoding)));
134
136}
#define lengthof(array)
Definition: c.h:759
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:717
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
int i
Definition: isn.c:77
const void size_t len
int32 encoding
Definition: pg_database.h:41
@ PG_UTF8
Definition: pg_wchar.h:232
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:507
static const pg_conv_map maps[]

References CHECK_ENCODING_CONVERSION_ARGS, generate_unaccent_rules::dest, encoding, ereport, errcode(), errmsg(), ERROR, i, len, lengthof, LocalToUtf(), maps, PG_GETARG_BOOL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_RETURN_INT32, and PG_UTF8.

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( iso8859_to_utf8  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( utf8_to_iso8859  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "utf8_and_iso8859",
version = PG_VERSION 
)

◆ utf8_to_iso8859()

Datum utf8_to_iso8859 ( PG_FUNCTION_ARGS  )

Definition at line 139 of file utf8_and_iso8859.c.

140{
141 int encoding = PG_GETARG_INT32(1);
142 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
143 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
144 int len = PG_GETARG_INT32(4);
145 bool noError = PG_GETARG_BOOL(5);
146 int i;
147
149
150 for (i = 0; i < lengthof(maps); i++)
151 {
152 if (encoding == maps[i].encoding)
153 {
154 int converted;
155
156 converted = UtfToLocal(src, len, dest,
157 maps[i].map2,
158 NULL, 0,
159 NULL,
160 encoding,
161 noError);
162 PG_RETURN_INT32(converted);
163 }
164 }
165
167 (errcode(ERRCODE_INTERNAL_ERROR),
168 errmsg("unexpected encoding ID %d for ISO 8859 character sets",
169 encoding)));
170
172}
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:507

References CHECK_ENCODING_CONVERSION_ARGS, generate_unaccent_rules::dest, encoding, ereport, errcode(), errmsg(), ERROR, i, len, lengthof, maps, PG_GETARG_BOOL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_RETURN_INT32, PG_UTF8, and UtfToLocal().

Variable Documentation

◆ maps

const pg_conv_map maps[]
static
Initial value:
= {
{PG_LATIN2, &iso8859_2_to_unicode_tree,
&iso8859_2_from_unicode_tree},
{PG_LATIN3, &iso8859_3_to_unicode_tree,
&iso8859_3_from_unicode_tree},
{PG_LATIN4, &iso8859_4_to_unicode_tree,
&iso8859_4_from_unicode_tree},
{PG_LATIN5, &iso8859_9_to_unicode_tree,
&iso8859_9_from_unicode_tree},
{PG_LATIN6, &iso8859_10_to_unicode_tree,
&iso8859_10_from_unicode_tree},
{PG_LATIN7, &iso8859_13_to_unicode_tree,
&iso8859_13_from_unicode_tree},
{PG_LATIN8, &iso8859_14_to_unicode_tree,
&iso8859_14_from_unicode_tree},
{PG_LATIN9, &iso8859_15_to_unicode_tree,
&iso8859_15_from_unicode_tree},
{PG_LATIN10, &iso8859_16_to_unicode_tree,
&iso8859_16_from_unicode_tree},
{PG_ISO_8859_5, &iso8859_5_to_unicode_tree,
&iso8859_5_from_unicode_tree},
{PG_ISO_8859_6, &iso8859_6_to_unicode_tree,
&iso8859_6_from_unicode_tree},
{PG_ISO_8859_7, &iso8859_7_to_unicode_tree,
&iso8859_7_from_unicode_tree},
{PG_ISO_8859_8, &iso8859_8_to_unicode_tree,
&iso8859_8_from_unicode_tree},
}
@ PG_LATIN4
Definition: pg_wchar.h:237
@ PG_LATIN9
Definition: pg_wchar.h:242
@ PG_ISO_8859_6
Definition: pg_wchar.h:252
@ PG_LATIN6
Definition: pg_wchar.h:239
@ PG_LATIN5
Definition: pg_wchar.h:238
@ PG_LATIN2
Definition: pg_wchar.h:235
@ PG_ISO_8859_5
Definition: pg_wchar.h:251
@ PG_LATIN10
Definition: pg_wchar.h:243
@ PG_ISO_8859_7
Definition: pg_wchar.h:253
@ PG_LATIN8
Definition: pg_wchar.h:241
@ PG_LATIN3
Definition: pg_wchar.h:236
@ PG_LATIN7
Definition: pg_wchar.h:240
@ PG_ISO_8859_8
Definition: pg_wchar.h:254

Definition at line 73 of file utf8_and_iso8859.c.

Referenced by do_swap(), gen_db_file_maps(), iso8859_to_utf8(), swap_catalog_files(), transfer_single_new_db(), and utf8_to_iso8859().