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 112 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.

113 {
114  int encoding = PG_GETARG_INT32(0);
115  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
116  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
117  int len = PG_GETARG_INT32(4);
118  int i;
119 
121 
122  for (i = 0; i < lengthof(maps); i++)
123  {
124  if (encoding == maps[i].encoding)
125  {
126  LocalToUtf(src, len, dest,
127  maps[i].map1, maps[i].size1,
128  NULL, 0,
129  NULL,
130  encoding);
131  PG_RETURN_VOID();
132  }
133  }
134 
135  ereport(ERROR,
136  (errcode(ERRCODE_INTERNAL_ERROR),
137  errmsg("unexpected encoding ID %d for ISO 8859 character sets",
138  encoding)));
139 
140  PG_RETURN_VOID();
141 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:558
#define ERROR
Definition: elog.h:43
void LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_local_to_utf *map, int mapsize, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
Definition: conv.c:576
#define ereport(elevel, rest)
Definition: elog.h:122
static char * encoding
Definition: initdb.c:120
#define PG_RETURN_VOID()
Definition: fmgr.h:293
#define NULL
Definition: c.h:226
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:428
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:233
PG_FUNCTION_INFO_V1 ( iso8859_to_utf8  )
PG_FUNCTION_INFO_V1 ( utf8_to_iso8859  )
Datum utf8_to_iso8859 ( PG_FUNCTION_ARGS  )

Definition at line 144 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().

145 {
146  int encoding = PG_GETARG_INT32(1);
147  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
148  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
149  int len = PG_GETARG_INT32(4);
150  int i;
151 
153 
154  for (i = 0; i < lengthof(maps); i++)
155  {
156  if (encoding == maps[i].encoding)
157  {
158  UtfToLocal(src, len, dest,
159  maps[i].map2, maps[i].size2,
160  NULL, 0,
161  NULL,
162  encoding);
163  PG_RETURN_VOID();
164  }
165  }
166 
167  ereport(ERROR,
168  (errcode(ERRCODE_INTERNAL_ERROR),
169  errmsg("unexpected encoding ID %d for ISO 8859 character sets",
170  encoding)));
171 
172  PG_RETURN_VOID();
173 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:558
void UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_utf_to_local *map, int mapsize, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
Definition: conv.c:390
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static char * encoding
Definition: initdb.c:120
#define PG_RETURN_VOID()
Definition: fmgr.h:293
#define NULL
Definition: c.h:226
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:428
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:233

Variable Documentation

const pg_conv_map maps[]
static

Definition at line 69 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.