PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_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

 PG_MODULE_MAGIC
 
static const pg_conv_map maps []
 

Function Documentation

Datum iso8859_to_utf8 ( PG_FUNCTION_ARGS  )

Definition at line 97 of file utf8_and_iso8859.c.

References CHECK_ENCODING_CONVERSION_ARGS, encoding, ereport, errcode(), errmsg(), ERROR, i, lengthof, LocalToUtf(), NULL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_RETURN_VOID, and PG_UTF8.

98 {
99  int encoding = PG_GETARG_INT32(0);
100  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
101  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
102  int len = PG_GETARG_INT32(4);
103  int i;
104 
106 
107  for (i = 0; i < lengthof(maps); i++)
108  {
109  if (encoding == maps[i].encoding)
110  {
111  LocalToUtf(src, len, dest,
112  maps[i].map1,
113  NULL, 0,
114  NULL,
115  encoding);
116  PG_RETURN_VOID();
117  }
118  }
119 
120  ereport(ERROR,
121  (errcode(ERRCODE_INTERNAL_ERROR),
122  errmsg("unexpected encoding ID %d for ISO 8859 character sets",
123  encoding)));
124 
125  PG_RETURN_VOID();
126 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:562
#define ERROR
Definition: elog.h:43
void 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)
Definition: conv.c:665
#define ereport(elevel, rest)
Definition: elog.h:122
static char * encoding
Definition: initdb.c:122
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define NULL
Definition: c.h:229
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:490
static const pg_conv_map maps[]
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
PG_FUNCTION_INFO_V1 ( iso8859_to_utf8  )
PG_FUNCTION_INFO_V1 ( utf8_to_iso8859  )
Datum utf8_to_iso8859 ( PG_FUNCTION_ARGS  )

Definition at line 129 of file utf8_and_iso8859.c.

References CHECK_ENCODING_CONVERSION_ARGS, encoding, ereport, errcode(), errmsg(), ERROR, i, lengthof, NULL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_RETURN_VOID, PG_UTF8, and UtfToLocal().

130 {
131  int encoding = PG_GETARG_INT32(1);
132  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
133  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
134  int len = PG_GETARG_INT32(4);
135  int i;
136 
138 
139  for (i = 0; i < lengthof(maps); i++)
140  {
141  if (encoding == maps[i].encoding)
142  {
143  UtfToLocal(src, len, dest,
144  maps[i].map2,
145  NULL, 0,
146  NULL,
147  encoding);
148  PG_RETURN_VOID();
149  }
150  }
151 
152  ereport(ERROR,
153  (errcode(ERRCODE_INTERNAL_ERROR),
154  errmsg("unexpected encoding ID %d for ISO 8859 character sets",
155  encoding)));
156 
157  PG_RETURN_VOID();
158 }
void 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)
Definition: conv.c:474
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:562
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static char * encoding
Definition: initdb.c:122
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define NULL
Definition: c.h:229
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:490
static const pg_conv_map maps[]
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242

Variable Documentation

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},
}

Definition at line 67 of file utf8_and_iso8859.c.

Referenced by gen_db_file_maps().

PG_MODULE_MAGIC

Definition at line 44 of file utf8_and_iso8859.c.